Skip to main content

x402 Authentication

In addition to API keys, the Zapper API supports authentication via the x402 protocol. This allows you to pay for API usage on a per-request basis using USDC on Base, with 0 fees and instant settlement.

Learn more about x402

Example Client

Below is an example client implementation that demonstrates how to use x402 authentication with the Zapper API:

import axios from 'axios';
import { x402Client, wrapAxiosWithPayment } from '@x402/axios';
import { registerExactEvmScheme } from '@x402/evm/exact/client';
import { privateKeyToAccount } from 'viem/accounts';

async function main() {
const privateKey = 'YOUR_PRIVATE_KEY';

const client = new x402Client();

const signer = privateKeyToAccount(privateKey);
registerExactEvmScheme(client, { signer });

const api = wrapAxiosWithPayment(
axios.create({
baseURL: 'https://public.zapper.xyz',
headers: { 'Content-Type': 'application/json' },
}),
client
);

const response = await api.post('/x402/token-price', {
variables: {
address: '0xbe19c96f5deec29a91ca84e0d038d4bb01d098cd',
chainId: 8453,
},
});

console.log('response:', response.data.data);
}

main().catch(console.error);

How it Works

  1. Initial Request: Make a GraphQL request without payment headers
  2. Payment Required Response: The API returns an 402 Payment Required error with payment requirements
  3. Payment Header Creation: Create a payment header using your signer and the selected requirements
  4. Retry with Payment: Retry the request with the payment header included

Query Pricing

The x402 protocol has no fees. API queries are priced the same as the Pay-As-You-Go plan (USD $0.001 / API credit, ~$0.003 / query). Visit our pricing page for exact query costs.

Supported Payment Chain

The Zapper API x402 authentication system supports USDC payments on Base.

Prerequisites

To use x402 authentication, you'll need:

  • A private key for signing transactions
  • Access to the x402 client libraries (x402/client and x402/types)
  • Sufficient USDC balance on Base

Available Endpoints

All endpoints are available at https://public.zapper.xyz/x402/*

Onchain DataEndpoint
Aggregated portfolio value across tokens, DeFi, and NFTs/x402/portfolio-totals
Detailed list of token holdings with USD values/x402/token-balances
Active positions in lending, staking, liquidity pools, etc./x402/app-balances
Individual NFT holdings with floor prices and values/x402/nft-balances
Real-time token price and market cap/x402/token-price
Token price at any point in time/x402/historical-token-price
Trending tokens based on swap activity/x402/token-ranking
Trending NFT collections by trading volume/x402/nft-ranking
Full metadata for a specific NFT (traits, media, holder)/x402/nft-token-metadata
Collection stats, floor price, holders, events/x402/nft-collection-metadata
Find tokens, NFTs, users, and apps by name/x402/search
Resolve ENS, Farcaster, Lens profiles for addresses/x402/account-identity
Human-readable transaction interpretation/x402/transaction-details
Chronological transaction timeline for addresses/x402/transaction-history
List of accounts holding a specific token/x402/token-holders
Real-time feed of swap activity, including token trades, volume, and social context/x402/general-swap-feed
Activity feed for a specific token, including swaps and top Farcaster casts/x402/token-activity-feed