AgentKit Integration
Build a Base token screening agent with Coinbase AgentKit
AgentKit Integration
Coinbase AgentKit provides the simplest integration path. It handles the entire x402 payment flow — 402 challenge, Permit2 signing, and retry — automatically.
Install
bashnpm install @coinbase/agentkit viem
Setup
typescriptimport { AgentKit } from '@coinbase/agentkit' import { privateKeyToAccount } from 'viem/accounts' const account = privateKeyToAccount(process.env.AGENT_KEY as `0x${string}`) const agentKit = await AgentKit.from({ account })
Query helper
typescriptasync function queryScreener(query: string) { const res = await agentKit.fetch('https://apitoken.agentchaintools.xyz/graphql', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ query }), }) const data = await res.json() return data.data }
Example: Find low-risk opportunities
typescriptasync function findOpportunities() { const data = await queryScreener(`{ newTokens(maxAgeSeconds: 7200, minLiquidityUsd: 50000, limit: 10) { tokens { address symbol price { usd change1h } risk { score isHoneypot isMintable liquidityLocked } liquidity { usd } } } }`) return data.newTokens.tokens .filter((t: any) => t.risk.score < 30 && !t.risk.isHoneypot) .sort((a: any, b: any) => b.price.change1h - a.price.change1h) }
Example: Monitor trending tokens
typescriptasync function getTrending() { const data = await queryScreener(`{ trending(period: H1, limit: 20) { tokens { address symbol price { usd change1h } largestPool { liquidityUsd } volume { usd24h } } } }`) return data.trending.tokens }
How the payment flow works
agentKit.fetch()sends your query- API returns
402with USDC cost inPAYMENT-REQUIREDheader - AgentKit auto-signs a Permit2 authorization (no gas needed)
- AgentKit retries the request with
PAYMENT-SIGNATUREheader - You receive your data
All of this happens transparently — your code just sees the final successful response.