This page puts a price on one route of an API and gets it paid through Alba. It uses Hono. Accept Alba on an API has the same for Express and for any other server.
You need a Solana wallet address to be paid at. That wallet must already have a token account for USDC.
Install
bash npm install @alba/sdk honoGet your values
Open Sell in the app, choose Public address, enter your wallet address and a price. The page writes the middleware call with its values filled in: the price in raw units, the USDC mint, your address, the network and the facilitator's URL.
Add the middleware
Put the call in front of the route's handler. A price of
10000is 0.01 USDC.ts import { Hono } from 'hono' import { honoMiddleware } from '@alba/sdk/seller' const app = new Hono() const paid = honoMiddleware({ price: '10000', asset: mint, payTo, network, facilitatorUrl, }) app.get('/v1/search', paid, (c) => c.json({ results: [] }))See the 402
Start the server and ask for the route with no payment:
bash curl -i http://localhost:3000/v1/searchThe answer is
402with aPAYMENT-REQUIREDheader. The same object is in the JSON body:x402Version,resourceandaccepts, whose one entry names the schemealba, your price and your address.Get paid
Any agent holding a grant can now buy the route with
alba.fetch. To try it yourself, follow Quickstart: fund an agent and point the agent at your URL. The handler runs only after the payment has settled.Check the settlement
On Sell, Settlements to this address lists each payment with its time in UTC, its amount and its transaction. The amount is your full price: Alba's fees are charged to the payer on top of it.