Skip to main content

Overview

This guide will help you make your first API call to Crest and integrate swap and bridge functionality into your application.

Authentication

Coming Soon - Authentication and API key management is currently being finalized. Check back soon for detailed instructions on obtaining and using API keys.
In the meantime, you can explore the API structure and prepare your integration.

Base URL

All API requests should be made to:
https://api.crestapp.xyz
The base URL and endpoint structure is subject to change before official launch. We’ll provide migration guides for any breaking changes.

Making Your First Request

Get a Swap Quote

Request a quote for swapping tokens:
const response = await fetch('https://api.crestapp.xyz/v1/quote', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    // 'Authorization': 'Bearer YOUR_API_KEY' // Coming soon
  },
  body: JSON.stringify({
    fromToken: 'USDC',
    toToken: 'ETH',
    fromChain: 'ethereum',
    toChain: 'ethereum',
    amount: '1000',
    userAddress: '0x...'
  })
});

const quote = await response.json();
console.log(quote);

Expected Response

The API returns the best quote along with an array of steps to execute:
{
  "quoteId": "abc123...",
  "fromToken": {
    "address": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
    "symbol": "USDC",
    "decimals": 6
  },
  "toToken": {
    "address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
    "symbol": "WETH",
    "decimals": 18
  },
  "fromChain": "ethereum",
  "toChain": "ethereum",
  "fromAmount": "1000000000", // 1000 USDC in base units
  "toAmount": "420000000000000000", // 0.42 ETH in base units
  "estimatedGas": "350000",
  "provider": "1inch",
  "expiresAt": "2024-01-15T12:35:00Z",
  "steps": [
    {
      "type": "approval",
      "description": "Approve USDC spending",
      "tx": {
        "to": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
        "data": "0x095ea7b3000000000000000000000000...",
        "value": "0",
        "gasLimit": "50000"
      }
    },
    {
      "type": "transaction",
      "description": "Execute swap",
      "tx": {
        "to": "0x1111111254EEB25477B68fb85Ed929f73A960582",
        "data": "0x12aa3caf000000000000000000000000...",
        "value": "0",
        "gasLimit": "300000"
      }
    }
  ]
}

Execute the Steps

Use the returned steps array to execute each step sequentially:
import { createWalletClient, custom, parseSignature } from 'viem';
import { mainnet } from 'viem/chains';

// Create wallet client
const walletClient = createWalletClient({
  chain: mainnet,
  transport: custom(window.ethereum)
});

const [account] = await walletClient.getAddresses();

// Get quote from Crest API
const response = await fetch('https://api.crestapp.xyz/v1/quote', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    fromToken: 'USDC',
    toToken: 'ETH',
    fromChain: 'ethereum',
    toChain: 'ethereum',
    amount: '1000000000', // 1000 USDC in base units
    userAddress: account
  })
});

const quote = await response.json();

// Execute each step sequentially
for (const step of quote.steps) {
  if (step.type === 'approval' || step.type === 'transaction') {
    // Send transaction
    const hash = await walletClient.sendTransaction({
      account,
      to: step.tx.to,
      data: step.tx.data,
      value: BigInt(step.tx.value),
      gas: BigInt(step.tx.gasLimit)
    });

    console.log(`${step.description}: ${hash}`);

    // Wait for confirmation
    await walletClient.waitForTransactionReceipt({ hash });
  }
  else if (step.type === 'signature') {
    // Sign message
    const signature = await walletClient.signMessage({
      account,
      message: step.message
    });

    console.log(`${step.description}: ${signature}`);
  }
}

console.log('Swap completed successfully!');

Basic Integration Flow

Here’s a typical integration flow for adding Crest to your application:
  1. Request Quote - User initiates a swap, you call /quote endpoint
  2. Display Quote - Show the user estimated amounts, rates, and fees
  3. User Confirms - User reviews and confirms the transaction
  4. Execute Steps - Loop through the steps array and execute each step (approvals, signatures, transactions)
  5. Monitor Status - Track each transaction status and wait for confirmations
  6. Show Confirmation - Display success message and transaction details
Always execute steps in order. Some swaps may require multiple steps like token approvals before the actual swap transaction.

Rate Limits

TBD - Rate limits will be implemented in the future.