Start

Quickstart: accept Alba

Put a price on one route and see it paid.

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.

  1. Install

    bash
    npm install @alba/sdk hono
  2. Get 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.

  3. Add the middleware

    Put the call in front of the route's handler. A price of 10000 is 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: [] }))
  4. See the 402

    Start the server and ask for the route with no payment:

    bash
    curl -i http://localhost:3000/v1/search

    The answer is 402 with a PAYMENT-REQUIRED header. The same object is in the JSON body: x402Version, resource and accepts, whose one entry names the scheme alba, your price and your address.

  5. 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.

  6. 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.