Introduction
Guides
Components
- Appchain
- Buy
- Checkout
- Earn
- Fund
- Identity
- Mint
- <Signature />
- Swap
- Token
- <Transaction />
- Wallet
API
- Mint
- Swap
- Token
- Wallet
Utilities
- Config
- Earn
- Fund
- Identity
- Mint
- Token
- Wallet
Contribution
Swap
getSwapQuote
GET
/
getSwapQuote
Copy
Ask AI
import { setOnchainKitConfig } from '@coinbase/onchainkit';
import { getSwapQuote } from '@coinbase/onchainkit/api';
import type { Token } from '@coinbase/onchainkit/token';
setOnchainKitConfig({ apiKey: 'YOUR_API_KEY' });
const fromToken: Token = {
name: 'ETH',
address: '',
symbol: 'ETH',
decimals: 18,
image: 'https://wallet-api-production.s3.amazonaws.com/uploads/tokens/eth_288.png',
chainId: 8453,
};
const toToken: Token = {
name: 'USDC',
address: '0x833589fcd6edb6e08f4c7c32d4f71b54bda02913',
symbol: 'USDC',
decimals: 6,
image:
'https://d3r81g40ycuhqg.cloudfront.net/wallet/wais/44/2b/442b80bd16af0c0d9b22e03a16753823fe826e5bfd457292b55fa0ba8c1ba213-ZWUzYjJmZGUtMDYxNy00NDcyLTg0NjQtMWI4OGEwYjBiODE2',
chainId: 8453,
};
const quote = await getSwapQuote({
from: fromToken,
to: toToken,
amount: '0.001',
useAggregator: false,
});
Copy
Ask AI
{
"amountReference": "from",
"chainId": 8453,
"from": {
"address": "",
"chainId": 8453,
"decimals": 18,
"image": "https://wallet-api-production.s3.amazonaws.com/uploads/tokens/eth_288.png",
"name": "ETH",
"symbol": "ETH"
},
"to": {
"address": "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913",
"chainId": 8453,
"decimals": 6,
"image": "https://d3r81g40ycuhqg.cloudfront.net/wallet/wais/…-ZWUzYjJmZGUtMDYxNy00NDcyLTg0NjQtMWI4OGEwYjBiODE2",
"name": "USDC",
"symbol": "USDC"
},
"fromAmount": "1000000000000000",
"fromAmountUSD": "2.6519265340000002",
"toAmount": "2650405",
"toAmountUSD": "2.64980125",
"priceImpact": "0",
"highPriceImpact": false,
"slippage": "3"
}
The getSwapQuote
function is used to get a quote for a swap between two Tokens.
Before using them, make sure to obtain a Client API Key from Coinbase Developer Platform.
Returns
Parameters
Types
Body
application/json
Response
200 - application/json
Successful response
The response is of type object
.
Was this page helpful?
Copy
Ask AI
import { setOnchainKitConfig } from '@coinbase/onchainkit';
import { getSwapQuote } from '@coinbase/onchainkit/api';
import type { Token } from '@coinbase/onchainkit/token';
setOnchainKitConfig({ apiKey: 'YOUR_API_KEY' });
const fromToken: Token = {
name: 'ETH',
address: '',
symbol: 'ETH',
decimals: 18,
image: 'https://wallet-api-production.s3.amazonaws.com/uploads/tokens/eth_288.png',
chainId: 8453,
};
const toToken: Token = {
name: 'USDC',
address: '0x833589fcd6edb6e08f4c7c32d4f71b54bda02913',
symbol: 'USDC',
decimals: 6,
image:
'https://d3r81g40ycuhqg.cloudfront.net/wallet/wais/44/2b/442b80bd16af0c0d9b22e03a16753823fe826e5bfd457292b55fa0ba8c1ba213-ZWUzYjJmZGUtMDYxNy00NDcyLTg0NjQtMWI4OGEwYjBiODE2',
chainId: 8453,
};
const quote = await getSwapQuote({
from: fromToken,
to: toToken,
amount: '0.001',
useAggregator: false,
});
Copy
Ask AI
{
"amountReference": "from",
"chainId": 8453,
"from": {
"address": "",
"chainId": 8453,
"decimals": 18,
"image": "https://wallet-api-production.s3.amazonaws.com/uploads/tokens/eth_288.png",
"name": "ETH",
"symbol": "ETH"
},
"to": {
"address": "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913",
"chainId": 8453,
"decimals": 6,
"image": "https://d3r81g40ycuhqg.cloudfront.net/wallet/wais/…-ZWUzYjJmZGUtMDYxNy00NDcyLTg0NjQtMWI4OGEwYjBiODE2",
"name": "USDC",
"symbol": "USDC"
},
"fromAmount": "1000000000000000",
"fromAmountUSD": "2.6519265340000002",
"toAmount": "2650405",
"toAmountUSD": "2.64980125",
"priceImpact": "0",
"highPriceImpact": false,
"slippage": "3"
}
Assistant
Responses are generated using AI and may contain mistakes.