Function: address()
ts
function address<TAddress>(putativeAddress): Address<TAddress>;Combines asserting that a string is an address with coercing it to the Address type. It's most useful with untrusted input.
Type Parameters
| Type Parameter | Default type |
|---|---|
TAddress extends string | string |
Parameters
| Parameter | Type |
|---|---|
putativeAddress | TAddress |
Returns
Address<TAddress>
Example
ts
import { address } from '@solana/addresses';
await transfer(address(fromAddress), address(toAddress), lamports(100000n));TIP
When starting from a known-good address as a string, it's more efficient to typecast it rather than to use the address helper, because the helper unconditionally performs validation on its input.
ts
import { Address } from '@solana/addresses';
const MEMO_PROGRAM_ADDRESS =
'MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr' as Address<'MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr'>;