BlockonomicsAPI Reference
Guides

Receiving Payments

Unified API to accept crypto payments on your website. One crypto-agnostic interface, built for both humans and AI agents.


Payment Intents API works on orders level using fiat amounts. It abstracts crypto payment processing so that you can accept multiple crypto by just implementing a single API. If your integration needs fine grain control of crypto payments, use Raw Payments API.

How It Works

Payment intent flowYour server creates a payment intent and passes its ID to your checkout page. checkout.js uses the ID to get a quote from Blockonomics, the customer pays, and checkout.js shows a receipt once the payment is detected. Blockonomics calls your server back when the intent is paid. Your server can optionally fetch the payment quotes for the crypto payment details, then fulfils the order.Checkout pagecheckout.js, intent ID onlyYour serverAPI keyBlockonomicsAPI + blockchainCreate payment intent1Intent ID pi_…Intent ID2Blockonomics.checkout(): status + quote3address, amount, 5-min price lockCustomer pays4Payment detected → receiptCallback: status paid5Get payment quotes (optional)6Crypto payment detailsFulfil order7
  1. Create an intent. Your server creates a payment intent for the order amount with your API key.
  2. Pass the ID. Your server sends the intent ID to your checkout page. The page needs nothing else.
  3. Get a quote. The checkout page asks Blockonomics for the status and a quote: address, amount and a 5-minute price lock.
  4. Customer pays. The customer sends the amount. The page shows a receipt once the payment is detected.
  5. Callback. Blockonomics calls your callback URL with status paid once the payment confirms.
  6. Get payment quotes (optional). Your server gets the intent's payment_quotes to get the crypto payment details: crypto txid and crypto amount.
  7. Fulfil the order. Your server fulfils the order.

Setup

1. Get Your API Key

Register on Blockonomics and get APIKey from Stores.

2. Add a Wallet

  1. Go to Wallets and click Add a wallet
  2. Select the cryptocurrency (BTC or USDT), fill out the form and click Create wallet. Add one wallet per crypto you accept.

3. Add a Store

  1. Go to Stores and click Add a store
  2. Fill out the form and click Create Store
  3. Enable each crypto and select its wallet
  4. Set the callback URL as indicated below
  • The store's callback URL must be reachable from the internet.
  • For production/remote site use its domain as DOMAIN. For local deployment, use a tunnel such as ngrok (ngrok http 3000) or localhost.run
  • Use a high entry random string as SECRET
  • Set store callback as https://DOMAIN/callback_endpoint?secret=SECRET.

Blockonomics dashboard showing wallet and store setup

To add/modify wallets and stores programmatically refer to wallets and stores API endpoints


Frontend Implementation

checkout.js handles crypto selection, QR code, price refresh, EVM wallet connect, underpayment top-ups and the receipt.

1. Create the intent on your server and return only its ID:

