Hono Integration
Add x402 payments to your Hono API with minimal code
Installation
npm install @getconduit/x402-hono honoBasic Setup
import { Hono } from 'hono'
import { x402 } from '@getconduit/x402-hono'
const app = new Hono()
// Configure x402 middleware
app.use('*', x402({
facilitatorUrl: 'https://getconduit.io/api/facilitator',
network: 'solana',
}))
// Protected endpoint
app.get('/api/premium', (c) => {
return c.json({
message: 'Premium content unlocked!',
payer: c.get('payment').payer
})
})
export default appCloudflare Workers
Hono works great with Cloudflare Workers for edge x402 payments:
import { Hono } from 'hono'
import { x402 } from '@getconduit/x402-hono'
const app = new Hono()
app.use('*', x402({
facilitatorUrl: 'https://getconduit.io/api/facilitator',
network: 'solana',
price: 0.01
}))
app.get('/api/data', async (c) => {
// Fetch data from KV, D1, or external API
const data = await c.env.KV.get('premium-data')
return c.json({ data })
})
export default appRoute-Specific Pricing
import { Hono } from 'hono'
import { x402 } from '@getconduit/x402-hono'
const app = new Hono()
// Free routes
app.get('/api/public', (c) => c.json({ free: true }))
// Paid routes with different prices
const premium = new Hono()
premium.use('*', x402({
facilitatorUrl: 'https://getconduit.io/api/facilitator',
network: 'solana',
price: 0.05
}))
premium.get('/data', (c) => c.json({ premium: 'data' }))
const vip = new Hono()
vip.use('*', x402({
facilitatorUrl: 'https://getconduit.io/api/facilitator',
network: 'solana',
price: 0.10
}))
vip.get('/exclusive', (c) => c.json({ vip: 'content' }))
app.route('/premium', premium)
app.route('/vip', vip)
export default app