Prerequisites
Before you begin, ensure that you’ve: These are required so any example below runs with a validkit and adapter.
Estimate fees before spending
This sample estimates then spends 1.00 USDC from Base Sepolia to Arc Testnet when you specify explicit amounts from a source blockchain:For automatic routing (no explicit
allocations), see
Select source blockchains.TypeScript
Estimated fees may differ from actual fees due to network conditions at
execution time. Review the estimate before proceeding.
Example fee response
The JSON below shows the shape of the fees array.JSON
type values can include:
provider: Protocol transfer fee when the spend is crosschain. Not charged for same-chain spends.gasFee: Onchain gas paid on source blockchains as part of the spend.kit: Developer custom fee from your custom fee policy.forwarder: Forwarding Service fee when the spend uses the forwarder (not shown in the sample above).
Handle missing Solana ATAs
When you estimate a spend to a Solana recipient,estimateSpend() checks that
the recipient has an associated token account (ATA) for the token you spend
(USDC or EURC). If the account is missing, it throws an
INPUT_VALIDATION_FAILED error instead of returning fees. spend() runs the
same check for spends that don’t use the forwarder, and throws before anything
is signed. The error message names each missing account, and
error.cause.trace.missingTokenAccounts lists them.
The SDK doesn’t create ATAs, so
create the missing accounts
and then call the method again.
If the account goes missing only when the mint is submitted, spend() throws a
RESUMABLE error. Create the account, then call spend() again with
config.retry set to the attestation and signature from
error.cause.trace:
TypeScript