For the complete documentation index, see llms.txt. This page is also available as Markdown.

Token Management

Unlike Stellar assets, contract tokens a user owns are not automatically displayed in Freighter — they must be explicitly added. This method lets your dapp prompt users to add a contract token directly, without the user having to find and add it in Freighter manually.

In a future release, Freighter will auto-detect token transfers and display them automatically. Once that ships, addToken() will become a no-op.

Adding a Token

addToken()

Trigger an "add token" flow that displays token details in a modal for the user to review and approve.

addToken({ contractId: string, networkPassphrase?: string })
  -> Promise<{ contractId: string } & { error?: FreighterApiError }>

When called, Freighter loads the token's symbol, name, decimals, and balance from the contract and displays them for the user to verify before adding.

Parameters

Parameter
Type
Description

contractId

string

Required. The contract token ID (C... address).

networkPassphrase

string

Defaults to Mainnet passphrase if omitted.

Example

import { isConnected, addToken } from "@stellar/freighter-api";

const { isConnected: connected } = await isConnected();
if (!connected) return;

const result = await addToken({
  contractId: "CC...ABCD",
  networkPassphrase: "Test SDF Network ; September 2015", // optional
});

if (result.error) {
  console.error(result.error.message);
} else {
  console.log(`Token added: ${result.contractId}`);
}

After the user approves, Freighter will automatically track the token's balance and display it alongside other account balances.

Last updated

Was this helpful?