A sample application demonstrating Quicknode's x402 protocol for pay-per-request blockchain API access. Connect your wallet, authenticate with SIWE, and call RPC/REST methods across multiple chains — each request is paid for with an EVM signature.
- Connect a wallet via ConnectKit (MetaMask, Coinbase Smart Wallet, etc.)
- Authenticate using Sign-In with Ethereum (SIWE) to receive a session JWT
- Request testnet USDC from the faucet (Base Sepolia)
- Execute blockchain methods across networks (Ethereum, Base Sepolia, Arbitrum, Polygon, Aptos) — if you don't have enough credits, the app automatically purchases them with your testnet USDC
- Inspect payment metadata returned with each response
# 1. Clone the repository
git clone https://github.com/quiknode-labs/qn-guide-examples.git
cd qn-guide-examples/sample-dapps/x402-quicknode
# 2. Install dependencies
pnpm install
# 3. Start the development server
pnpm devOpen http://localhost:3000 in your browser.
| Variable | Default | Description |
|---|---|---|
NEXT_PUBLIC_X402_BASE_URL |
https://x402.quicknode.com |
x402 API base URL |
Create a .env.local file to override:
NEXT_PUBLIC_X402_BASE_URL=https://x402.quicknode.comWallet ──► SIWE Auth ──► JWT Token
│
▼
x402 Fetch Wrapper (JWT + EVM payment signature)
│
▼
Quicknode x402 API ──► Blockchain RPC / REST
Each API request is wrapped by @x402/fetch, which automatically signs a payment authorization using your connected wallet. The x402 backend verifies the signature, deducts credits, and proxies the request to the target blockchain network.
As all JSON-RPC, REST, gRPC-Web, and WebSocket methods are supported, you can call any method available on the target network. For demonstration, the app includes buttons for popular methods:
| Method | Protocol | Network |
|---|---|---|
eth_blockNumber |
JSON-RPC | Base Sepolia, Arbitrum, Polygon |
eth_gasPrice |
JSON-RPC | Base Sepolia |
eth_chainId |
JSON-RPC | Ethereum |
| Ledger Info | REST | Aptos |
| Block by Height | REST | Aptos |
src/
├── app/ # Next.js App Router (pages & layouts)
├── components/
│ ├── providers.tsx # Wagmi + React Query + ConnectKit providers
│ └── ... # UI components (header, panels, cards, etc.)
├── hooks/
│ ├── use-x402-auth.ts # SIWE authentication state
│ ├── use-credits.ts # Credit balance fetching
│ └── use-x402-fetch.ts # Authenticated fetch wrapper
└── lib/
├── constants.ts # x402 URLs, chain IDs, contract addresses
├── methods.ts # Available RPC/REST method definitions
├── types.ts # TypeScript types
└── x402.ts # Core x402 logic (auth, credits, execution)
| Command | Description |
|---|---|
pnpm dev |
Start development server |
pnpm build |
Create production build |
pnpm start |
Start production server |
pnpm lint |
Run ESLint |
pnpm typecheck |
Run TypeScript type checking |
- Framework: Next.js 16 (App Router)
- Styling: Tailwind CSS 4
- Wallet: wagmi + ConnectKit
- Auth: SIWE (Sign-In with Ethereum)
- Payments: @x402/fetch + @x402/evm
- State: TanStack React Query
MIT
