Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: getSwapQuote #525

Merged
merged 4 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions site/docs/pages/swap/get-swap-quote.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# `getSwapQuote`

The `getSwapQuote` function is used to get a quote for a swap between two Tokens.

## Usage

:::code-group

```tsx [code]
import { getSwapQuote } from '@coinbase/onchainkit/swap';

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',
});
```

```json [return value]
{
"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"
},
"fromAmount": "1000000000000000",
"highPriceImpact": false,
"priceImpact": "0.16",
"slippage": "3",
"to": {
"address": "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913",
"chainId": 8453,
"decimals": 6,
"image": "https://d3r81g40ycuhqg.cloudfront.net/wallet/wais/…-ZWUzYjJmZGUtMDYxNy00NDcyLTg0NjQtMWI4OGEwYjBiODE2",
"name": "USDC"
},
"toAmount": "3547037"
}
```

:::

## Returns

[`Promise<GetSwapQuoteResponse>`](/token/types#GetSwapQuoteResponse)

## Parameters

[`GetSwapQuoteParams`](/token/types#GetSwapQuoteParams)
10 changes: 10 additions & 0 deletions site/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,16 @@ export const sidebar = [
},
],
},
{
text: 'Utilities',
collapsed: true,
items: [
{
text: 'getSwapQuote',
link: '/swap/get-swap-quote',
},
],
},
{
text: 'Types',
link: '/swap/types',
Expand Down
Loading