x402 payments
Send a programmatic x402 payment. Nirium plans and assembles the transaction; the Pollar SDK signs and submits the unsigned XDR with your connected wallet — no secret key, no API key.
Recipient Stellar address (G…) on testnet.
'XLM' for native, or 'CODE:ISSUER' for an issued asset.
Optional x402 resource / invoice id — stored as the tx memo (max 28 chars).
Setup — register the Nirium adapter once
// adapter.ts — register once in your app
import { Agent } from 'nirium';
const agent = new Agent({ network: 'testnet' });
export const niriumAdapter: NiriumAdapter = {
// Nirium plans the x402 payment → unsigned XDR.
pay: (p) => agent.x402.buildPayment(p),
};
// each adapter fn returns { unsignedTransaction: string }.
// Pollar then signs + submits with the user's wallet automatically.
export const useNiriumX402 =
createPollarAdapterHook<NiriumAdapter>('niriumX402');import { PollarClient } from '@pollar/core'; import { niriumAdapter } from './adapter'; const client = new PollarClient({ apiKey, baseUrl }); await client.ready(); // Nirium assembles the payment → returns an unsigned XDR const { unsignedTransaction } = await niriumAdapter.pay({ to: 'G… (recipient)', amount: '1', asset: 'XLM', signer: 'G…', }); // Pollar signs + submits with the connected wallet await client.signAndSubmitTx(unsignedTransaction);
const { pay } = useNiriumX402(); // Nirium plans the x402 payment → unsigned XDR. // Pollar signs + submits with the connected wallet automatically. await pay({ to: 'G… (recipient)', amount: '1', asset: 'XLM', signer: 'G…', });
Fill in destination, amount and asset, then pay.
@pollar/core — functions used
The adapter returns an unsigned XDR; the core client signs and submits it.
niriumAdapter.pay(params)asyncparams: params: { to, amount, asset, reference?, signer }. Nirium plans the payment.
returns: Promise<{ unsignedTransaction: string }> — the unsigned XDR, ready to sign.
client.signAndSubmitTx(xdr)asyncparams: xdr: string — the unsigned transaction returned by the adapter.
returns: Promise<SubmitOutcome> — { status, hash, … }. Signs with the connected wallet, then submits.
@pollar/react — hook & values used
createPollarAdapterHook wires the adapter so Pollar auto-signs; usePollar exposes the live tx state.
useNiriumX402()hookparams: No arguments. Returns the wrapped adapter — calling pay() builds, signs and submits in one step.
returns: WrappedAdapter — { pay }. The unsigned XDR is signed + submitted automatically.
usePollar().txreactive valueparams: No arguments — read it during render.
returns: TransactionState — the live build → sign → submit progress (tx.step, tx.hash).