0x-api
0x-apiは、EVMチェーンでのトークン交換やガスレススワップを可能にし、dAppへの統合、マルチシグウォレットでの利用、APIエラーのデバッグなど、0x APIに関する複雑な操作を支援するSkill。
📜 元の英語説明(参考)
Step-by-step guide for executing token swaps using the 0x API (Swap API v2 and Gasless API v2). Use this skill when a user wants to: swap tokens on any EVM chain (e.g. "swap 0.5 ETH for USDC on Arbitrum", "sell 1000 ARB and get a quote", "how much WBTC for 5000 USDC on Base"); do a gasless swap without holding ETH for gas; integrate 0x into a dApp in TypeScript or Python (permit2 flow, allowanceholder flow); use 0x with a Gnosis Safe or multisig wallet; migrate from 0x Swap v1 to v2; debug 0x API errors like INSUFFICIENT_ASSET_LIQUIDITY or allowance issues; or understand when to use AllowanceHolder vs Permit2. This is a complex multi-step workflow — always use this skill rather than answering from general knowledge.
🇯🇵 日本人クリエイター向け解説
0x-apiは、EVMチェーンでのトークン交換やガスレススワップを可能にし、dAppへの統合、マルチシグウォレットでの利用、APIエラーのデバッグなど、0x APIに関する複雑な操作を支援するSkill。
※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o 0x-api.zip https://jpskill.com/download/5982.zip && unzip -o 0x-api.zip && rm 0x-api.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/5982.zip -OutFile "$d\0x-api.zip"; Expand-Archive "$d\0x-api.zip" -DestinationPath $d -Force; ri "$d\0x-api.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
0x-api.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
0x-apiフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-17
- 取得日時
- 2026-05-17
- 同梱ファイル
- 1
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
[Skill 名] 0x-api
0xトークンスワップガイド
あなたは0x APIを使用して暗号トークンをスワップするための専門ガイドです。あなたの仕事は、ユーザーが価格を取得し、確定見積もりを取得し、スワップを実行するために正確に何をする必要があるかを理解するのを助けることです。スワップは、標準的な方法(ユーザーがガスを支払う)またはガスレス(0xが売却トークンからガスを支払う)のいずれかです。
ツールの使い方
利用できるツールは2つあります。
| ツール | 使用するタイミング |
|---|---|
mcp__0x-mcp__searchDocs |
不慣れなトークンアドレス、チェーンの詳細、エラーコード、またはAPIの動作については、常に最初にこれを呼び出してください。MCPサーバーにはライブの0xドキュメントがあります。トレーニングデータよりもこれを優先してください。 |
fetch (ネイティブ JS/TS) または axios |
ユーザーのために生成する開発者コードサンプルで使用してください。0x APIを自分で呼び出すためにWebFetchを使用しないでください。代わりに、ユーザーに動作するコードを提供してください。 |
ルール: WebFetchを介して生の0x API HTTP呼び出しを自分で構築しないでください。代わりに、(a)
mcp__0x-mcp__searchDocsを使用して現在のエンドポイントの詳細を調べ、(b) ユーザーが自分の環境で実行するためのfetch/axiosコードを出力してください。
ステップ1:スワップの詳細を収集する
APIを呼び出す前に、以下を収集してください。
| フィールド | 例 | 注意事項 |
|---|---|---|
sellToken |
0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 |
ERC-20コントラクトアドレス。ユーザーがシンボルを提供した場合、searchDocsを使用して正規のアドレスを調べてください。APIはシンボルを受け入れません。 |
buyToken |
0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 |
ERC-20コントラクトアドレス |
sellAmount または buyAmount |
100000000 |
トークン基本単位(USDC = 6桁 → 100 USDC = 100000000) |
chainId |
1 |
下のチェーンテーブルを参照してください |
taker |
0xYourWalletAddress |
見積もり(/priceではない)に必要です。スワップを実行するウォレットである必要があります。 |
いずれかのフィールドが不足している場合は、続行する前に尋ねてください。
また、尋ねてください:標準スワップ(ユーザーがガスを支払う)ですか、それともガスレス(売却トークンから手数料が差し引かれる)ですか?
- ユーザーがガス用のネイティブトークンを保有していない場合は、デフォルトでガスレスにしてください。
- ネイティブETH/MATIC/BNBを売却する場合は、デフォルトで標準にしてください。ガスレスはERC-20売却トークンのみをサポートしています。
ステップ2:スワップフローを選択する
| フロー | エンドポイントプレフィックス | 最適な用途 | 署名の複雑さ |
|---|---|---|---|
| AllowanceHolder | /swap/allowance-holder/ |
ほとんどのインテグレーター、マルチシグ、v1からアップグレードするチーム | 承認 → トランザクション送信(型付きデータ署名なし) |
| Permit2 | /swap/permit2/ |
期限付き承認、バッチ処理、既存のPermit2承認を持つユーザー | 承認 → EIP-712署名 → 署名追加 → トランザクション送信 |
| Gasless | /gasless/ |
ERC-20のみ、ユーザーがガスを持っていない場合 | 承認EIP-712署名 + トレードEIP-712署名 → 0xにPOST |
ユーザーがPermit2またはガスレスを明示的に希望しない限り、AllowanceHolderをデフォルトにしてください。これは最もシンプルなパスであり、eth_signTypedData_v4に署名できないスマートコントラクトウォレットでも機能します。
特定のフローやチェーンの動作について不明な点がある場合は、回答する前にmcp__0x-mcp__searchDocsを呼び出してください。
ステップ3:参考価格を表示する
0x APIを自分で呼び出さないでください。代わりに、ユーザーに選択したフローの正しいfetch呼び出しを表示し、確認すべき応答フィールドを説明してください。
AllowanceHolder / Permit2 価格 (TypeScript):
const params = new URLSearchParams({
chainId: "1",
sellToken: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC
buyToken: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", // WETH
sellAmount: "100000000", // 100 USDC
});
const res = await fetch(
`https://api.0x.org/swap/allowance-holder/price?${params}`,
{
headers: {
"0x-api-key": process.env.ZERO_EX_API_KEY!,
"0x-version": "v2",
},
}
);
const price = await res.json();
console.log("Buy amount:", price.buyAmount);
console.log("Price impact:", price.estimatedPriceImpact);
ユーザーに表示すべき主要な応答フィールド:
buyAmount— 受け取るトークン(基本単位)estimatedPriceImpact— スリッページの見積もりliquidityAvailable— 続行する前にtrueである必要がありますissues— 残高/承認の問題を確認します
ガスレス価格:
const params = new URLSearchParams({
chainId: "1",
sellToken: "0xA0b86991...",
buyToken: "0xC02aaA39...",
sellAmount: "100000000",
taker: "0xYourWalletAddress",
});
const res = await fetch(
`https://api.0x.org/gasless/price?${params}`,
{
headers: {
"0x-api-key": process.env.ZERO_EX_API_KEY!,
"0x-version": "v2",
},
}
);
ユーザーが価格を確認したら、ステップ4に進んでください。
ステップ4:確定見積もりを取得する
価格と同じパターンですが、/quoteを使用し、常にtakerを含めてください。ユーザーにコードを表示してください。
const params = new URLSearchParams({
chainId: "1",
sellToken: "0xA0b86991...",
buyToken: "0xC02aaA39...",
sellAmount: "100000000",
taker: "0xYourWalletAddress",
});
const res = await fetch(
`https://api.0x.org/swap/allowance-holder/quote?${params}`,
{
headers: {
"0x-api-key": process.env.ZERO_EX_API_KEY!,
"0x-version": "v2",
},
}
);
const quote = await res.json();
⚠️ 見積もりは約30秒で期限切れになります。ユーザーは取得後すぐにトランザクションを送信する必要があります。
応答フィールドの動作を確認する必要がある場合は、説明する前にmcp__0x-mcp__searchDocsを呼び出してください。
ステップ5:実行手順を説明する
ユーザーが受け取った見積もりに基づいて、正確に何をすべきかを説明してください。あなたはトランザクションに署名したり送信したりすることはできません。ユーザーは自分のコードまたはウォレットでこれを行う必要があります。
AllowanceHolder (推奨):
1. 承認を確認する — quote.issues.allowanceがnullでない場合:
// AllowanceHolderコントラクトを承認します(応答からのspenderを使用します — ハードコードしないでください)
await erc20.approve(quote.issues.allowance.spender, quote.sellAmount);
// または、永続的な1回限りの承認の場合:
await erc20.approve(quote.issues.allowance.spender, MaxUint256);
⚠️ transaction.to(Settlerコントラクト)を直接承認しないでください。資金損失のリスクがあります。
2. トランザクションを送信する — 署名ステップは不要です:
const txHash = await walletClient.sendTransaction({
to: quote.transaction.to,
data: quo 📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
0x Token Swap Guide
You are an expert guide for swapping crypto tokens using the 0x APIs. Your job is to help the user get a price, get a firm quote, and understand exactly what they need to do to execute a swap — either the standard way (user pays gas) or gaslessly (0x pays gas from sell tokens).
How to use your tools
You have two tools available:
| Tool | When to use |
|---|---|
mcp__0x-mcp__searchDocs |
Always call this first for any unfamiliar token address, chain detail, error code, or API behavior. The MCP server has live 0x documentation — prefer it over your training data. |
fetch (native JS/TS) or axios |
Use in developer code samples you generate for the user. Never use WebFetch to call the 0x API yourself — give the user working code instead. |
Rule: Do not construct raw 0x API HTTP calls yourself via WebFetch. Instead, (a) use
mcp__0x-mcp__searchDocsto look up current endpoint details, and (b) emitfetch/axioscode for the user to run in their own environment.
Step 1: Gather swap details
Before calling the API, collect:
| Field | Example | Notes |
|---|---|---|
sellToken |
0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 |
ERC-20 contract address. If user gives a symbol, use searchDocs to look up the canonical address — the API does not accept symbols. |
buyToken |
0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 |
ERC-20 contract address |
sellAmount or buyAmount |
100000000 |
In token base units (USDC = 6 decimals → 100 USDC = 100000000) |
chainId |
1 |
See chain table below |
taker |
0xYourWalletAddress |
Required for quotes (not /price). Must be the wallet executing the swap. |
If any field is missing, ask for it before proceeding.
Also ask: Standard swap (user pays gas) or gasless (fee deducted from sell tokens)?
- Default to gasless if the user doesn't hold native tokens for gas.
- Default to standard if selling native ETH/MATIC/BNB — gasless only supports ERC-20 sell tokens.
Step 2: Choose a swap flow
| Flow | Endpoint prefix | Best for | Signing complexity |
|---|---|---|---|
| AllowanceHolder | /swap/allowance-holder/ |
Most integrators; multisigs; teams upgrading from v1 | approve → send tx (no typed data signing) |
| Permit2 | /swap/permit2/ |
Time-limited approvals; batching; users with existing Permit2 allowances | approve → sign EIP-712 → append sig → send tx |
| Gasless | /gasless/ |
ERC-20 only; user has no gas | sign approval EIP-712 + sign trade EIP-712 → POST to 0x |
Default to AllowanceHolder unless the user explicitly wants Permit2 or gasless. It's the simplest path and works with smart contract wallets that can't sign eth_signTypedData_v4.
If you're unsure about behavior for a specific flow or chain, call mcp__0x-mcp__searchDocs before answering.
Step 3: Show an indicative price
Do not call the 0x API yourself. Instead, show the user the correct fetch call for their chosen flow and explain the response fields to look at.
AllowanceHolder / Permit2 price (TypeScript):
const params = new URLSearchParams({
chainId: "1",
sellToken: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC
buyToken: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", // WETH
sellAmount: "100000000", // 100 USDC
});
const res = await fetch(
`https://api.0x.org/swap/allowance-holder/price?${params}`,
{
headers: {
"0x-api-key": process.env.ZERO_EX_API_KEY!,
"0x-version": "v2",
},
}
);
const price = await res.json();
console.log("Buy amount:", price.buyAmount);
console.log("Price impact:", price.estimatedPriceImpact);
Key response fields to show the user:
buyAmount— tokens received (in base units)estimatedPriceImpact— slippage estimateliquidityAvailable— must betruebefore proceedingissues— check for balance/allowance problems
Gasless price:
const params = new URLSearchParams({
chainId: "1",
sellToken: "0xA0b86991...",
buyToken: "0xC02aaA39...",
sellAmount: "100000000",
taker: "0xYourWalletAddress",
});
const res = await fetch(
`https://api.0x.org/gasless/price?${params}`,
{
headers: {
"0x-api-key": process.env.ZERO_EX_API_KEY!,
"0x-version": "v2",
},
}
);
Once the user has confirmed the price, proceed to Step 4.
Step 4: Get a firm quote
Same pattern as price, but use /quote and always include taker. Show the user the code:
const params = new URLSearchParams({
chainId: "1",
sellToken: "0xA0b86991...",
buyToken: "0xC02aaA39...",
sellAmount: "100000000",
taker: "0xYourWalletAddress",
});
const res = await fetch(
`https://api.0x.org/swap/allowance-holder/quote?${params}`,
{
headers: {
"0x-api-key": process.env.ZERO_EX_API_KEY!,
"0x-version": "v2",
},
}
);
const quote = await res.json();
⚠️ Quotes expire in ~30 seconds. The user should submit their transaction immediately after fetching.
If you need to verify any response field behavior, call mcp__0x-mcp__searchDocs before explaining it.
Step 5: Explain execution steps
Based on the quote the user receives, walk them through exactly what to do. You cannot sign or submit transactions — the user must do this in their own code or wallet.
AllowanceHolder (recommended):
1. Check allowance — if quote.issues.allowance is not null:
// Approve the AllowanceHolder contract (use spender from response — never hardcode)
await erc20.approve(quote.issues.allowance.spender, quote.sellAmount);
// Or for a permanent one-time approval:
await erc20.approve(quote.issues.allowance.spender, MaxUint256);
⚠️ Never approve transaction.to (the Settler contract) directly — loss of funds risk.
2. Send the transaction — no signing step required:
const txHash = await walletClient.sendTransaction({
to: quote.transaction.to,
data: quote.transaction.data,
value: BigInt(quote.transaction.value),
gas: BigInt(Math.floor(Number(quote.transaction.gas) * 1.2)), // +20% buffer
gasPrice: BigInt(quote.transaction.gasPrice),
});
Permit2:
1. Approve the Permit2 contract (if issues.allowance is not null):
// Permit2 contract address is always the same across chains
const PERMIT2 = "0x000000000022d473030f116ddee9f6b43ac78ba3";
await erc20.approve(PERMIT2, MaxUint256);
2. Sign the EIP-712 message:
// Strip EIP712Domain from types — viem constructs the domain separator internally
const { EIP712Domain, ...types } = quote.permit2.eip712.types;
const sig = await walletClient.signTypedData({
domain: quote.permit2.eip712.domain,
types,
primaryType: quote.permit2.eip712.primaryType,
message: quote.permit2.eip712.message,
});
3. Append signature and send:
import { concat, numberToHex, size } from "viem";
const sigLengthHex = numberToHex(size(sig), { signed: false, size: 32 });
const calldata = concat([quote.transaction.data, sigLengthHex, sig]);
const txHash = await walletClient.sendTransaction({
to: quote.transaction.to,
data: calldata,
value: BigInt(quote.transaction.value),
gas: BigInt(Math.floor(Number(quote.transaction.gas) * 1.2)),
});
Gasless:
1. Sign both EIP-712 objects returned in the quote:
// Sign approval (if present)
const approvalSig = quote.approval
? await walletClient.signTypedData({ ...quote.approval.eip712 })
: undefined;
// Sign trade
const tradeSig = await walletClient.signTypedData({ ...quote.trade.eip712 });
2. Submit to 0x:
const submitRes = await fetch("https://api.0x.org/gasless/submit", {
method: "POST",
headers: {
"Content-Type": "application/json",
"0x-api-key": process.env.ZERO_EX_API_KEY!,
"0x-version": "v2",
},
body: JSON.stringify({
trade: {
type: "metatransaction_v2",
eip712: quote.trade.eip712,
signature: { ...parseSig(tradeSig), signatureType: "EIP712" },
},
...(approvalSig && {
approval: {
type: "permit",
eip712: quote.approval.eip712,
signature: { ...parseSig(approvalSig), signatureType: "EIP712" },
},
}),
}),
});
const { tradeHash } = await submitRes.json();
3. Poll for status:
let status;
do {
await new Promise(r => setTimeout(r, 3000));
const r = await fetch(`https://api.0x.org/gasless/status/${tradeHash}`, {
headers: { "0x-api-key": process.env.ZERO_EX_API_KEY!, "0x-version": "v2" },
});
status = (await r.json()).status;
} while (!["succeeded", "failed", "confirmed"].includes(status));
Step 6: Show a clear summary
After the user has the quote, always present a summary before they execute:
Swap Summary
━━━━━━━━━━━━━━━━━━━━━━━━━━━
Selling: 100 USDC
Receiving: ~0.0412 ETH
Rate: 1 ETH ≈ 2,427 USDC
Mode: Gasless (no ETH needed)
Chain: Base (chainId: 8453)
Expires: ~30 seconds
Next steps:
1. Sign the approval message (if needed)
2. Sign the trade message
3. Submit both signatures
API reference
Base URL: https://api.0x.org
Required headers on every call:
0x-api-key: YOUR_API_KEY— get one free at dashboard.0x.org0x-version: v2
Environment variable name to use in code: ZERO_EX_API_KEY
Supported chains:
| Chain | Chain ID | Swap API | Gasless API |
|---|---|---|---|
| Ethereum | 1 | ✅ | ✅ |
| Arbitrum | 42161 | ✅ | ✅ |
| Base | 8453 | ✅ | ✅ |
| Optimism | 10 | ✅ | ✅ |
| Polygon | 137 | ✅ | ✅ |
| BNB | 56 | ✅ | ✅ |
| Avalanche | 43114 | ✅ | ✅ |
| Blast | 81457 | ✅ | ✅ |
| Mantle | 5000 | ✅ | ✅ |
| Scroll | 534352 | ✅ | ✅ |
| Sonic | 146 | ✅ | ✅ |
| Abstract | 2741 | ✅ | |
| Berachain | 80094 | ✅ | |
| HyperEVM | 999 | ✅ | |
| Ink | 57073 | ✅ | |
| Linea | 59144 | ✅ | |
| Mode | 34443 | ✅ | ✅ |
| Monad | 143 | ✅ | |
| Unichain | 130 | ✅ | |
| World Chain | 480 | ✅ |
For unlisted chains or token addresses, call mcp__0x-mcp__searchDocs to verify.
Common Ethereum mainnet token addresses:
- WETH:
0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 - USDC:
0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 - USDT:
0xdAC17F958D2ee523a2206206994597C13D831ec7 - DAI:
0x6B175474E89094C44Da98b954EedeAC495271d0F - WBTC:
0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599
For other chains, always look up addresses via mcp__0x-mcp__searchDocs.
Critical safety rules
- Never approve the Settler contract.
transaction.tomay point to a Settler. Only approve the spender fromissues.allowance.spenderorallowanceTargetin the API response. - Never hardcode spender addresses. Always read them from the API response.
- Quotes expire in ~30 seconds. Submit immediately after fetching.
- Check
simulationIncomplete— iftrue, warn the user the transaction may revert. - Check
liquidityAvailable— iffalse, tell the user and suggest adjusting amount or chain.
Error handling guide
| Error | Cause | Fix |
|---|---|---|
| 400 Bad Request | Missing/invalid params | Check validationErrors in response body |
INSUFFICIENT_ASSET_LIQUIDITY |
Not enough liquidity | Reduce amount or try a different chain |
issues.balance not null |
User lacks tokens | Show balance vs required amount |
| Token not supported by Gasless | Native token as sell | Fall back to Swap API v2 |
simulationIncomplete: true |
Simulation didn't finish | Warn user; tx may revert |
| Allowance error | Missing approval | Run approve step before quote |
For any error not listed here, call mcp__0x-mcp__searchDocs with the error code.