0to1pay Server SDK
Use this server SDK to sell digital goods or one-time paid access in a Next.js or Node.js app. Create a checkout that sends USDC or USDT directly to your merchant wallet. The hosted beta uses test USDC on Base Sepolia and Ethereum Sepolia and test USDT on TRON Nile. Requires Node.js 22.20.0+.
Choosing how to accept payment for an access pass? Compare payment options for a Next.js app.
Use a hosted payment link to add a buy button without building checkout. Create the link for your product in the merchant dashboard. Buyers need a wallet, test tokens and test gas. Your app verifies the signed webhook, records one grant per order for the paying wallet, and checks wallet ownership before unlocking an account. The beta collects no real sales revenue. Hosted payment link guide · 한국어 결제 링크 가이드
Next.js quickstart
Build a custom checkout. In the Next.js example, your server creates each order and quote. Its worker handles the example’s grant_plan action and grants one access pass after a 0.01 test USDC payment on Base Sepolia. Hosted links send grant_access to your own handler. Follow the Next.js quickstart or 한국어 빠른 시작. To make a test purchase, use a Base Sepolia wallet with test USDC and test ETH for gas. If you have already sent the payment, reopen your original order.
To run the Next.js checkout and webhook example from source, prepare Node.js 22.20+, writable PostgreSQL, a public HTTPS webhook and a separate continuously running worker. Create a test project and issue a scoped server key. Merchant dashboard
curl -fsSLO https://0to1pay.com/examples/nextjs-base-usdc.zip
unzip nextjs-base-usdc.zip
cd nextjs-base-usdc
npm ci
cp .env.example .env
Set DATABASE_URL, ZERO_TO_ONE_PAY_API_KEY, MERCHANT_ID and PROJECT_ID. Use the exact browser origin for APP_ORIGIN (local default http://localhost:3000) and the public HTTPS URL forwarding the original request bytes to POST /api/webhooks/0to1pay for WEBHOOK_URL. Run the app in one terminal and the worker in another, from the same directory.
npm run setup
npm run dev
npm run worker
Preserve the merchant database and private .merchant/ directory. The example associates one entitlement with its original order and guest. A signed recovery challenge lets the original paying wallet regain access after cookie loss. Setup and purchase recovery · Machine-readable guide
Use the server client in an existing app
npm install @0to1pay/server-sdk
Read the assets enabled for a test project from your server. Keep the API key in the server environment.
import { ZeroToOnePayClient } from '@0to1pay/server-sdk';
const client = new ZeroToOnePayClient({
origin: 'https://api.0to1pay.com',
apiKey: process.env.ZERO_TO_ONE_PAY_API_KEY,
});
const { data } = await client.call('listChainAssets', {});
const baseUsdc = data.find(asset => asset.network_id === 'eip155:84532' && asset.symbol === 'USDC');
Plans and usage
The project can use Sandbox for free with 1,000 metered requests per UTC calendar month. Prepay for 30 days with Starter (9 test tokens / 1,000 requests), Growth (29 / 5,000), or Scale (99 / 25,000). The beta accepts test USDC or USDT at zero real cost. All paid plans include Ethereum Sepolia, Base Sepolia, TRON Nile, the core APIs, webhooks and recovery. Pricing is independent of settled volume and successful payment count.
One order creation plus one quote creation uses two requests. With no other metered calls, 500 fresh checkouts consume Starter’s 1,000 requests. Include metered list/configuration reads in your estimate. Same-project, same-key, same-content creation retries count once. At 80% and 95% the API flags usage. At 100%, new starts stop and existing verification, fulfillment and redelivery continue. A manual upgrade charges the difference and retains usage and expiry. Renewals require a manual payment. The service does not bill overages. Estimate your 30-day cost
For integration tools and coding assistants, start with the Markdown quickstart, public OpenAPI JSON, API reference, and SDK reference.
Use call for the full merchant API. Use the same idempotency key when retrying a mutation for the same logical request. The client validates requests and responses against the bundled OpenAPI contract. The hosted API also serves the contract at /openapi.json. Keep the scoped key on your server and route browser actions through your merchant backend.
Create a stablecoin checkout
| Beta network |
network_id |
Test asset |
| Ethereum Sepolia |
eip155:11155111 |
USDC |
| Base Sepolia |
eip155:84532 |
USDC |
| TRON Nile |
tron:3448148188 |
USDT |
Call listChainAssets to see which assets your project can accept. Register a test connection and its merchant-owned receiving addresses through createChainConnection and registerChainRecipients. Create a payment using policy_ref: 'digital_goods_standard_v1' and a price in stable:USDC or stable:USDT with scale 6. For example, 0.01 USDC is { asset: 'stable:USDC', amount_atomic: '10000', scale: 6 }. The atomic amount must be positive and below 2^64. Each connection in allowed_connections must support the selected asset. Use a webhook from the same test project.
Call createQuote with the matching denomination or its registered asset on the selected chain. Then call createAttempt with connection_id and quote_id to read the reserved destination and transfer instructions. Finish checkout with the buyer authorization and signed transaction steps below.
Payment receipts
The Platform must support GET /v1/payments/{payment_id}/receipt.
Call getPaymentReceipt(payment_id) with a server key that has payments:read. Display each confirmed amount with its own asset, scale, and network. The receipt reports the funds received at the order’s destinations. Use the payment decision to determine whether to grant the purchased product. An empty available receipt has no confirmed funds. Payments without canonical receipt data can return availability: "unavailable".
Buyer approval for on-chain checkout
The merchant backend authenticates the buyer and checks their access to the quote on every checkout request. Give that checkout a stable, opaque checkout_session_ref of 16 to 128 base64url characters. Generate or derive it on the server and keep the raw session cookie or bearer token private. The three calls require a server key with payments:write.
- Call
client.createChainIntent(quoteId, { checkout_session_ref, payer_address }, createKey) with the wallet account that will fund the transfer.
- Have the wallet sign the exact returned
signing_message and call client.authorizeChainIntent(quoteId, intent.intent_id, { checkout_session_ref, signature }, authorizeKey). The message binds this authorization to the quote, payer, destination, network, asset, amount, and expiry. Preserve every byte of the message.
- After authorization, use the quote's existing transfer instructions. Once the wallet broadcasts, call
chainIntentClaimMessage(intent, transactionId) on the merchant server and have the same wallet sign the returned message.
- Call
client.submitChainIntent(quoteId, intent.intent_id, { checkout_session_ref, transaction_id: transactionId, signature }, submitKey) from the same checkout. Status submitted means the signed transaction claim was queued. Read the payment decision for verification and fulfillment status.
Use the wallet's UTF-8 message signing for the chain. Ethereum and Base use the EVM personal-message signature. TRON uses signMessageV2, which returns a 0x-prefixed signature. EVM and TRON transaction hashes must contain 64 hexadecimal digits. The claim helper accepts 0x or 0X and normalizes to lowercase 0x-prefixed hex. TRON also accepts bare hex.
The platform compares the finalized transaction's actual token source with the approved wallet and checks the exact token, destination, amount, and timing. If a buyer has already sent funds, resume the existing order and use the original transaction hash to finish the wallet proof. The buyer can share their order reference and hash with the merchant for help. Access is granted after the payment is confirmed and the signed fulfillment command is processed.
Subscription and API request allowance
To integrate with billing directly, use a dedicated billing key on your server. A test billing key with billing:write can issue a Sandbox server key via client.call('issueTestBillingKey', { body: {}, idempotencyKey }). The returned key belongs to the test environment. Save its token in your server's secret store. If the response is lost, retry with the same billing credential and idempotency key. A project can issue five Sandbox keys per rolling 24 hours and hold five active Sandbox keys. SANDBOX_KEY_LIMIT_REACHED indicates that limit was reached.
To purchase a prepaid subscription for your beta project and issue a server key, use the billing API from your backend.
- Call
listBillingPlans and getBillingSubscription to read plan terms, current request usage, and available collection networks. Each collection option identifies the network and test token to use.
- Call
createBillingInvoice with a paid plan_id, wallet payer_address and an opaque checkout_session_ref. Choose an offered network_id or omit it for the default configured collector.
- Sign the invoice intent, call
authorizeBillingInvoice, then send the exact token and amount in the quote on its specified network. TRON wallets sign the intent and transaction claim using the TRON V2 message format. Sign the transaction claim and call submitBillingInvoice with the same checkout session. Each mutation uses its own stable idempotency key.
- Use
listBillingInvoices to resume recent invoices and poll getBillingInvoice for a single invoice. During reconciling, wait for final reconciliation before paying again. An active invoice reflects verified payment and a current prepaid period. An early renewal can be scheduled for the end of the current period.
- Call
issueBillingKey with body: {} and a stable idempotency key. Store the returned token on the server.
API_REQUEST_LIMIT_REACHED indicates that the project has used its allowance for the period. Payment completion and fulfillment operations remain available to keys with the appropriate scopes.
The SDK is available under the MIT license. See the LICENSE file included in the package.