Skip to main content

On-chain Payment Requests

vault-core 0.4.0. Live on regtest from block 1,934,800 and on signet from 2,004,400 (payment_requests in /tachi_nodeInfo features).

A payee opens a request for an amount on chain. A payer settles it by paying the payee, and the payee can cancel it while it is open. Each step is an ordinary ledger spend that pays its own fee and carries its payload in vaultPayload:

Tx typeCodeBuilderPayloadValue moved
payment_request0x30buildTachiTxPaymentRequestamount, expiry height, memoFee only
payment_request_pay0x31buildTachiTxPaymentRequestPay32-byte request IDamountSats to the payee, plus fee
payment_request_cancel0x32buildTachiTxPaymentRequestCancel32-byte request IDFee only

Every builder returns an unsigned TachiTx with exact change back to the sender, like buildTachiTxLedgerTransfer. Sign it with signTachiTx and send it with broadcastTachiTx.

Create a request​

import {
buildTachiTxPaymentRequest,
signTachiTx,
broadcastTachiTx,
tachiTxHash,
} from "@tachibtc/taurus-vault-core";

const draft = buildTachiTxPaymentRequest({
senderXOnly: payeeXOnly, // the payee opens the request
inputs: [{ vtxoId, valueSats: 2_000n }], // pays only the fee; the rest comes back as change
feeSats: 1n,
nonce,
amountSats: 400n, // > 0
expiryHeight: 0n, // last Tachi height it can be paid at; 0 = never expires
memo: "invoice #42", // at most 256 UTF-8 bytes
});
const signed = await signTachiTx(draft, payeeSigner);
await broadcastTachiTx(signed, { url: `${DAEMON_URL}/tachi_txBroadcastSync` });

const requestId = tachiTxHash(signed); // 32 bytes; hex it for the RPC

The request ID is the tx hash of the signed create tx. tachiTxHash(tx) is sha256(encodeTachiTx(tx)), the same hash the daemon names the tx by. The signature is part of it, so tachiTxHash throws on an unsigned tx. Hash the final signed tx you broadcast.

A create tx must leave at least one output. If the inputs exactly cover the fee, the builder throws, because the daemon rejects a tx with no outputs.

Pay a request​

import { buildTachiTxPaymentRequestPay } from "@tachibtc/taurus-vault-core";

const draft = buildTachiTxPaymentRequestPay({
senderXOnly: payerXOnly,
inputs: [{ vtxoId, valueSats: 5_000n }],
to: Buffer.from(req.payee, "hex"), // payee x-only key, from tachi_paymentRequest
amountSats: BigInt(req.amount),
requestId: Buffer.from(req.request_id, "hex"),
feeSats: 1n,
nonce,
});

Read the request with GET /tachi_paymentRequest?id= first and take payee and amount from it, not from whoever sent you the request ID.

Cancel a request​

Only the payee can cancel, and only a request that is not yet paid or cancelled:

import { buildTachiTxPaymentRequestCancel } from "@tachibtc/taurus-vault-core";

const draft = buildTachiTxPaymentRequestCancel({
senderXOnly: payeeXOnly,
inputs: [{ vtxoId, valueSats: 2_000n }],
requestId,
feeSats: 1n,
nonce,
});

Payload codec​

encodePaymentRequestPayload({ amountSats, expiryHeight, memo }) and decodePaymentRequestPayload(bytes) match the daemon's types.EncodePaymentRequest byte for byte:

amount i64 BE || expiry_height i64 BE || memo_len u16 BE || memo (UTF-8)

Both apply the daemon's checks: amount > 0, expiry >= 0, and a memo of valid UTF-8 of at most PAYMENT_REQUEST_MAX_MEMO_BYTES (256) bytes. Use decodeTachiTx plus decodePaymentRequestPayload(tx.vaultPayload) to show a signer what a create tx asks for.

Status​

curl "https://rpc-regtest.tachibtc.com/tachi_paymentRequest?id=<request id hex>"
{
"request_id": "97967cb2…77c37516",
"payee": "e7ab2537…b4f9c319",
"amount": 400,
"expiry_height": 1935619,
"memo": "e2e C: paid on chain",
"created_height": 1934903,
"status": "paid",
"closed_height": 1934906,
"paid_tx": "b9fdff20…8385b139",
"payer": "d61318bb…94360e75",
"paid_amount": 400
}

status is open, paid, cancelled or expired, as of the next block. paid_tx, payer and paid_amount are set once the request is paid. Unknown IDs return 404.

GET /tachi_listPaymentRequests?payee=<pubkey or taproot address>&limit=&offset= lists a payee's requests, oldest first, as { payment_requests, total }. limit defaults to 50, max 500. This endpoint pages with limit/offset, not page_size.

The SDKs wrap both: getPaymentRequest(id) / listPaymentRequests(params) in TypeScript, and PaymentRequest.Get / PaymentRequest.List in Go.

Rejection codes​

CodeMeaning
43Request not found
44Request is already paid or cancelled
45Underpaid: plain outputs to the payee sum to less than the amount
46Expired: the expiry height has passed (or, on create, is already behind the chain)

A pay only counts outputs to the payee with no locking script. Paying more than the amount is accepted, and paid_amount records what was paid.

caution

memo is chosen by the payee and is untrusted. Escape it before rendering it.