javascript
// Express.js example
app.post('/api/checkout', async (req, res) => {
  const order = await createOrder(req.body) // your code

  const response = await fetch('https://www.blockonomics.co/api/v2/payment_intents', {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${process.env.BLOCKONOMICS_API_KEY}`,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({ amount: order.total.toFixed(2), currency: 'USD', extra_data: order.id }),
  })
  const { data: intent } = await response.json()

  await saveIntentId(order.id, intent.id) // your code
  res.json({ intent_id: intent.id })
})

2. Mount the widget:

html
<script src="https://www.blockonomics.co/js/checkout.js"></script>

<button id="pay">Pay with crypto</button>
<div id="payment_area"></div>

<script>
  document.getElementById('pay').addEventListener('click', async () => {
    const { intent_id } = await fetch('/api/checkout', { method: 'POST' }).then((r) => r.json())
    Blockonomics.checkout({ msg_area: 'payment_area', intent_id })
  })
</script>
OptionRequiredDescription
msg_areaYesid of the element to render into
intent_idYesThe payment intent ID
onPaymentDetectedNoCalled when a payment covering the full amount is seen, before it confirms. Receives { txid, value, expected, crypto, intentId }. Use it to move the customer on, not to fulfil.
  • Closing: the widget hides itself and dispatches a bubbling close event on the container. Listen for it to close your modal.
  • Styling: set --bk-bg, --bk-fg, --bk-muted, --bk-accent, --bk-accent-fg, --bk-border, --bk-danger, --bk-font, --bk-radius, --bk-gap or --bk-width on the blockonomics-checkout element.
  • React / Next.js: load the script once (such as with next/script) and call Blockonomics.checkout() in a useEffect keyed on the intent ID.

Option 2: Use a Custom UX

Build your own screens when you need full control.

1. Crypto selection. Get payment status returns accepted_cryptos, due_amount and testmode. On selection, create a quote:

javascript
const API = 'https://www.blockonomics.co/api'

const { data: status } = await fetch(`${API}/v2/pay_stat/${intentId}`).then((r) => r.json())

async function getQuote(crypto) {
  const res = await fetch(`${API}/v2/pay/${intentId}`, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ crypto }),
  })
  return (await res.json()).data // { address, crypto_amount, expires_timestamp, ... }
}

crypto_amount is a string in base units: satoshi for BTC ("12966" = 0.00012966 BTC), 6 decimals for USDT ("10013511" = 10.013511 USDT).

2. BTC screen. Show address, the BTC amount, a QR code of bitcoin:<address>?amount=<btc> and a countdown to expires_timestamp. Each BTC quote has its own address, so detection is automatic. For instant feedback, optionally open a WebSocket on the address.

3. USDT screen with wallet connection. Embed the Web3 USDT Component and submit the transaction hash it returns:

html
<script src="https://www.blockonomics.co/js/web3-payment.js"></script>
<web3-payment id="web3_payment"></web3-payment>
javascript
const quote = await getQuote('USDT')
const web3 = document.getElementById('web3_payment')
web3.receive_address = quote.address
web3.order_amount = Number(quote.crypto_amount) / 1e6
web3.testmode = status.testmode

web3.onTxnSubmitted = ({ txhash }) =>
  fetch(`${API}/v2/pay/${intentId}/submit`, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ crypto: 'USDT', txhash }),
  })

A USDT payment whose hash is never submitted is not detected. All USDT quotes share the store's address, so the hash is what links a transfer to the intent.

4. Price refresh. On countdown expiry or a refresh click, call getQuote() with the same crypto. You get the same address with a new crypto_amount and expires_timestamp.

5. Check payment status. Poll Get payment status and loop while due_amount > 0.

Option 3: No UX / Agentic Payments

AI agents can pay an intent with the Payer API alone.

1. Return the payment intent ID at checkout.

2. Add payment instructions to your llms.txt. Adapt step 1 to your site:

markdown
## Paying for an order

1. Place the order: `POST https://yoursite.com/api/orders`. The response contains `payment_intent_id`.
2. Check what is due: `GET https://www.blockonomics.co/api/v2/pay_stat/{payment_intent_id}` → `due_amount`, `accepted_cryptos`.
3. Get a quote: `POST https://www.blockonomics.co/api/v2/pay/{payment_intent_id}` with `{"crypto": "BTC"}` or `{"crypto": "USDT"}`. Send exactly `crypto_amount` (satoshi for BTC, 6 decimals for USDT on Ethereum) to `address` before `expires_timestamp`. Call again to refresh the price.
4. USDT only: `POST https://www.blockonomics.co/api/v2/pay/{payment_intent_id}/submit` with `{"crypto": "USDT", "txhash": "0x..."}`. Unsubmitted USDT payments are never detected.
5. Poll step 2 every 10 seconds. While `due_amount` is above 0, pay the rest with a new quote.

Docs: https://developers.blockonomics.co/docs/payer-api

Anyone with the intent ID can pay it, so return it only to the payer.


Backend Implementation

Create a Payment Intent

bash
curl -X POST https://www.blockonomics.co/api/v2/payment_intents \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"amount": "10.00", "currency": "USD", "extra_data": "order-1234"}'

Returns the payment intent with its id (pi_…), status: "unpaid" and due_amount. Store the id with your order.

  • amount is a decimal string with 2 decimals.
  • extra_data is your reference (up to 2048 characters), such as the order ID. The payer never sees it.
  • match_callback picks the store if you have several: part of its callback URL, such as "example.com".

Handling Callbacks

Blockonomics sends a GET to your callback URL each time a payment moves an intent to processing, underpaid or paid:

GET https://example.com/blockonomics/callback?secret=YOUR_SECRET&id=pi_5GfD5m1b8khzFSLza91VR6&status=paid&due_amount=0.00&extra_data=b3JkZXItMTIzNA%3D%3D

extra_data is base64-encoded. Callbacks are not signed, so check the secret, then read the status from the API:

javascript
// Express.js example
app.get('/blockonomics/callback', async (req, res) => {
  if (req.query.secret !== process.env.BLOCKONOMICS_CALLBACK_SECRET) {
    return res.status(403).send('Forbidden')
  }

  const response = await fetch(
    `https://www.blockonomics.co/api/v2/payment_intents/${encodeURIComponent(req.query.id)}`,
    { headers: { Authorization: `Bearer ${process.env.BLOCKONOMICS_API_KEY}` } }
  )
  const { data: intent } = await response.json()

  if (intent.status === 'paid') {
    await fulfilOrder(intent.extra_data, intent) // must be idempotent
  }

  res.send('OK')
})
  • Fulfil only on status: "paid", never on due_amount or a frontend event. due_amount drops as soon as a payment is detected; status changes only on confirmation. The same status can arrive more than once.
  • Return 200 HTTP status. If Blockonomics doesn't get a 200, it retries the callback up to 7 times with exponential backoff.

Testing Notes

After implementation it is recommended to do E2E testing to verify the complete flow. Store can be put in test mode and toggled back after testing. Refer to Testing

Test these on a 10.00 USD intent:

  • Correct amount: processing callback, then paid. The order is fulfilled once.
  • Underpaid BTC: pay half. due_amount is about 5.00, Pay remaining shows, and after confirmation you get underpaid.
  • Underpaid BTC, completed with USDT: quote USDT for the remainder and pay its crypto_amount. You get paid once both confirm.
  • Price refresh: let the countdown expire or click refresh. Same address, new amount and expires_timestamp.