Payments and receipts
Examples use Arc testnet values (free faucet USDC). For production, swap in the mainnet column — see Networks.
Nibgate earnings are payment analytics, not withdrawals. Funds flow to the creator’s on-chain fee wallet contract, which enforces a 99% creator / 1% treasury split — see Revenue model.
Payment model
With hosted pay enabled, the hub resolves each creator’s payment destination to their GatewayFeeWallet contract (deployed deterministically per creator). The derivation is per recipient address: sites and posts using the same recipient share a fee wallet; different payout recipients get different fee wallets.
Nibgate does not need to custody funds to show earnings. It records payment events and receipt references after the creator site completes an unlock. Receipts store the gross amount plus a derived protocolFee (1% under hosted pay), to report the expected split; onchain distribution uses the fee at distribution time — see Revenue model.
Unlock model
One reliable path powers every rail:
one resource -> one payment -> one verified unlock receipt -> one entitlement -> one unlock proofOn hosted Nibshare and Subblogs, a paid entitlement persists while the resource remains reachable and access has not been revoked or banned: once a receipt exists, the wallet keeps access even after the proof expires or browser storage clears (the server re-issues a fresh proof on every legit visit). Existing active free entitlements may also continue granting access; removing a whitelist entry alone does not revoke the entitlement. The generic SDK does not add a persistent entitlement store automatically. Metered streaming, metered reading, passes, and agent quotas are future unlock strategies; they should still produce receipt events that can be indexed by Nibgate.
Unlock proofs (the short-lived cache)
Proofs are the browser/agent cache over the database; they are bindable and short-lived. Full grant logic lives on Whitelists & access control.
- Nibshare — server-minted:
{wallet}.{iat}.{exp}.{mac},mac = HMAC-SHA256("nibshare:{shareId}:{wallet}:{iat}:{exp}")keyed byNIBGATE_GATEWAY_SECRET/NIBGATE_PROOF_SECRET. 12h window. - Subblogs — SDK-signed: unlock token minted by
createNibgateServer(...)after proof verification, 12h TTL.
An expired proof is harmless — entitlements + receipts are checked before proof freshness, so the server simply re-mints on the next legit visit. The x-nibgate-payment-proof header carries the proof to media/document routes; ?proof= supports media elements that cannot send headers. A ?wallet= value alone is only a claim; the server must corroborate possession with a matching session or supported ownership signature before granting wallet-based access.
Payment idempotency: one grant per payment
When a settlement txHash is available, hosted receipt idempotency uses it as the payment nonce. Gateway responses may also carry an authorization/payment identifier while settlement is deferred. Both backends enforce a unique (paymentNonce=txHash, resourceId) index and do find-or-create on grant. A replayed proof hits the stored receipt and returns {receipt, replay: true} — no second grant, no double unlock count, no double event. This prevents repeated verification of the same settled transaction from creating duplicate receipts.
Receipt types
x402 gateway receipt
Use this when the unlock flow completes through a gateway-style x402 payment flow. Store the gateway receipt id or proof URL when available.
Headless x402 (agent/API flow)
For server-to-server or AI agent payments, use GatewayClient from @circle-fin/x402-batching/client:
import { GatewayClient } from '@circle-fin/x402-batching/client'
const agent = new GatewayClient({
chain: 'arcTestnet',
privateKey: process.env.AGENT_KEY,
rpcUrl: 'https://rpc.testnet.arc.io'
})
const result = await agent.pay(contentAccessUrl, {
headers: { 'x-nibgate-actor': 'agent' }
})The GatewayClient.pay() method auto-handles the 402 challenge → EIP-3009 signing → retry → settlement flow.
Direct transfer receipt
Use the direct rail when the buyer’s wallet sends USDC straight to the creator’s receiver (no Gateway facilitator). The browser checkout is createTransferCheckout/payWithTransfer from @nibgate/sdk — it broadcasts a USDC transfer to the seller’s payTo address and submits the tx hash as the x-nibgate-transfer-tx header on the access retry.
The retry must also carry an ownership proof: an EIP-191 signature (made by the paying wallet) over transferOwnershipMessage(txHash, resource) — i.e. Nibgate transfer ownership\ntx:<txHash lowercased>\nresource:<resource path or url> — sent as the x-nibgate-tx-owner header. This binds the public txHash to the payer and this specific resource. Missing proofs fail with transfer-ownership-proof-required, mismatched signers with transfer-owner-mismatch. Self-hosters can opt out with NIBGATE_TX_OWNER_PROOF_OPTIONAL=true; Nibgate-hosted surfaces additionally claim each txHash single-use per content id.
The server verifies on-chain (createTransferVerifier): the transaction mined successfully, a USDC Transfer log credits the seller’s address, and the amount is at least the resource price. On success it mints the unlock proof and returns the content, storing a paymentProvider: 'direct-transfer' receipt keyed by txHash.
import { payWithTransfer, createTransferCheckout } from '@nibgate/sdk'
import { encodeFunctionData, parseUnits, parseAbi } from 'viem'
const usdcTransferAbi = parseAbi(['function transfer(address to, uint256 amount) returns (bool)'])
const result = await payWithTransfer(resource, {
accessPath: '/api/nibgate/access',
checkout: createTransferCheckout(resource, {
// Broadcast the transfer from the connected wallet; return the txHash.
sendTransfer: async ({ recipient, amount }) =>
({ txHash: await walletClient.sendTransaction({
account,
to: '0x3600000000000000000000000000000000000000', // USDC token contract
value: 0n,
data: encodeFunctionData({ abi: usdcTransferAbi, functionName: 'transfer', args: [recipient, parseUnits(amount, 6)] })
}) })
}).pay,
signOwnership: ({ message }) => walletClient.signMessage({ account, message })
})Enabling hub event reporting
After successful Gateway payment through accessResponse or payAndUnlockResponse, the SDK emits payment_completed and unlock_completed events to the Hub — if the creator site has these env vars set:
| Env var | Purpose |
|---|---|
NIBGATE_SITE_ID | Hub website UUID |
NIBGATE_SITE_TOKEN | Hub website verify token |
NIBGATE_API_BASE | Hub API URL (e.g. https://api.nibgate.xyz) |
Without these, x402 payments still work and return unlock proofs, but unlock counts and revenue on Explore do not update.
Arc testnet receipt
Use this when the payment can link to an Arc testnet transaction hash or Arcscan URL.
Gateway balance & deposit
The hub backend exposes Circle Gateway helper status on both rails via the shared packages/internal/src/payments.js:
POST /nibshare/gateway/balance(hub) andGET /api/nibgate/gateway/balances(subblogs) — return the depositor’s balance on the configured Gateway network; the response shape and required authorization depend on the surface.- Browser deposits use the selected wallet to approve USDC and deposit it into the Gateway contract. Nibgate does not custody the wallet.
The SDK 0.4.40 and wallet 0.4.31 shared React and browser/CDN deposit flow waits for a successful approval receipt before requesting deposit, then verifies the matching transfer receipt before reporting success. Saved hashes survive panel remounts and reloads in the same tab. Resume checks the original transaction; an interrupted wallet request with no saved hash requires wallet-activity review before another payment.
Browser Gateway unlocks likewise retain submitted authorization proofs for an
explicit retryVerification() action. RPC repair requests the official settings
for the selected Arc network, verifies responding reads, and preserves pending
proofs. It never automatically retries a payment. These client changes are included in SDK 0.4.40 and wallet 0.4.31
on Arc mainnet and testnet. Configure the network and matching Hub together.
Event payload
Unlock completion events should include:
amountcurrencyreceiverrecipientsiteIdcontentIdtxHashfor chain transactions (this doubles as thepaymentNoncefor idempotent granting)paymentIdfor gateway/provider recordsreceiptUrlwhen the provider returns a real receipt URLchainExplorerUrlwhen availablepaidAt
Earnings dashboard
The dashboard should group earnings by site, receiver, content, currency, and time range. Clicking a receipt should open the source transaction or gateway receipt when available.
Google wallet compatibility: wallet 0.4.31 checks already-authorized accounts before SIWE, closes the AppKit sheet before the embedded signature prompt, and configures Reown’s Arc RPC routes on both networks. This avoids overlapping dialogs and Magic iframe restrictions on direct Arc RPC hosts. Nibgate’s application RPC proxies remain read-only; wallet signing still requires user approval.
Viem integration reference
For source-linked client, ABI, address and amount helpers used around these flows, see the Viem integration reference. It documents the pinned Viem 2.54.1 dependency and clearly separates local encoding or signature checks from payment settlement.