Stellar Asset Contract

The StellarAssetContract class provides a high-level client for interacting with Stellar Asset Contracts (SAC), which bridge classic Stellar assets with Soroban smart contracts.

SACs implement the SEP-41arrow-up-right token interface and are defined in CAP-0046-06arrow-up-right.

Overview

Stellar Asset Contracts enable classic Stellar assets (like USDC, XLM, or any issued asset) to be used within Soroban smart contracts. The contract ID is deterministically derived from the asset code, issuer, and network passphrase.

Creating a SAC Instance

import { StellarAssetContract, NetworkConfig } from "@colibri/core";

const sac = new StellarAssetContract({
  code: "USDC",
  issuer: "GCNY5OXYSY4FKHOPT2SPOQZAOEIGXB5LBYW3HVU3OWSTQITS65M5RCNY",
  networkConfig: NetworkConfig.TestNet(),
});

// The contract ID is automatically calculated
console.log("Contract ID:", sac.contractId);

Deploying the Contract

Before using the SAC, it must be deployed on the network. This operation creates the Stellar Asset Contract for the classic asset:

circle-info

If the contract has already been deployed, deploy() will detect the existing contract and return successfully without throwing an error.

Reading Token Information

Metadata

Balances and Allowances

Token Operations

Transfer

Transfer tokens from one address to another:

Approve

Set an allowance for delegated transfers:

Transfer From (Delegated)

Transfer tokens on behalf of another address using an allowance:

Burn

Destroy tokens (permanently remove from circulation):

Burn From (Delegated)

Burn tokens on behalf of another address:

Admin Operations

Admin operations require the current admin's authorization (initially the asset issuer).

Mint

Create new tokens:

Set Admin

Transfer admin rights to a new address:

Set Authorized

Enable or disable authorization for an address (for assets with AUTH_REQUIRED flag):

Clawback

Recover tokens from an address (for assets with AUTH_CLAWBACK_ENABLED flag):

Method Reference

Read Methods

Method
Parameters
Returns
Description

decimals()

number

Returns decimals (always 7)

name()

string

Returns "CODE:ISSUER" format

symbol()

string

Returns asset code

balance({ id })

address

bigint

Returns balance

allowance({ from, spender })

addresses

bigint

Returns remaining allowance

authorized({ id })

address

boolean

Returns authorization status

admin()

string

Returns admin address

Invoke Methods

Method
Parameters
Description

approve({ from, spender, amount, expirationLedger, config })

addresses, amount, ledger, config

Sets allowance

transfer({ from, to, amount, config })

addresses, amount, config

Transfers tokens

transferFrom({ spender, from, to, amount, config })

addresses, amount, config

Delegated transfer

burn({ from, amount, config })

address, amount, config

Burns tokens

burnFrom({ spender, from, amount, config })

addresses, amount, config

Delegated burn

Admin Methods

Method
Parameters
Description

setAdmin({ newAdmin, config })

address, config

Transfers admin rights

setAuthorized({ id, authorize, config })

address, boolean, config

Sets authorization

mint({ to, amount, config })

address, amount, config

Creates new tokens

clawback({ from, amount, config })

address, amount, config

Recovers tokens

Properties

Property
Type
Description

code

string

The asset code

issuer

Ed25519PublicKey

The issuer's public key

contractId

ContractId

The deterministic contract ID

contract

Contract

The underlying Contract instance

Errors

Code
Class
Description

SAC_001

FAILED_TO_WRAP_ASSET

Asset contract deployment failed

SAC_002

UNMATCHED_CONTRACT_ID

Deployed ID doesn't match expected

SAC_003

MISSING_RETURN_VALUE

Contract method returned no value

Notes

  • Decimals: All SACs use 7 decimal places, matching classic Stellar assets

  • Amounts: All amounts are bigint base units. Use fromDecimals("100", 7) / toDecimals(amount, 7) to convert safely

  • Authorization: The from address must sign/authorize most operations

  • Admin: Initially the asset issuer; can be transferred via setAdmin

  • Deterministic IDs: Contract IDs are deterministically derived from the asset and network

See Also

Last updated