BS
BaseScreener

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

bash
npm install @coinbase/agentkit viem

Setup

typescript
import { 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

typescript
async 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

typescript
async 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

typescript
async 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

  1. agentKit.fetch() sends your query
  2. API returns 402 with USDC cost in PAYMENT-REQUIRED header
  3. AgentKit auto-signs a Permit2 authorization (no gas needed)
  4. AgentKit retries the request with PAYMENT-SIGNATURE header
  5. You receive your data

All of this happens transparently — your code just sees the final successful response.