Quick Start
Get up and running with T402 in under 5 minutes.
Overview
T402 enables HTTP-native payments using USDT and USDT0. Here’s what a typical flow looks like:
- Client makes a request to a protected resource
- Server responds with
402 Payment Requiredand payment options - Client signs a payment authorization
- Server verifies and settles the payment
- Client receives the requested resource
Server Setup (Express.js)
import express from 'express'
import { paymentMiddleware } from '@t402/express'
import { ExactEvmScheme } from '@t402/evm'
const app = express()
// Add payment middleware
app.use(paymentMiddleware({
'GET /api/premium': {
price: '$0.01',
network: 'eip155:8453', // Base
payTo: '0xYourAddress...',
description: 'Premium API access'
}
}))
app.get('/api/premium', (req, res) => {
res.json({ data: 'Premium content!' })
})
app.listen(3000)Client Setup
import { t402Client, wrapFetchWithPayment } from '@t402/fetch'
import { registerExactEvmScheme } from '@t402/evm/exact/client'
import { privateKeyToAccount } from 'viem/accounts'
// Create and configure client
const client = new t402Client()
registerExactEvmScheme(client, {
signer: privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`)
})
// Wrap fetch to automatically handle payments
const fetchWithPayment = wrapFetchWithPayment(fetch, client)
// Make requests - payments are handled automatically!
const response = await fetchWithPayment('https://api.example.com/api/premium')
const data = await response.json()What’s Next?
- Installation - Detailed installation guide
- Core Concepts - Understand how T402 works
- Server Integration - Complete server setup
- Client Integration - Complete client setup