Spending Cross-Chain
Build a spend request, submit it to the attester for signing, then execute the attestation on the destination chain.
Example: Spend Cross-Chain
Section titled “Example: Spend Cross-Chain”use alloy_primitives::{address, U256};use trident_sdk::SpendRequestBuilder;
let request = SpendRequestBuilder::new( 1, // source domain (Avalanche) address!("aaa..."), // source token address 2, // destination domain (Optimism) address!("bbb..."), // destination token address address!("ccc..."), // recipient on destination chain U256::from(500_000), // amount);
// Optional: pin execution to a specific caller address// let request = request.with_caller(address!("ddd..."));
// Optional: set an explicit max fee (otherwise estimated automatically)// let request = request.with_max_fee(U256::from(1000));
// Submit to attester - returns a signed attestationlet attestation = client.spend(request).await?;
// Execute the attestation on-chain (destination chain)let receipt = attestation.execute().await?;println!("Spend tx: {:?}", receipt.transaction_hash);What Happens During spend()
Section titled “What Happens During spend()”- The SDK generates a random anti-replay salt
- If no
max_feeis set, the SDK calls the attester’sGetSpendFeesRPC to estimate fees - The spend intent is submitted to the attester’s delivery service
- The attester validates the request, checks balances, and returns a signed
AcceptedSpendAttestation - If rejected, a
SpendRejectederror is returned with the reason
What Happens During execute()
Section titled “What Happens During execute()”- The SDK calls
tridentSpend(attestation, signature)on the destination Trident contract - The contract verifies the signer, domain, expiry, and replay protection
- If
usdcMinted > 0: USDC is minted via Circle Gateway and supplied to Aave as collateral - The requested token is borrowed from Aave V3
- The borrowed token is transferred to the recipient
- If any step fails, the entire transaction reverts
Spend Request Options
Section titled “Spend Request Options”| Field | Required | Description |
|---|---|---|
src_domain | Yes | Source chain domain ID |
src_token | Yes | Token address on the source chain |
dst_domain | Yes | Destination chain domain ID |
dst_token | Yes | Token address on the destination chain |
dst_recipient | Yes | Address that receives tokens on the destination chain |
amount | Yes | Amount to transfer (in token’s smallest unit) |
max_fee | No | Maximum fee you’re willing to pay. Auto-estimated if omitted |
caller | No | If set, only this address can submit the attestation on-chain. Defaults to address(0) (any caller) |