The Ankara Chain SDK ships its React bindings as a separate entry point — @ankarachain/sdk/react — so that importing the core SDK in a Node.js or server-side context never pulls React into your bundle. The hooks are all marked "use client" and are safe for React 18+ and Next.js App Router client components.
Installation and import
useAnkaraChain(config)
useAnkaraChain initializes the SDK inside a React component. Pass your AnkaraChainConfig — the same config shape you’d pass to new TokenFactory() — and the hook returns a connected factory instance along with the signer’s address, native balance, and connection state.
The hook re-runs automatically whenever network, factoryAddress, or the credential fields (signer, stellarSecretKey, stellarSigner) change, so wallet-switch events are handled without any extra wiring.
useAnkaraChain returns:
useAsset(opts)
useAsset reads on-chain metadata for a single deployed token — no signer required. It builds a read-only adapter internally, so you can display asset data to unauthenticated users.
It returns:
Portfolio card component
useTokenBalance(opts)
useTokenBalance reads a wallet’s balance for any deployed Ankara Chain token — no signer required.
It returns:
Usage
buildReadOnlyAdapter
buildReadOnlyAdapter is an internal helper that useAsset and useTokenBalance use to create a read-only EVMAdapter or StellarAdapter without any signing credentials. It is exported for advanced use cases — for example, building a custom hook that calls methods not yet covered by the built-in hooks — but most applications should not need it directly.
Complete example: portfolio page
This example renders a list of RWA tokens owned by the connected wallet, showing live metadata and balances for each.
Using Stellar in the browser
For Stellar, pass a StellarAnkaraChainConfig with stellarSigner instead of stellarSecretKey. The stellarSigner field expects a StellarExternalSigner — an object with a publicKey string and a signTransaction function matching Freighter’s API shape. The optional signAuthEntry field enables Soroban authorization when present:
You can pass the Freighter global object directly, since Freighter implements this shape:
Never use stellarSecretKey in browser code. The raw Stellar secret seed gives full control of the account to anyone who reads it from your JavaScript bundle, network traffic, or browser memory. Use stellarSigner with Freighter (or any SEP-43-compatible wallet) in all browser contexts.
useAsset and useTokenBalance work identically on Stellar — pass network: "stellar-testnet" and a Stellar contract ID ("C...") as tokenAddress, and both hooks will use the Soroban read-only adapter internally.