Integrate a wallet or marketplace
An application needs two things to work with XMR721, a reader to query and a way to have the user sign a message. The rule library in the repository builds the records and the texts to sign.
#Reading the ledger
To show what an address owns, its history, listings and pictures, read a reader: your own, or the public one.
curl https://api.xmr20.org/xmr721/address/<address>
curl https://api.xmr20.org/xmr721/mordinal/<number>
curl https://api.xmr20.org/xmr721/content/<number>
curl https://api.xmr20.org/xmr721/nft/<id>Run your own reader for anything that matters: a reader's answers are its own statements until you check them. See the HTTP API.
#Making a record
Every signed action follows the same steps:
- Build the body from the NFT's current state (its 32-byte name and counter) and what the user wants.
- Render the text the wallet will sign. It is fully decided by the body.
- Have the wallet sign it with Sign message, with the spend key of the address the rules name: the owner for a move or list, the buyer for a reservation, the creator for a collection or mint.
- Attach the signature and hand the record to a relay with
POST /records, or carry it in a transaction of your own.
#Example: send a Mordinal
This runs with Node.js 22 from the repository folder, against the public reader. It uses only the repository's rule library.
import {OP, encodeBody, renderText, attachSignature} from './rules/lib/records.mjs';
const READER = 'https://api.xmr20.org/xmr721';
const get = path => fetch(READER + path).then(r => r.json());
const info = await get('/info');
const n = 2177; // the Mordinal to send
const {mordinal: m} = await get(`/mordinal/${n}`);
// 1. The body: from its owner to a new address, at its current counter.
const body = {reg: m.reg, seq: m.seq, from: m.owner, to: '<new owner address>'};
const bodyBytes = encodeBody(OP.move, body, info.network);
// 2. The text the owner signs.
const ctx = {domain: info.domain, number: n};
const text = renderText(OP.move, body, bodyBytes, ctx);
// "Mordinals move: send Mordinal #2177 to 4…; move 1; code e20f…"
// 3. The owner signs `text` with Sign message in their wallet and gives you the signature ("SigV2…").
const signature = await askTheWalletToSign(m.owner, text);
// 4. The record, checked against the text and address, handed to the relay.
const record = attachSignature(bodyBytes, signature, ctx, info.network);
const job = await fetch(READER + '/records', {
method: 'POST',
headers: {'content-type': 'application/json'},
body: JSON.stringify({record: Buffer.from(record).toString('hex')}),
}).then(r => r.json());
console.log(job.state, job.id); // then poll GET /status/<id>attachSignature refuses a signature that is not by that address's spend key over exactly that text. For a minted NFT, use its id as reg and give the text its name with ctx.what = nftLabel(id, nft, collectionName), also from records.mjs, as the market pages in reader/views/ do.
#Wallets that sign messages
| Wallet | How a user signs |
|---|---|
| Feather | Tools → Sign/verify message |
| Monero GUI | Advanced → Sign/verify |
| Monero CLI | sign <file> |
| monero-wallet-rpc | sign with data set to the text |
| Cake Wallet | its Sign and verify screen |
Wallets end the text in different ways. The record's variant byte says which: none, a line feed, or a carriage return and a line feed. attachSignature finds it for you.
#Purchases
A purchase is the one record without a signature: it carries proofs of the buyer's payments instead. Your app needs the buyer's payment transaction ids and transaction keys, uses GET /tx/<txid> to fetch each payment as the rules read it, and makes the proofs with the library (provePayments in rules/lib/payment.mjs). The keys never leave your app and never go into the record. Study reader/views/market.js for the whole flow, and see Sell and buy for the timing rules.
#A marketplace fee
A marketplace can earn a fee on top of the price: the reservation names the marketplace's address and a rate in basis points, at most 500 (5%). The buyer then pays three payees: seller, protocol fee, marketplace. Nothing else changes, and any reader applies it.
#Claims
Claims are the most involved records: the burn is a transaction in the original 2023 format, and a claim by a spent coin needs a payment proof and a signed key image. Start from the burn and claim code in the XMR20 wallet and from rules/lib/burn.mjs and rules/lib/spend.mjs, and read RULES.md sections 10 and 11.
#Carrying records yourself
Instead of a relay, any wallet that can put bytes into a transaction's extra field can carry a record: frame it as in Records and signed texts and send any ordinary transaction. The xmr721 command's carrier tool (reader/carrier) is a working example in Rust.