본문으로 건너뛰기
샘플 앱으로 돌아가기

x402 Explorer

A sample app 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 with EVM payment signatures.

프론트엔드 프레임워크/라이브러리:
React
언어:
TypeScript
빌드 도구/개발 서버:
Next.js
샘플 앱 미리 보기

개요

This sample app demonstrates Quicknode's x402 protocol for pay-per-request blockchain API access. The x402 protocol enables seamless micropayments for API calls — each request is paid for with an EVM signature, removing the need for traditional API keys or subscription plans.

Connect your wallet, authenticate with Sign-In with Ethereum (SIWE), and request testnet USDC from the faucet. When you execute blockchain methods, if you don't have enough credits, the app will automatically purchase test credits using your testnet USDC. Execute RPC/REST methods across multiple networks including Ethereum, Base Sepolia, Arbitrum, Polygon, and Aptos.

건축

Wallet ──► 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.

주요 기능


  • Wallet Connection via ConnectKit (MetaMask, Coinbase Smart Wallet, etc.)
  • SIWE Authentication to receive a session JWT
  • Testnet USDC Faucet on Base Sepolia — credits are automatically purchased with testnet USDC when needed
  • Multi-Chain RPC/REST Execution across Ethereum, Base Sepolia, Arbitrum, Polygon, and Aptos
  • Payment Metadata Inspection returned with each response
  • JSON-RPC, REST, gRPC-Web, and WebSocket method support

Supported Methods

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:

방법의정서네트워크
eth_blockNumberJSON-RPCBase Sepolia, Arbitrum, Polygon
eth_gasPriceJSON-RPC베이스 세폴리아
eth_chainIdJSON-RPC이더리움
Ledger InfoREST앱토스
Block by HeightREST앱토스

필수 조건


  • Node.js v18+
  • pnpm v8+
  • A browser wallet (e.g., MetaMask) with Base Sepolia testnet configured

프로젝트 구조

src/
├── app/ # Next.js App Router (pages & layouts)
├── components/
│ ├── providers.tsx # Wagmi + React Query + ConnectKit providers
│ └── wallet-connection-shell.tsx
├── 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)

환경 변수

변수Default설명
NEXT_PUBLIC_X402_BASE_URLhttps://x402.quicknode.com/x402 API base URL

만들기 .env.local file to override, but the default points to the public x402 endpoint which you can use for testing without any setup.

NEXT_PUBLIC_X402_BASE_URL=https://x402.quicknode.com/

시작하기

1. Clone the repository

git clone https://github.com/quiknode-labs/qn-guide-examples.git
cd qn-guide-examples/sample-dapps/x402-quicknode

2. 종속성 설치

pnpm 설치

3. Start the development server

pnpm dev

Open http://localhost:3000 in your browser. Connect your wallet, authenticate with SIWE, request testnet USDC from the faucet, and start making pay-per-request API calls — credits are automatically purchased with your testnet USDC when needed.


미리 보기

미리 보기

기여 및 피드백
여러분의 의견을 듣고 싶으며, 이 샘플 앱에 대한 모든 기여를 환영합니다!
문제를 신고하거나 피드백을 공유하려면, 다음에서 GitHub 이슈를 생성해 주세요. qn-가이드-예시 저장소.
기여하시려면 다음 단계를 따르세요:
  1. 저장소를 포크하기
  2. 기능 브랜치 생성:
    git checkout -b feature/amazing-feature
  3. 변경 사항을 커밋하세요:
    git commit -m "멋진 기능 추가"
  4. 브랜치를 푸시하세요:
    git push origin feature/amazing-feature
  5. 풀 리퀘스트를 제출하세요.