Address class
Represents an address in Soroban smart contracts.
An Address identifies different types of entities in the Stellar network:
- Accounts: Regular Stellar accounts (G... addresses)
- Contracts: Deployed smart contracts (C... addresses)
- Muxed Accounts: Multiplexed accounts (M... addresses, protocol >= 23)
- Claimable Balances: Claimable balance entries (protocol >= 23)
- Liquidity Pools: Liquidity pool entries (protocol >= 23)
Addresses are used as arguments to contract functions and can represent different authorization contexts in Soroban transactions.
Factory methods:
- Address.forAccountId: Create from Stellar account ID (G...)
- Address.forContractId: Create from contract ID (C...)
- Address.forMuxedAccountId: Create from muxed account (M...)
- Address.forClaimableBalanceId: Create from claimable balance ID
- Address.forLiquidityPoolId: Create from liquidity pool ID
- Address.fromXdr: Create from XdrSCAddress
- Address.fromXdrSCVal: Create from XdrSCVal containing an address
Example:
// Create address for an account
final accountAddr = Address.forAccountId('GABC...');
final accountScVal = accountAddr.toXdrSCVal();
// Create address for a contract
final contractAddr = Address.forContractId('CABC...');
final contractScVal = contractAddr.toXdrSCVal();
// Use as contract function argument
final result = await client.invokeMethod(
name: 'transfer',
args: [
Address.forAccountId(fromAccount).toXdrSCVal(),
Address.forAccountId(toAccount).toXdrSCVal(),
XdrSCVal.forI128Parts(0, amount),
],
);
Example - Check address type:
if (address.type == Address.TYPE_ACCOUNT) {
print('Account: ${address.accountId}');
} else if (address.type == Address.TYPE_CONTRACT) {
print('Contract: ${address.contractId}');
}
See also:
- XdrSCAddress for XDR representation
- SorobanAuthorizationEntry for authorization contexts
Constructors
- Address(int _type, {String? accountId, String? contractId, String? muxedAccountId, String? claimableBalanceId, String? liquidityPoolId})
- Constructs an Address for the given type which can be one of: Address.TYPE_ACCOUNT, Address.TYPE_CONTRACT, Address.TYPE_CLAIMABLE_BALANCE, Address.TYPE_LIQUIDITY_POOL.
Properties
- accountId ↔ String?
-
The id of the account if type is TYPE_ACCOUNT otherwise null.
getter/setter pair
- claimableBalanceId ↔ String?
-
The id of the claimable balance if type is TYPE_CLAIMABLE_BALANCE otherwise null.
getter/setter pair
- contractId ↔ String?
-
The id of the contract if type is TYPE_CONTRACT otherwise null.
getter/setter pair
- hashCode → int
-
The hash code for this object.
no setterinherited
- liquidityPoolId ↔ String?
-
The id of the liquidity pool if type is TYPE_LIQUIDITY_POOL otherwise null.
getter/setter pair
- muxedAccountId ↔ String?
-
The id of the account if type is TYPE_MUXED_ACCOUNT otherwise null.
getter/setter pair
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- type → dynamic
-
The type of the Address (TYPE_ACCOUNT or TYPE_CONTRACT).
no setter
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
toXdr(
) → XdrSCAddress - Returns a XdrSCAddress object created from this Address object.
-
toXdrSCVal(
) → XdrSCVal - Returns a XdrSCVal containing an XdrSCAddress for this Address.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
forAccountId(
String accountId) → Address -
Constructs an Address of type Address.TYPE_ACCOUNT for the given
accountId("G..."). -
forClaimableBalanceId(
String claimableBalanceId) → Address -
Constructs an Address of type Address.TYPE_CLAIMABLE_BALANCE for the given
claimableBalanceId. -
forContractId(
String contractId) → Address -
Constructs an Address of type Address.TYPE_CONTRACT for the given
contractId. -
forLiquidityPoolId(
String liquidityPoolId) → Address -
Constructs an Address of type Address.TYPE_LIQUIDITY_POOL for the given
liquidityPoolId. -
forMuxedAccountId(
String muxedAccountId) → Address -
Constructs an Address of type Address.TYPE_MUXED_ACCOUNT for the given
muxedAccountId("M..."). -
fromXdr(
XdrSCAddress xdr) → Address -
Constructs an Address from the given
xdr. -
fromXdrSCVal(
XdrSCVal val) → Address - Creates an address from an XDR SCVal representation.
Constants
- TYPE_ACCOUNT → const int
- Account address type (G... addresses). Supported in all protocol versions.
- TYPE_CLAIMABLE_BALANCE → const int
- Claimable balance address type. Requires protocol version 23 or higher.
- TYPE_CONTRACT → const int
- Contract address type (C... addresses). Supported in all protocol versions.
- TYPE_LIQUIDITY_POOL → const int
- Liquidity pool address type. Requires protocol version 23 or higher.
- TYPE_MUXED_ACCOUNT → const int
- Muxed account address type (M... addresses). Requires protocol version 23 or higher.