Overview
Address is a universal opaque identifier used in Soroban contracts. It can represent either a Stellar account or a contract.
Address can be used as:
- An input argument (e.g., to identify a payment recipient)
- A data key (e.g., to store balances)
- An authentication & authorization source
- A Stellar account (using Ed25519 public key)
- A contract (identified by contract hash)
Creating Addresses
from_str()
Creates an Address from a Stellar strkey.
- Account keys:
G...(Ed25519 public keys) - Contract keys:
C...(Contract identifiers)
from_string()
Creates an Address from a String containing a Stellar strkey.
from_string_bytes()
Creates an Address from bytes containing a Stellar strkey.
generate() (Test Only)
Generates a random Address for testing.
Authorization
require_auth()
Ensures that this Address has authorized the invocation of the current contract with all invocation arguments.
require_auth_for_args()
Ensures that this Address has authorized the invocation with specific arguments.
require_auth arguments.
Panics:
If the invocation is not authorized.
Example:
Conversion Methods
to_string()
Converts this Address into the corresponding Stellar strkey.
to_payload()
Extracts the payload from the address.
- For contract addresses (
C...):AddressPayload::ContractIdHashcontaining the 32-byte contract hash - For account addresses (
G...):AddressPayload::AccountIdPublicKeyEd25519containing the 32-byte Ed25519 public key Noneif the address type is not recognized
from_payload()
Constructs an Address from an AddressPayload.
to_payload().
Query Methods
executable()
Returns the executable type of this address, if any.
Nonewhen the contract or account does not existSome(Executable::Wasm(BytesN<32>))for Wasm contractsSome(Executable::StellarAsset)for Stellar Asset contractsSome(Executable::Account)for account contracts
exists()
Returns whether this address exists in the ledger.
Internal Methods
env()
Returns a reference to the Env.
as_val() / to_val()
Convert to/from Val representation.
as_object() / to_object()
Convert to/from AddressObject representation.
Traits
Address implements the following traits:
CloneDebugEq,PartialEqOrd,PartialOrd
Examples
Basic Usage
Testing with Generated Addresses
MuxedAddress
MuxedAddress is a union type that represents either a regular Address or a “multiplexed” address consisting of a regular address plus a u64 ID. This allows representing virtual accounts that manage multiple off-chain balances with a single on-chain balance entry.
When to Use MuxedAddress
- Token transfers supporting non-custodial accounts (e.g., exchange support)
- Off-chain balance tracking where the ID identifies virtual sub-accounts
- Event emission where the ID helps off-chain processors distinguish accounts
Creating MuxedAddress
Compatibility
MuxedAddress is compatible with Address at the contract interface level:
- Contracts accepting
MuxedAddresscan receiveAddressarguments - Upgrading from
AddresstoMuxedAddressdoesn’t break existing clients - Only Stellar accounts can be multiplexed (not contract addresses)
MuxedAddress cannot be used as a storage key to prevent accidental key space fragmentation.
Example: Token Transfer
Key Methods
new(env: &Env, address: &Address, id: u64)- Create multiplexed addressfrom_address(env: &Env, address: &Address)- Create from regular addressaddress(&self) -> Address- Extract base addressmux_id(&self) -> Option<u64>- Get multiplexing ID if present
See Also
- Authentication - Using addresses for authorization
- Token Interface - Token standard using MuxedAddress