bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 27쪽 중 6쪽
urchase, bridge etc. has completed without any reversions and the user has received the intended funds.
**NEEDS\_GAS**
This state is specific for Axelar transactions. If the gas price has spiked on the destination chain and execution cannot complete, Squid will return this status. The best user flow in this case is to send the user to Axelarscan to view the paused transaction.
**ONGOING**
There is nothing wrong, nothing to do, just relax and wait. The transaction should have an `estimatedRouteDuration` in seconds that you can read from the `/route` response. We generally recommend contacting support after either 15 minutes has passed, or double the `estimatedRouteDuration`, whichever is larger.
**PARTIAL\_SUCCESS**
This status indicates that the transaction has completed some of its steps. Currently, there is only one case that could cause this state. In the future there will be many, but we will provide more metadata around the `PARTIAL_SUCCESS`. For now, this is what has happened:
* The source chain transaction successfully executed, along with any swaps or contract calls.
* The destination chain transaction has executed, but reverted during execution. This is usually due to slippage on volatile assets, but if you are trying to buy an NFT or do some cross-chain staking, then it could indicate that the custom hook had a failure.
If there is a partial success, the user will have received the bridged token in their wallet on the destination chain. In most cases this is axlUSDC.
**NOT\_FOUND**
The Squid API cannot find an on-chain record of the transaction. This is usually due to our various services or service providers not having indexed the completed transaction. This state is often returned for 5-10 seconds after the transaction was executed, while chain indexing occurs.
This should not persist after maximum a few minutes (some chains such as Filecoin take a very long time to index, and for block inclusion). If it does, then get in touch with us on Discord.
**REFUND\_STATUS**
This status is specific to failed Squid Intents routes. When a Squid Intents transaction fails, the funds are automatically refunded on the source chain. This is the default behavior for Squid Intents routes when passing the user's address as the `fromAddress`.
**How Squid Intents refunds work:**
* Funds are always transferred from the `msg.sender` on the source chain (this could be the user for direct calls to Squid Intents, or a smart contract like Multicall)
* When refunded, funds are sent to the `order.fromAddress` which is encoded to the user, not the caller
* The `fromAddress` from the route request is used as the `order.fromAddress` for refunds
* This ensures that even if the transaction was initiated through a smart contract, the refund goes to the actual user
### Example Response
```json
{
"id": "0x7591aa38d646ac26b57f7235836cb7e7b63a32534bdd2e5dcecf06136744a94d",
"status": "success",
"gasStatus": "",
"isGMPTransaction": false,
"axelarTransactionUrl": "",
"fromChain": {
"transactionId": "0x7591aa38d646ac26b57f7235836cb7e7b63a32534bdd2e5dcecf06136744a94d",
"blockNumber": "339763809",
"callEventStatus": "",
"callEventLog": [],
"chainData": {
"id": "42161",
"chainId": "42161",
"networkIdentifier": "arbitrum",
"chainName": "Chain 42161",
"axelarChainName": "Arbitrum",
"type": "evm",
"networkName": "Arbitrum",
"nativeCurrency": {
"name": "Arbitrum",
"symbol": "ETH",
"decimals": 18,
"icon": "https://raw.githubusercontent.com/axelarnetwork/axelar-docs/main/public/images/chains/arbitrum.svg"
},
"chainIconURI": "https://raw.githubusercontent.com/0xsquid/assets/main/images/webp128/chains/arbitrum.webp",
"blockExplorerUrls": [
"https://arbiscan.io/"
],
"swapAmountForGas": "2000000",
"sameChainSwapsSupported": true,
"compliance": {
"trmIdentifier": "arbitrum"
},
"rpcList": [
"https://arb1.arbitrum.io/rpc"
],
"visible": true,
"chainNativeContracts": {
"wrappedNativeToken": "0x82af49447d8a07e3bd95bd0d56f35241523fbab1",
"ensRegistry": "",
"multicall": "0xcA11bde05977b3631167028862bE2a173976CA11",
"usdcToken": "0xff970a61a04b1ca14834a43f5de4533ebddb5cc8"
},
"feeCurrencies": [],
"currencies": [],
"features": []
},
"transactionUrl": "https://arbiscan.io/tx/0x7591aa38d646ac26b57f7235836cb7e7b63a32534bdd2e5dcecf06136744a94d"
},
"toChain": {
"transactionId": "0x4579e4df67994f4b1790d51c1586cbe79048dafd9c69467de1ecc887b4a25186",
"blockNumber": "30616439",
"callEventStatus": "",
"callEventLog": [],
"chainData": {
"id": "8453",
"chainId": "8453",
"networkIdentifier": "base",
"chainName": "Chain 8453",
"axelarChainName": "base",
"type": "evm",
"networkName": "Base",
"nativeCurrency": {
"name": "Base",
"symbol": "ETH",
"decimals": 18,
"icon": "https://raw.githubusercontent.com/axelarnetwork/axelar-docs/main/public/images/chains/base.svg"
},
"chainIconURI": "https://raw.githubusercontent.com/0xsquid/assets/main/images/chains/base.svg",
"blockExplorerUrls": [
"https://basescan.org/"
],
"swapAmountForGas": "2000000",
"sameChainSwapsSupported": true,
"rpcList": [
"https://developer-access-mainnet.base.org"
],
"visible": true,
"chainNativeContracts": {
"wrappedNativeToken": "0x4200000000000000000000000000000000000006",
"ensRegistry": "",
"multicall": "0xcA11bde05977b3631167028862bE2a173976CA11",
"usdcToken": "0x66627F389ae46D881773B7131139b2411980E09E"
},
"feeCurrencies": [],
"currencies": [],
"features": [],
"axelarFeeMultiplier": 150
},
"transactionUrl": "https://basescan.org/tx/0x4579e4df67994f4b1790d51c1586cbe79048dafd9c69467de1ecc887b4a25186"
},
"timeSpent": {
"total": 2
},
"routeStatus": [
{
"chainId": "42161",
"txHash": "0x7591aa38d646ac26b57f7235836cb7e7b63a32534bdd2e5dcecf06136744a94d",
"status": "success",
"action": "send"
},
{
"chainId": "8453",
"txHash": "0x4579e4df67994f4b1790d51c1586cbe79048dafd9c69467de1ecc887b4a25186",
"status": "success",
"action": "call"
}
],
"squidTransactionStatus": "success"
}
```
# Authentication
All Squid API requests require authentication via an **integrator ID**. This page covers how to obtain credentials, use them correctly, and follow security best practices.
***
## Request Your Integrator ID
Squid issues Integrator IDs on a limited basis and upon review.
1. **Submit a request** via the [partnerships form](https://squidrouter.typeform.com/partnerships) with details about your project and integration requirements.
2. **Review & Follow-up** — a member of the Squid team will review your submission and follow up regarding approval and credential issuance.
{% hint style="info" %}
The integrator ID is required for all API, SDK, and widget integrations. The Squid API will reject any request without a valid integrator ID.
{% endhint %}
***
## Using Your Integrator ID
### API Requests
Include your integrator ID in the `x-integrator-id` HTTP header on every request:
```bash
curl -X POST 'https://v2.api.squidrouter.com/v2/route' \
-H 'x-integrator-id: YOUR_INTEGRATOR_ID' \
-H 'Content-Type: application/json' \
-d '{ ... }'
```
### SDK Initialization
Pass your integrator ID when creating the Squid SDK instance:
```typescript
import { Squid } from "@0xsquid/sdk";
const squid = new Squid({
baseUrl: "https://v2.api.squidrouter.com",
integratorId: "YOUR_INTEGRATOR_ID",
});
await squid.init();
```
### Widget Configuration
Include your integrator ID in the widget configuration:
```typescript
<SquidWidget
config={{
integratorId: "YOUR_INTEGRATOR_ID",
// ... other config options
}}
/>
```
***
## Error Response
If the integrator ID is missing or invalid, the API returns:
```json
{
"message": "x-integrator-id header is missing",
"type": "UNAUTHORIZED"
}
```
***
## Security Best Practices
{% hint style="warning" %}
**Never expose your integrator ID in client-side code** if your ID has elevated privileges or custom rate limits. For public-facing widget integrations, the standard integrator ID is safe to include in frontend code.
{% endhint %}
* **Server-side usage**: For API integrations, make Squid API calls from your backend server, never directly from browser JavaScript.
* **Environment variables**: Store your integrator ID in environment variables (`.env`), not in source code.
# Rate Limiting
The Squid API enforces rate limits to ensure fair usage and protect infrastructure. This page documents the rate limiting behavior you may encounter when integrating.
***
## Authentication Required
All API requests must include a valid `x-integrator-id` header. Requests without this header will receive:
```json
{
"message": "x-integrator-id header is missing",
"type": "UNAUTHORIZED"
}
```
***
## Request Rate (RPS)
Every integrator ID is issued with a **requests-per-second (RPS)** limit that controls how many API calls you can make per second across all endpoints.
| Stage | Default RPS | Notes |
| ------------------------- | ----------- | ------------------------------------------------------------ |
| **Testing / Development** | 1 RPS | Issued with every new integrator ID |
| **Production** | 10 RPS | Request an upgrade from the Squid team when ready to go live |
| **High Volume** | Custom | Contact the team for higher limits based on your usage needs |
### How to request an RPS increase
1. Ensure your integration is tested and production-ready.
2. Contact the Squid team via [Discord](https://discord.gg/squidrouter) or <support@squidrouter.com>.
3. Specify your expected traffic volume and use case.
{% hint style="warning" %}
If you exceed your RPS limit, requests will be throttled. Make sure to request an upgrade **before** launching to production to avoid interruptions for your users.
{% endhint %}
***
## Wallet-Based Quote Rate Limit
When requesting routes with `quoteOnly: false` (the default), the API enforces a per-wallet rate limit to prevent duplicate transaction data from being generated.
### Why this limit exists
When `quoteOnly` is `false`, the API generates full transaction call data (including signed solver quotes for Squid Intents routes). Submitting identical requests for the same wallet in rapid succession would produce the same call data, wasting compute and potentially causing transaction conflicts.
### Error Response
If you exceed the rate limit, the API returns:
```json
{
"error": "Too many quote requests for this address",
"retryAfter": 1
}
```
| Field | Type | Description |
| ------------ | -------- | ----------------------------------------- |
| `error` | `string` | Human-readable error message |
| `retryAfter` | `number` | Number of seconds to wait before retrying |
### How to handle this
1. **Wait and retry** — respect the `retryAfter` value before sending another request for the same wallet.
2. **Use `quoteOnly: true` for price discovery** — if you only need a price estimate (e.g., for display purposes), set `quoteOnly: true` in your route request. This returns a quote without generating transaction data and is not subject to the same rate limit.
3. **Cache quotes** — if your UI needs to refresh prices, cache the previous quote and only request a new one after a reasonable interval.
### Example: Using quoteOnly for price display
```typescript
// For UI price display — not rate limited
const quoteParams = {
fromAddress: userAddress,
fromChain: "56",
fromToken: "0x55d398326f99059fF775485246999027B3197955",
fromAmount: "1000000000000000",
toChain: "42161",
toToken: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
toAddress: userAddress,
quoteOnly: true, // Only returns pricing, no tx data
};
// When user clicks "Swap" — request full route with tx data
const execParams = {
...quoteParams,
quoteOnly: false, // Generates transaction data (rate limited per wallet)
};
```
{% hint style="info" %}
The rate limit applies **per wallet address**. Different wallet addresses can request routes concurrently without triggering the limit.
{% endhint %}
***
## General Best Practices
* **Separate quote from execution** — use `quoteOnly: true` for displaying prices and only request full transaction data when the user initiates a swap.
# Error Codes
This page documents the error responses you may encounter when using the Squid API. Understanding these errors will help you build robust error handling into your integration.
***
## HTTP Error Responses
| HTTP Status | Type | Description |
| ----------- | ---------------- | ----------------------------------------------------------------------------------- |
| `400` | `BAD_REQUEST` | Invalid or missing request parameters |
| `401` | `UNAUTHORIZED` | Missing or invalid `x-integrator-id` header |
| `404` | `NOT_FOUND` | Resource not found (e.g., unknown transaction ID) |
| `429` | `RATE_LIMITED` | Too many requests — see [Rate Limiting](/api-and-sdk-integration/api/rate-limiting) |
| `500` | `INTERNAL_ERROR` | Server-side error — retry with backoff |
***
## Route Request Errors
These errors are returned by the `POST /v2/route` endpoint:
| Error Message | Cause | Resolution |
| ------------------------------------------ | -------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------- |
| `x-integrator-id header is missing` | Request missing the required auth header | Add the `x-integrator-id` header to every request |
| `Too many quote requests for this address` | Duplicate `quoteOnly: false` request for the same wallet | Wait `retryAfter` seconds, or use `quoteOnly: true` for price display |
| `No route found` | No valid route exists for the given parameters | Check that source/destination chains and tokens are supported. Verify sufficient liquidity exists. |
| `Amount too low` | The `fromAmount` is below the minimum for the route | Increase the swap amount |
| `Amount too high` | The `fromAmount` exceeds the maximum for the route | Decrease the swap amount |
| `Unsupported chain` | The specified chain ID is not supported | Check the [supported chains list](/chains-and-tokens/get-supported-tokens-and-chains) |
| `Unsupported token` | The specified token address is not whitelisted | Verify the token address. Only [whitelisted tokens](/additional-resources/compliance-and-security) are supported. |
#### Example: Unsupported Token
```json
{
"message": "Token is not supported for toChain: 8453 toToken: 0xeeeeeeseeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee.",
"statusCode": 400,
"type": "BAD_REQUEST"
}
```
#### Example: Unsupported Chain
```json
{
"message": "toChain: 84353 unsupported chain id",
"statusCode": 400,
"type": "SCHEMA_VALIDATION_ERROR"
}
```
***
## Status API Errors
These errors are returned by the `GET /v2/status` endpoint:
| HTTP Status | Scenario | Resolution |
| ----------- | --------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
| `404` | Transaction not yet indexed | Retry after 5 seconds. Indexing typically takes 5–10 seconds after execution. Some chains (e.g., Filecoin) take longer. |
| `400` | Missing required parameters | Ensure `transactionId`, `fromChainId`, `toChainId`, and `quoteId` are provided. |
***
## Transaction Status Values
After a transaction is submitted, the status API returns a `squidTransactionStatus` field. See [Track Status](/api-and-sdk-integration/key-concepts/track-status) for details on each status:
| Status | Description |
| ----------------- | ---------------------------------------------------------------------- |
| `success` | Transaction completed on all chains |
| `ongoing` | Transaction in progress — no action needed |
| `needs_gas` | Gas price spike on destination chain (Axelar routes only) |
| `partial_success` | Source chain executed but destination reverted |
| `not_found` | Transaction not yet indexed — retry shortly |
| `refund` | Squid Intents route failed — funds refunded on source chain (\~10 min) |
***
## Best Practices
1. **Always check the HTTP status code** before parsing the response body.
2. **Log the full error response** — Squid error payloads include descriptive messages.
3. **Use `quoteOnly: true`** for price discovery to avoid rate limit errors.
# SDK
## Overview
The SDK is ideal for integrating cross-chain swaps, bridges, and deposits into applications that utilize JavaScript or Typescript, while the API can be used for similar purposes in a more language-agnostic manner.
## Types
We recommend using the types from our npm package. If you are using our API without our SDK, you can find the types inside `node_modules/@0xsquid/sdk/dist/types/index.d.ts` after installing the SDK (`npm install @0xsquid/sdk`).
```typescript
import { Token, ChainData } from '@0xsquid/sdk/dist/types'
```
## **Installing the SDK**
### From the terminal, install [our SDK](https://www.npmjs.com/package/@0xsquid/sdk)
```bash
npm install --save @0xsquid/sdk@2.12.0 # or higher
```
### Now in your typescript file
```typescript
import { Squid } from "@0xsquid/sdk"; // Import Squid SDK
// Initialize the Squid client with the base URL and integrator ID
const getSDK = (): Squid => {
const squid = new Squid({
baseUrl: "https://v2.api.squidrouter.com",
integratorId: integratorId,
});
return squid;
};
```
Next, explore the first [**Swap & Bridging with the Squid SDK** ](/old-v2-documentation-deprecated/api/swap-and-bridge-example)to understand the fundamentals.
# Cross-chain Swap Example
Here is an example of a cross-chain swap that you can run out of the box. Head to our [examples repo](https://github.com/0xsquid/examples/tree/main/V2/sdk/evmToEVMSwap), download the folder and run:
```
yarn install
```
Create a .env file and replace the values shared in the .env.example file. Then run
```
yarn start
```
This will run the index.ts below
```typescript
import { Squid } from "@0xsquid/sdk"; // Import Squid SDK
import { ethers } from "ethers"; // Import ethers v6
import * as dotenv from "dotenv"; // Import dotenv for environment variables
dotenv.config(); // Load environment variables from .env file
// Retrieve environment variables
const privateKey: string = process.env.PRIVATE_KEY!;
const integratorId: string = process.env.INTEGRATOR_ID!;
const FROM_CHAIN_RPC: string = process.env.FROM_CHAIN_RPC_ENDPOINT!;
if (!privateKey || !integratorId || !FROM_CHAIN_RPC) {
console.error("Missing environment variables. Ensure PRIVATE_KEY, INTEGRATOR_ID, and FROM_CHAIN_RPC_ENDPOINT are set.");
process.exit(1);
}
// Define chain and token addresses
const fromChainId = "56"; // BNB chain ID
const toChainId = "42161"; // Arbitrum chain ID
const fromToken = "0x55d398326f99059fF775485246999027B3197955"; // USDT token address on BNB
const toToken = "0xaf88d065e77c8cC2239327C5EDb3A432268e5831"; // USDC token address on Arbitrum
// Define the amount to be sent (in smallest unit, e.g., wei for Ethereum)
const amount = "1000000000000000";
// Set up JSON RPC provider and signer using the private key and RPC URL
// Create provider with the full URL
const provider = new ethers.JsonRpcProvider(FROM_CHAIN_RPC);
// Create wallet with the private key
const signer = new ethers.Wallet(privateKey, provider);
// Initialize the Squid client with the base URL and integrator ID
const getSDK = (): Squid => {
const squid = new Squid({
baseUrl: "https://v2.api.squidrouter.com",
integratorId: integratorId,
});
return squid;
};
// Function to approve the transactionRequest.target to spend fromAmount of fromToken
const approveSpending = async (transactionRequestTarget: string, fromToken: string, fromAmount: string) => {
const erc20Abi = [
"function approve(address spender, uint256 amount) public returns (bool)"
];
const tokenContract = new ethers.Contract(fromToken, erc20Abi, signer);
try {
const tx = await tokenContract.approve(transactionRequestTarget, fromAmount);
await tx.wait();
console.log(`Approved ${fromAmount} tokens for ${transactionReques프로젝트로 돌아가기