Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.
hood-pay
Stripe-Checkout-grade USDG payments on Robinhood Chain (chain ID 4663). Three pieces, each usable on its own:
- Core (
hood-pay): networks, the payment-request type + URL-fragment link codec, the reference/dust attribution scheme, and unsigned-tx builders for direct ERC-20 transfers andHoodPayRouter-mode payments. - Widget (
hood-pay/widget, or the prebuiltdist/hood-pay.min.js): an embeddable checkout that mounts on[data-hoodpay]elements or viamountCheckout(), no bundler required. It drives wallet discovery and chain-add/switch throughhood-connect, so it never re-implements EIP-6963 or EIP-3085 itself. - Verify (
hood-pay/verify, Node-only): a reorg-safe on-chain payment watcher, an idempotent SQLite ledger, signed webhooks, and refund helpers for the merchant side.
Website — nirholas.github.io/hood-pay
The project site is an interactive thermal receipt printer: the whole page is one long receipt tape. Type an amount and ring up a sale, and a real payment link (the exact base64url URL-fragment codec this package uses), the direct-mode dust fingerprint, and a real 32-byte router reference print onto the tape line by line, then the reorg-safe watcher settles it to PAID. Everything runs client-side, nothing is sent anywhere. It is a single self-contained page in docs/, so it deploys anywhere static.
Deploy your own copy in one click:
| Target | How |
|---|---|
| GitHub Pages | Settings → Pages → Source: main / /docs. Serves at nirholas.github.io/hood-pay/. No build step. |
| Cloudflare Pages | The button above, or wrangler pages deploy docs. Config in wrangler.toml. |
| Netlify / Vercel | The buttons above. Publish directory is docs/ (netlify.toml, vercel.json). |
USDG (Robinhood Chain's dollar stablecoin) is a plain ERC-20 whose transfer carries no memo or
invoice-reference field. A bare transfer cannot say which invoice it settles. hood-pay solves that two ways: router
mode, where the buyer pays through the stateless, non-custodial HoodPayRouter contract
(contracts/src/HoodPayRouter.sol) which emits PaymentReceived(reference, payer, payTo, token, amount) for exact attribution regardless of amount; and direct mode, where the invoice
amount itself is fingerprinted in USDG's unused low decimal digits (zero contracts, works with
any ERC-20). See src/reference.ts for the full collision-probability math behind both.
Install
npm install hood-pay
viem >= 2.55.0 is a peer dependency. hood-connect (wallet discovery +
chain add/switch) and hoodchain (the Robinhood
Chain address book and chain definitions) are regular dependencies and install automatically.
Quickstart
1. Embeddable widget (hood-pay/widget)
Script tag, no build step:
<div data-hoodpay
data-pay-to="0x4022de2D36C334E73C7a108805Cea11C0564f402"
data-amount="25.00"
data-memo="Invoice 7"></div>
<script src="https://unpkg.com/hood-pay/widget.js"></script>
Any element with data-hoodpay auto-mounts on load. Add data-network="testnet" for chain
46630, or data-reference + data-router to pay through HoodPayRouter instead of a plain
transfer. From a bundler, mount the same checkout programmatically and observe every state:
import { mountCheckout } from 'hood-pay/widget'
const checkout = mountCheckout('#checkout', {
payTo: '0x4022de2D36C334E73C7a108805Cea11C0564f402',
amount: '25.00',
memo: 'Invoice 7',
onStateChange: (state) => console.log(state.step), // review, discovering, paying, success, ...
onSuccess: (receipt) => console.log(receipt.txHash, receipt.explorerUrl),
onError: (error) => console.error(error.message),
})
// Later: checkout.destroy()
The widget never holds keys or custodies funds: it only builds the unsigned approve/transfer/
pay calls for the buyer's own EIP-6963 wallet to sign, via hood-connect's wallet discovery.
2. Payment links (core, hood-pay)
A payment link encodes a PaymentRequest as a base64url JSON payload in the URL fragment
(never sent to a server, so a hosted link page leaks nothing to its host):
import { paymentLinkUrl } from 'hood-pay'
const url = paymentLinkUrl({
v: 1,
network: 'mainnet',
payTo: '0x4022de2D36C334E73C7a108805Cea11C0564f402',
amount: '25.00',
memo: 'invoice 7',
})
// https://nirholas.github.io/hood-pay/pay.html#1.eyJ2IjoxLCJuZXR3b3JrIjoibWFpbm5ldC...
or from the CLI:
npx hood-pay link --to 0x4022de2D36C334E73C7a108805Cea11C0564f402 --amount 25 --memo "invoice 7"
The default base URL (https://nirholas.github.io/hood-pay/pay.html) is a real page in this repo
(docs/pay.html, published to GitHub Pages from docs/): it decodes the fragment client-side,
mounts the checkout, and never sends the payment request to any server. docs/index.html is the
landing page and docs/hood-pay.min.js is the compiled widget both pages load (regenerated by
npm run build). To self-host instead, point paymentLinkUrl's second argument at your own static
page - it only needs to decode the fragment and mount the widget, no server involved:
<!doctype html>
<div id="checkout"></div>
<script type="module">
import { decodePaymentRequest, mountCheckout } from 'https://esm.sh/hood-pay/widget'
const request = decodePaymentRequest(location.hash)
mountCheckout('#checkout', request)
</script>
3. Merchant-side verification (hood-pay/verify, Node-only)
Watch the chain for a payment, keep an idempotent ledger, and deliver a signed webhook when it settles:
import { createLedger, createReader, awaitPayment, createWebhookEmitter, toWebhookEvent } from 'hood-pay/verify'
import { networkInfo } from 'hood-pay'
const ledger = await createLedger('./data/hood-pay.sqlite') // Node >= 22.5 (node:sqlite)
const payTo = '0x4022de2D36C334E73C7a108805Cea11C0564f402'
const usdg = networkInfo('mainnet').usdg
const invoice = ledger.createDirectInvoice({
network: 'mainnet',
payTo,
token: usdg.address,
baseRaw: 25_000000n, // 25.00 USDG; low 4 digits reserved for the fingerprint
})
const reader = createReader('mainnet')
const result = await awaitPayment(
{ token: invoice.token, payTo: invoice.payTo, expectedRaw: invoice.expectedRaw },
{ reader, fromBlock: await reader.getBlockNumber(), onState: (r) => ledger.setStatus(invoice.id, r.status) },
)
ledger.recordTransfer(invoice.id, result.transfers[0]!)
const emitter = createWebhookEmitter({
url: 'https://merchant.example/webhooks/hood-pay',
secret: process.env.HOOD_PAY_WEBHOOK_SECRET!,
})
await emitter.emit(toWebhookEvent(`payment.${result.status}`, invoice.id, result))
Receive and verify that webhook on the merchant's server (any framework - this reads the raw
body and the hood-pay-signature header):
import { verifyWebhookSignature, type WebhookEvent } from 'hood-pay/verify'
app.post('/webhooks/hood-pay', express.text({ type: '*/*' }), (req, res) => {
const signature = req.header('hood-pay-signature')
if (!signature || !verifyWebhookSignature(process.env.HOOD_PAY_WEBHOOK_SECRET!, req.body, signature)) {
return res.status(400).send('bad signature')
}
const event = JSON.parse(req.body) as WebhookEvent
if (event.type === 'payment.paid' || event.type === 'payment.overpaid') markOrderPaid(event.invoiceId)
res.sendStatus(200)
})
verifyWebhookSignature is constant-time and rejects a stale timestamp (5 minute default
tolerance) - but still treat the payload as a hint: the ledger/watcher above remain the source of
truth for amounts.
Or watch and verify a payment straight from the CLI, no code:
npx hood-pay verify --to 0x4022de2D36C334E73C7a108805Cea11C0564f402 --amount 25.0042
Run hood-pay <command> --help for every flag.
Reorg safety
awaitPayment/checkPayment only ever scan blocks at depth >= confirmations below the chain
head (default 30, about 3s of Robinhood Chain's ~100ms blocks), and every candidate log's block
hash is re-fetched by number and compared before it counts - a block reorged out after the scan
but before the re-check is dropped. A confirmed PaymentResult is stable under any reorg
shallower than confirmations blocks.
Addresses are checksum-validated
Every address accepted anywhere in this package (payTo, token.address, router) is validated
against its EIP-55 checksum via viem's getAddress. A lowercase or fully-uppercase address is
accepted as-is (it makes no checksum claim); a mixed-case address with even one wrong character
throws, so a corrupted or mistyped merchant address is caught before a payment link is ever
generated.
API
Core (hood-pay)
| Export | Purpose |
|---|---|
networkInfo(network?) |
Resolve chain id, RPC/explorer URLs, and the USDG PayToken for 'mainnet' (4663, default) or 'testnet' (46630) |
explorerTxUrl / explorerAddressUrl |
Blockscout links for a network |
newReference() / isReference(v) |
32-byte router-mode reference generation + validation |
randomDust() / applyDust(base, dust) / splitDust(raw) |
Direct-mode amount-fingerprint helpers |
directCollisionProbability(k) / referenceCollisionProbability(k) |
Birthday-bound collision math for k concurrent invoices |
validatePaymentRequest(input) |
Parse + validate untrusted data into a PaymentRequest, checksumming every address |
requestToken / requestRawAmount / formatRequestAmount |
Read a request's settlement token and amount |
encodePaymentRequest / decodePaymentRequest / paymentLinkUrl |
The URL-fragment link codec |
buildTransferTx / buildApproveTx / buildRouterPayTx |
Unsigned { to, data, value } calls for any signer |
erc20Abi / hoodPayRouterAbi |
ABI literals used throughout the package |
Verify (hood-pay/verify, Node-only)
| Export | Purpose |
|---|---|
createReader(network, rpcUrl?) |
Build a ChainReader (viem public client) for the watcher |
awaitPayment(spec, options) |
Poll until an invoice is paid/overpaid, or expired after timeoutMs |
checkPayment(spec, options) |
One-shot historical scan (reconciliation/audits) |
createLedger(path) |
Idempotent SQLite ledger: reserved dust fingerprints, monotonic status transitions, replay-safe transfer recording |
createWebhookEmitter(options) |
Signed webhook delivery with retry on network errors and 5xx/429 |
signWebhook / verifyWebhookSignature |
HMAC-SHA256 signature scheme, constant-time verify |
toWebhookEvent(type, invoiceId, result) |
Serialize a PaymentResult (bigints as decimal strings) into the webhook wire shape |
buildRefundTx / refundOverageTx / refundReceivedTx |
Unsigned refund transfers for any signer |
sendRefund(wallet, call) |
Sign + broadcast a refund with a merchant-supplied viem WalletClient |
Widget (hood-pay/widget)
| Export | Purpose |
|---|---|
mountCheckout(el, config) |
Mount the checkout; returns { request, destroy() } |
validateCheckoutConfig(config) |
Validate a raw config into { request, onSuccess?, onError?, onStateChange? } |
ensureStyles(doc?) / WIDGET_CSS |
The scoped .hoodpay stylesheet, injected once per document |
decodePaymentRequest / encodePaymentRequest / paymentLinkUrl |
Re-exported from core, for building a link page without a second import |
The IIFE build (dist/hood-pay.min.js, loaded via hood-pay/widget.js) additionally exposes
window.HoodPay = { version, mount, validateConfig, decodePaymentRequest, encodePaymentRequest, paymentLinkUrl }
and auto-mounts every [data-hoodpay] element on DOMContentLoaded.
Solidity
contracts/src/HoodPayRouter.sol is the stateless, non-custodial router: pay(token, payTo, amount, ref) pulls amount of token from the caller straight to payTo via transferFrom
(requires a prior approve) and emits PaymentReceived. It never holds a
balance, has no owner, no pause, and no upgrade path; it tolerates non-reverting tokens that
signal failure by returning false and legacy tokens that return no data at all.
npm run forge:build
npm run forge:test # 10 unit/fuzz tests against a local EVM
npm run forge:test:fork # + 2 read-only tests against live mainnet USDG (needs an RPC)
Differences from hood-connect
hood-connect is generic dApp infrastructure: add-chain, connect, and the
funding funnel, with no notion of an invoice or a checkout. hood-pay is the payments layer built
on top of it - the widget calls straight into hood-connect's discoverWallets/ensureChain
rather than re-implementing wallet discovery, and adds everything a checkout needs that
hood-connect deliberately does not: the reference/dust attribution scheme, payment-request
validation and link encoding, a reorg-safe watcher, an idempotent ledger, signed webhooks, and
refund helpers. Use hood-connect alone for "connect and fund a wallet"; add hood-pay when you
need to accept and reconcile a specific payment.
Development
npm install
npm test # unit tests (vitest)
npm run test:live # live-network tests against Robinhood Chain mainnet
npm run typecheck
npm run build # tsup (., ./verify, ./widget) + the minified IIFE bundle, copied to docs/
npm run forge:test # contracts/ (Foundry)
createLedger imports node:sqlite lazily and throws a clear error if it is unavailable: Node
22.5-22.x needs --experimental-sqlite; it is stable without a flag from Node 23 on.
Notes
- Non-custodial, always. hood-pay never holds a merchant's or a buyer's keys anywhere in the
package. The widget builds unsigned calls for the buyer's wallet; refunds build unsigned calls
for the merchant's own signer (
sendRefundor any viemWalletClient). - USDG is not a Stock Token. hood-pay settles in USDG (or any ERC-20 a merchant configures) only; it never touches Robinhood Chain's tokenized-equity Stock Tokens.
- Not affiliated with Robinhood Markets, Inc.
License
All rights reserved. See LICENSE.