Token Management
Unlike Stellar assets, contract tokens a user owns are not automatically displayed in Varial — 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 Varial manually.
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, Varial 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/varial-sdk";
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}`);
}Last updated
Was this helpful?