Get Started with Swap API
Learn how to send your first Swap API (AllowanceHolder) request.
About Swap API
Swap API is a DEX aggregation and smart order routing REST API that finds the best price for crypto trades. With one API integration, you can easily add trading to your app. Swap API aggregates liquidity from 150+ sources , including AMMs and professional market makers, across the supported chains.
The API handles three key tasks:
- Queries ERC20 prices from decentralized exchanges and market makers
- Aggregates liquidity for the best possible price
- Returns a trade format executable via your preferred web3 library
What You Will Learn
This guide will cover the core steps to using Swap API, specifically using the Swap AllowanceHolder endpoint.
Learn about the difference between AllowanceHolder and Permit2 in Swap API
Playground
Try this code example directly in your browser—no installation needed!
Swap Token in 4 Steps
- Get a 0x API key
- Get an indicative price
- (If needed) Set token allowance
- Fetch a firm quote
- Submit the transaction
0. Get a 0x API key
Every 0x API call requires an API key. Create a 0x account to get your live API key. Follow the setup guide for more details.
1. Get an Indicative Price
Let's find the best price!
Use the /swap/allowance-holder/price
endpoint to get an indicative price for an asset pair. This returns pricing information without creating a full order or transaction, allowing the user to browse potential prices before committing.
Think of /price
as the "read-only" version of /quote
, which you'll use in step 3.
Example Request
Here is an example request to sell 100 WETH for DAI using /price
.
See (code):
const priceParams = new URLSearchParams({
chainId: '1', // / Ethereum mainnet. See the 0x Cheat Sheet for all supported endpoints: https://0x.org/docs/introduction/0x-cheat-sheet
sellToken: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', //ETH
buyToken: '0x6b175474e89094c44da98b954eedeac495271d0f', //DAI
sellAmount: '100000000000000000000', // Note that the WETH token uses 18 decimal places, so `sellAmount` is `100 * 10^18`.
taker: '$USER_TAKER_ADDRESS', //Address that will make the trade
});
const headers = {
'0x-api-key': '[api-key]', // Get your live API key from the 0x Dashboard (https://dashboard.0x.org/apps)
'0x-version': 'v2',
};
const priceResponse = await fetch('https://api.0x.org/swap/allowance-holder/price?' + priceParams.toString(), {
headers,
});
console.log(await priceResponse.json());
Example Response
You will receive a response that looks like this:
Expand to see response
{
"allowanceTarget": "0x0000000000001ff3684f28c67538d4d072c22734",
"blockNumber": "23234885",
"buyAmount": "458050129388884000000000",
"buyToken": "0x6b175474e89094c44da98b954eedeac495271d0f",
"fees": {
"integratorFee": null,
"zeroExFee": {
"amount": "688205446596484002742",
"token": "0x6b175474e89094c44da98b954eedeac495271d0f",
"type": "volume"
},
"gasFee": null
},
"gas": "1116817",
"gasPrice": "2558459858",
"issues": {
"allowance": {
"actual": "0",
"spender": "0x0000000000001ff3684f28c67538d4d072c22734"
},
"balance": {
"token": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"actual": "0",
"expected": "100000000000000000000"
},
"simulationIncomplete": false,
"invalidSourcesPassed": []
},
"liquidityAvailable": true,
"minBuyAmount": "453462747021444000000000",
"route": {
"fills": [
{
"from": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"to": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
"source": "Uniswap_V3",
"proportionBps": "500"
},
{
"from": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"to": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
"source": "Uniswap_V3",
"proportionBps": "3251"
},
{
"from": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"to": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
"source": "Uniswap_V4",
"proportionBps": "1250"
},
{
"from": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"to": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
"source": "Uniswap_V4",
"proportionBps": "500"
},
{
"from": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"to": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
"source": "0x_RFQ",
"proportionBps": "333"
},
{
"from": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"to": "0xdac17f958d2ee523a2206206994597c13d831ec7",
"source": "Uniswap_V3",
"proportionBps": "499"
},
{
"from": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"to": "0xdac17f958d2ee523a2206206994597c13d831ec7",
"source": "Uniswap_V3",
"proportionBps": "749"
},
{
"from": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"to": "0xdac17f958d2ee523a2206206994597c13d831ec7",
"source": "Uniswap_V4",
"proportionBps": "749"
},
{
"from": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"to": "0xdac17f958d2ee523a2206206994597c13d831ec7",
"source": "0x_RFQ",
"proportionBps": "2169"
},
{
"from": "0xdac17f958d2ee523a2206206994597c13d831ec7",
"to": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
"source": "Ekubo",
"proportionBps": "4166"
},
{
"from": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
"to": "0x6b175474e89094c44da98b954eedeac495271d0f",
"source": "Maker_PSM",
"proportionBps": "10000"
}
],
"tokens": [
{
"address": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"symbol": "WETH"
},
{
"address": "0xdac17f958d2ee523a2206206994597c13d831ec7",
"symbol": "USDT"
},
{
"address": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
"symbol": "USDC"
},
{
"address": "0x6b175474e89094c44da98b954eedeac495271d0f",
"symbol": "DAI"
}
]
},
"sellAmount": "100000000000000000000",
"sellToken": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"tokenMetadata": {
"buyToken": {
"buyTaxBps": "0",
"sellTaxBps": "0"
},
"sellToken": {
"buyTaxBps": "0",
"sellTaxBps": "0"
}
},
"totalNetworkFee": "2857331463231986",
"zid": "0x2450cc642b05b3cebfd9bf35"
}
2. Set a Token Allowance
Before proceeding with the swap, you'll need to set a token allowance.
A token allowance lets a third party move your tokens on your behalf. Approve an allowance for the AllowanceHolder contract—do not approve the Settler contract.
Specify the amount of ERC20 tokens the contract can use.
For step-by-step instructions, see How to set your token allowances.
NEVER set an allowance on the Settler contract. Doing so may result in unintended consequences, including potential loss of tokens or exposure to security risks. The Settler contract does not support or require token allowances for its operation. Setting an allowance on the Settler contract will lead to misuse by other parties.
ONLY set allowances on AllowanceHolder or Permit2 contracts, as indicated by the API responses.
The correct allowance target is returned in
issues.allowance.spender
orallowanceTarget
.
When setting the token allowance, make sure to provide enough allowance for the buy or sell amount as well as the gas; otherwise, you may receive a 'Gas estimation failed' error.
Example Code
Here is an example of how to check and set token approvals.
See code example.
// Set up contracts. Note abi and client setup not show in this snippet
// Check if taker needs to set an allowance for AllowanceHolder
if (price.issues.allowance !== null) {
try {
const { request } = await usdc.simulate.approve([price.issues.allowance.spender, maxUint256]);
console.log('Approving AllowanceHolder to spend USDC...', request);
// Set approval
const hash = await usdc.write.approve(request.args);
console.log('Approved AllowanceHolder to spend USDC.', await client.waitForTransactionReceipt({ hash }));
} catch (error) {
console.log('Error approving AllowanceHolder:', error);
}
} else {
console.log('USDC already approved for AllowanceHolder');
}
3. Fetch a Firm Quote
When you're ready to execute a trade, request a firm quote from the Swap API using /swap/allowance-holder/quote
. This signals a soft commitment to complete the trade.
The response includes a full 0x order, ready for submission to the network. The Market Maker is expected to have reserved the necessary assets, reducing the likelihood of order reversion.
Example request
Here is an example to fetch a firm quote sell 100 WETH for DAI using /quote
.
See code example.
const qs = require('qs');
const params = {
sellToken: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', //WETH
buyToken: '0x6b175474e89094c44da98b954eedeac495271d0f', //DAI
sellAmount: '100000000000000000000', // Note that the WETH token uses 18 decimal places, so `sellAmount` is `100 * 10^18`.
taker: '$USER_TAKER_ADDRESS', //Address that will make the trade
chainId: '1', // / Ethereum mainnet. See the 0x Cheat Sheet for all supported endpoints: https://0x.org/docs/introduction/0x-cheat-sheet
};
const headers = {
'0x-api-key': '[api-key]', // Get your live API key from the 0x Dashboard (https://dashboard.0x.org/apps)
'0x-version': 'v2', // Add the version header
};
const response = await fetch(
`https://api.0x.org/swap/allowance-holder/quote?${qs.stringify(params)}`, { headers }
); /
console.log(await response.json());
Example Response
You will receive a response that looks like this:
Expand to see response
{
"allowanceTarget": "0x0000000000001ff3684f28c67538d4d072c22734",
"blockNumber": "23234770",
"buyAmount": "454443538468285000000000",
"buyToken": "0x6b175474e89094c44da98b954eedeac495271d0f",
"fees": {
"integratorFee": null,
"zeroExFee": {
"amount": "682689324469874696651",
"token": "0x6b175474e89094c44da98b954eedeac495271d0f",
"type": "volume"
},
"gasFee": null
},
"issues": {
"allowance": {
"actual": "0",
"spender": "0x0000000000001ff3684f28c67538d4d072c22734"
},
"balance": {
"token": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"actual": "0",
"expected": "100000000000000000000"
},
"simulationIncomplete": false,
"invalidSourcesPassed": []
},
"liquidityAvailable": true,
"minBuyAmount": "449892276190185000000000",
"route": {
"fills": [
{
"from": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"to": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
"source": "Swaap_V2",
"proportionBps": "4667"
},
{
"from": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"to": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
"source": "Uniswap_V4",
"proportionBps": "249"
},
{
"from": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"to": "0xdac17f958d2ee523a2206206994597c13d831ec7",
"source": "Swaap_V2",
"proportionBps": "5084"
},
{
"from": "0xdac17f958d2ee523a2206206994597c13d831ec7",
"to": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
"source": "Ekubo",
"proportionBps": "2977"
},
{
"from": "0xdac17f958d2ee523a2206206994597c13d831ec7",
"to": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
"source": "Uniswap_V4",
"proportionBps": "2107"
},
{
"from": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
"to": "0x6b175474e89094c44da98b954eedeac495271d0f",
"source": "Maker_PSM",
"proportionBps": "10000"
}
],
"tokens": [
{
"address": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"symbol": "WETH"
},
{
"address": "0xdac17f958d2ee523a2206206994597c13d831ec7",
"symbol": "USDT"
},
{
"address": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
"symbol": "USDC"
},
{
"address": "0x6b175474e89094c44da98b954eedeac495271d0f",
"symbol": "DAI"
}
]
},
"sellAmount": "100000000000000000000",
"sellToken": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"tokenMetadata": {
"buyToken": {
"buyTaxBps": "0",
"sellTaxBps": "0"
},
"sellToken": {
"buyTaxBps": "0",
"sellTaxBps": "0"
}
},
"totalNetworkFee": "1394929353342525",
"transaction": {
"to": "0x0000000000001ff3684f28c67538d4d072c22734",
"data": "0x2213bc0b000000000000000000000000df31a70a21a1931e02033dbba7deace6c45cfd0f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000056bc75e2d63100000000000000000000000000000df31a70a21a1931e02033dbba7deace6c45cfd0f00000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000015c41fff991f000000000000000000000000d8da6bf26964af9d7eed9e03e53415d37aa960450000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000000000000000000000005f44b58b9b89426fda0000000000000000000000000000000000000000000000000000000000000000a09c2d3156ecfc7dd6b4acc4630000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000000260000000000000000000000000000000000000000000000000000000000000074000000000000000000000000000000000000000000000000000000000000008800000000000000000000000000000000000000000000000000000000000000a200000000000000000000000000000000000000000000000000000000000000f0000000000000000000000000000000000000000000000000000000000000010a00000000000000000000000000000000000000000000000000000000000001240000000000000000000000000000000000000000000000000000000000000130000000000000000000000000000000000000000000000000000000000000013a000000000000000000000000000000000000000000000000000000000000000e4c1fb425e000000000000000000000000df31a70a21a1931e02033dbba7deace6c45cfd0f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000056bc75e2d6310000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000068af682800000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004a438c9c147000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000000000000000000000123a000000000000000000000000d315a9c38ec871068fec378e4ce78af528c76293000000000000000000000000000000000000000000000000000000000000016400000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000003c452bbbe2900000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000df31a70a21a1931e02033dbba7deace6c45cfd0f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000df31a70a21a1931e02033dbba7deace6c45cfd0f000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000068af67384342b77fe3417bcb09d0a4383301b0dc733c755b0002000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000287a14e152e3ac00000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000063d5e67538feb0000000000000000000000000000000000000000000000000000000068af673800000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000d8da6bf26964af9d7eed9e03e53415d37aa9604500000000000000000000000000000000000000000000000000005af3107a400000000000000000000000c7d8e44de55700000000000000028e1b3cf18d696ae10000000000000027f5bda00912bbcd4900000000000070bfcc701f0cdb824000000000000000000000000000000000000000000000120486891ab10b3aac089400000000000000004563918244f400000000000000000000006a94d74f43000000000000000000000000000068af66fc0000000000000000000060a24181e40000000000000000000000000000000000000000000000000000000000000000416b92f2bc37c5b6c58be07f27c56962bb4681899110f08215d0f2ecae97d7842127dd36f1d841112413a8b0de6ef3abe55030c3ab09f6d5a3321c2151d44fd9571b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010438c9c147000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000000000001d4000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000242e1a7d4d000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000164af72634f000000000000000000000000df31a70a21a1931e02033dbba7deace6c45cfd0f000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee000000000000000000000000000000000000000000000000000000000000271000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000ffffffffffffffc5000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000034271001a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800006400000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004a438c9c147000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000002710000000000000000000000000d315a9c38ec871068fec378e4ce78af528c76293000000000000000000000000000000000000000000000000000000000000016400000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000003c452bbbe2900000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000df31a70a21a1931e02033dbba7deace6c45cfd0f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000df31a70a21a1931e02033dbba7deace6c45cfd0f000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000068af6738315a892a4d02c5c1169d5f0e4f7cb4130cc0d1380002000000000000000000090000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec7000000000000000000000000000000000000000000000002c1744757125b600000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000063d5e67538fea0000000000000000000000000000000000000000000000000000000068af673800000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000d8da6bf26964af9d7eed9e03e53415d37aa9604500000000000000000000000000000000000000000000000000005af3107a400000000000000000000000c7dc25325d0e0000000000000002c8823dd0432e3570000000000000001925030dc1c20ec38c0000000000007c373c0210d77f425000000000000000000000000000000000000000000000131ba2ee23a8d1d090000000000000000000004563918244f400000000000000000000006a94d74f43000000000000000000000000000068af66fc0000000000000000000060a24181e40000000000000000000000000000000000000000000000000000000000000000411387297acd023146168a6733db8a4d46133f0dbbc530d6e47b6caf4ef7a6e1d37087e3ee6f0b2367afbfabfc0f53e17bbe27429a79c1c2bcf789887bc40ab6ce1b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001646c5f9cf9000000000000000000000000df31a70a21a1931e02033dbba7deace6c45cfd0f000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec700000000000000000000000000000000000000000000000000000000000016dd00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000ffffffffffffffc5000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000037271001a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000053e2d6238da300000032000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000164af72634f000000000000000000000000df31a70a21a1931e02033dbba7deace6c45cfd0f000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec7000000000000000000000000000000000000000000000000000000000000271000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000ffffffffffffffc5000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000034271001a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000a0000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000084bfda5292000000000000000000000000df31a70a21a1931e02033dbba7deace6c45cfd0f000000000000000000000000000000000000000000000000000000000000271000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000064c876d21d000000000000000000000000f5c4f3dc02c3fb9279495a8fef7b0741da9561570000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000000000000000000000000060607238d90dfd52aa8000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000012438c9c1470000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000000000000000000000000000000000000000000f0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000000000000000000000000000000000000000002400000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000044a9059cbb000000000000000000000000ad01c20d5886137e056775af56915de824c8fce50000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"gas": "832055",
"gasPrice": "1676486955",
"value": "0"
},
"zid": "0x9c2d3156ecfc7dd6b4acc463"
}
4. Submit the Transaction
Finally, submit the transaction using your preferred web3 library. In this example, we use viem’s sendTransaction
.
This sends the prepared transaction data to the blockchain.
See code example.
await client.sendTransaction({
to: quote?.transaction.to,
data: quote?.transaction.data,
value: quote?.transaction.value ? BigInt(quote.transaction.value) : undefined, // value is used for native tokens
});
See also
This wraps up the Swap API AllowanceHolder quickstart. See the links below for starter projects.