Urgent.News

What's breaking now, across thousands of outlets.

Finance & Markets

Accept crypto payments in Node.js

A step-by-step Moonvex integration in plain Node.js with the official @moonvex /node SDK: your server creates an invoice, the customer pays on a hosted page, and an HMAC-signed webhook marks the order paid. No framework, just node:http and PostgreSQL. Step by step 1. Get an API key and a webhook secret In the Moonvex dashboard go to “Integration” → “Create key” → type “Secret” (sk_live_…). The…

To accept cryptocurrency payments in a Node.js application, follow these steps. First, obtain an API key and webhook secret from the Moonvex dashboard. The API key is required for creating invoices, while the webhook secret is used for generating signing secrets. Store both values securely on your server.

Next, install the @moonvex/node SDK and PostgreSQL, which are the only dependencies needed for this integration. Set up environment variables for the API key, webhook secret, and database connection URL.

Create a function that uses the SDK to generate an invoice for an order. The function should take an order object and an optional attempt parameter. The Moonvex.create method should be used to create the invoice, passing the order ID, total amount in string format, currency, network, customer ID, and expiration time. To prevent duplicate payments, use an idempotency key that combines the order ID, amount, and attempt number.

If a duplicate order error occurs, retrieve the existing payment from the database using a GET request. If a payment already exists, return it; otherwise, re-throw the error.

Finally, redirect the customer to the paymentUrl generated by the SDK. This hosted payment page will display the exact amount, including fees, the recipient address, a QR code, the official token contract, and a timer. It is essential to redirect or open the payment page using a GET request, as iframe embedding is not allowed. Monitor the payment status using a webhook or by retrieving the payment details from the API.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Finance & Markets

More from Thursday 12 November →