Skip to content

Wallet & Trustlines ​

The wallet service reads account balances and manages trustlines through Stellar's Horizon API. On Stellar, an account must hold a trustline for a non-native asset before it can receive or hold that asset — so the typical onboarding sequence is: check the balance, add a trustline if missing, then supply into the protocol.

Accessed via client.wallet.

Horizon, not Soroban

Trustline changes are classic Stellar operations submitted through Horizon, a different signing and submission path from the Soroban contract calls used elsewhere in the SDK. addTrustline handles this for you.

Balances ​

getBalances ​

Fetch all balance lines for an account.

typescript
const balances = await client.wallet.getBalances('GABC...')
ParameterTypeDescription
publicKeystringOptional; falls back to the client's connected public key

Returns an array of Horizon balance lines, or throws if no address is available.


getAssetBalance ​

Fetch the balance for one asset. Pass 'XLM' for the native asset; otherwise provide the asset code and, optionally, the issuer to disambiguate.

typescript
const xlm = await client.wallet.getAssetBalance('GABC...', 'XLM')
const usdc = await client.wallet.getAssetBalance('GABC...', 'USDC', usdcIssuer)
ParameterTypeDescription
publicKeystringAccount to read
assetCodestringAsset code, or 'XLM' for native
assetIssuerstringOptional issuer to disambiguate the asset

Returns the balance as a string, or null if the account holds no such asset.

Trustlines ​

addTrustline ​

Add a trustline for an asset, then sign and submit it through Horizon.

typescript
await client.wallet.addTrustline('GABC...', 'USDC', usdcIssuer, kit)
ParameterTypeDescription
publicKeystringAccount adding the trustline
assetCodestringAsset code to trust
assetIssuerstringIssuer of the asset
kitSigningKitWallet used to sign
options{ debug?: boolean }Optional; debug defaults to true

Build-only variant: buildAddTrustlineTx(publicKey, assetCode, assetIssuer) returns the unsigned transaction.

Connection helpers ​

hasWallet() returns whether a public key is currently set, and setPublicKey(publicKey) updates it after a wallet connects.

typescript
if (!client.wallet.hasWallet()) {
  client.wallet.setPublicKey(connectedAddress)
}