Documentation Index
Fetch the complete documentation index at: https://docs.dzap.io/llms.txt
Use this file to discover all available pages before exploring further.
A complete swap on Arbitrum: 100 USDC → WETH. Copy, paste, run.
Setup
import { DZapClient, ApprovalModes } from '@dzapio/sdk';
import { createWalletClient, http } from 'viem';
import { arbitrum } from 'viem/chains';
import { privateKeyToAccount } from 'viem/accounts';
const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`);
const walletClient = createWalletClient({
account,
chain: arbitrum,
transport: http(),
});
const dzap = DZapClient.getInstance();
const USDC = '0xaf88d065e77c8cC2239327C5EDb3A432268e5831';
const WETH = '0x82aF49447D8a07e3bd95BD0d56f35241523fBab1';
const AMOUNT = '100000000'; // 100 USDC (6 decimals)
Steps
Quote
const quotes = await dzap.getTradeQuotes({
fromChain: 42161,
account: account.address,
data: [{
srcToken: USDC,
destToken: WETH,
amount: AMOUNT,
slippage: 1,
}],
});
const best = quotes[0].quotes[0];
console.log(`Best: ${best.protocol}, output ${best.amountOut}`);
Approve (if needed)
const allowance = await dzap.getAllowance({
chainId: 42161,
sender: account.address,
tokens: [{ address: USDC, amount: BigInt(AMOUNT) }],
service: 'swap',
mode: ApprovalModes.AutoPermit,
});
const needsApproval = allowance.data[USDC].allowance < BigInt(AMOUNT);
if (needsApproval) {
await dzap.approve({
chainId: 42161,
signer: walletClient,
sender: account.address,
tokens: [{ address: USDC, amount: BigInt(AMOUNT) }],
service: 'swap',
mode: ApprovalModes.AutoPermit,
});
}
Trade
const result = await dzap.trade({
request: {
fromChain: 42161,
sender: account.address,
refundee: account.address,
data: [{
srcToken: USDC,
destToken: WETH,
amount: AMOUNT,
protocol: best.protocol,
recipient: account.address,
slippage: 1,
}],
},
signer: walletClient,
});
console.log(`Sent: ${result.txnHash}`);
Confirm
const status = await dzap.getTradeTxnStatus({
txHash: result.txnHash,
chainId: '42161',
});
console.log(status.status); // 'completed' once mined
What can go wrong
NO_ROUTE_FOUND — pair is too thin or not yet supported. Try a different amount or token.
SLIPPAGE_TOO_TIGHT — bump slippage from 1 to 2.
- Approval fails — make sure your wallet has gas (ETH on Arbitrum).
See Error Codes for the full catalog.
Going further