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)
  • Muxed Contracts: Contracts multiplexed with an id (W... addresses, protocol >= 30)

Addresses are used as arguments to contract functions and can represent different authorization contexts in Soroban transactions.

Two addresses are equal when they encode to the same XdrSCAddress, whichever spelling of the id they were built from. An address that serves as a map key or set member keeps its hash only while its id fields stay unchanged.

Factory methods:

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(BigInt.zero, BigInt.from(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:

Constructors

Address(int _type, {String? accountId, String? contractId, String? muxedAccountId, String? claimableBalanceId, String? liquidityPoolId, String? muxedContractId})
Constructs an Address for the given type which can be one of: Address.TYPE_ACCOUNT, Address.TYPE_CONTRACT, Address.TYPE_MUXED_ACCOUNT, Address.TYPE_CLAIMABLE_BALANCE, Address.TYPE_LIQUIDITY_POOL, Address.TYPE_MUXED_CONTRACT.

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
Returns a hash code consistent with ==.
no setteroverride
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
muxedContractId ↔ String?
The muxed contract address ("W...") if type is TYPE_MUXED_CONTRACT 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
Returns true if other is an Address that encodes to the same XdrSCAddress. An address whose id does not encode equals only an address of the same type with the same id strings.
override

Static Methods

deriveContractId({required Address deployer, required Uint8List salt, required Network network}) → String
Derives the contract id a deployment by the given deployer with the given salt creates on the given network.
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...").
forMuxedContract({required String contractId, required BigInt id}) → Address
Constructs an Address of type Address.TYPE_MUXED_CONTRACT that pairs the contract contractId with the multiplexing id.
forMuxedContractId(String muxedContractId) → Address
Constructs an Address of type Address.TYPE_MUXED_CONTRACT for the given muxedContractId ("W...").
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.
TYPE_MUXED_CONTRACT → const int
Muxed contract address type (W... strkeys, CAP-0084).