Documentation Index
Fetch the complete documentation index at: https://docs.cloud.coinbase.com/llms.txt
Use this file to discover all available pages before exploring further.
function getSwapPrice(options: GetSwapPriceOptions): Promise<
| GetSwapPriceResult
| SwapUnavailableResult>;
Gets a non-binding indicative price for a token swap.
Read-only operation — does not modify any on-chain state.
Parameters
| Parameter | Type | Description |
|---|
options | GetSwapPriceOptions | The swap price request parameters. |
Returns
Promise<
| GetSwapPriceResult
| SwapUnavailableResult>
Price estimate if liquidity is available, otherwise { liquidityAvailable: false }.
Throws
An InputValidationError if parameters are invalid.
Throws
An Error if the response is missing required fields when liquidity is available.
Example
const price = await getSwapPrice({
network: "base",
fromToken: "0x4200000000000000000000000000000000000006",
toToken: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
fromAmount: "100000000000000000",
});
if (price.liquidityAvailable) {
console.log("Expected output:", price.toAmount);
}