How it works
Think of an arcade: put a coin in, play. With x402 Pay-As-You-Go (PAYG) your Solana wallet is the coin.- Put a little SOL into StackNet’s vault.
- Get back an API key that’s already loaded with credit.
- Every API call spends a bit of it. Top up when it runs low.
The name comes from HTTP status
402 Payment Required. x402 is the standard that makes “pay for this request” actually work.Get a key
createKeyFromSol again with the same wallet to top up the existing key.
Use the key
It works exactly like a normal API key, just with apg_ prefix:
Building an app on Geoff?
By default any wallet can create a key. If you want your users’ wallets to spend only inside your app, under limits you set, use app invites. Your backend holds a secret app invite key. It hands each wallet a short-lived allow invite, which the wallet redeems (by signing a message) to become enrolled in your app. From then on, that wallet’s keys and balances are scoped to your app: spend-capped, tool-restricted, and isolated from any other app the same wallet uses.- Treat
wallet + stackId + inviteIdas the identity for key lookup and top-ups. - Top up the wallet’s existing key (
topUpKeyFromSol) instead of minting new ones. - The app invite key, allow invites, and
pg_keys are all secrets. Don’t log or persist them.
@stacknet/x402payg 0.3.5 or newer.