Connect a web page to a Lotus wallet
Ask the visitor's Lotus wallet for an address, a payment (with OP_RETURN data) or a message signature, from your web page: the extension, the web wallet, payment links.
A web page can ask the visitor's Lotus wallet for three things:
- an address (to know who is paying or signing in);
- a payment, to one address, optionally with OP_RETURN data such as a payment reference;
- a message signature (sign-in, proof of ownership).
The wallet shows every payment and every signature to the user, in its own window, and does nothing without the user's click. Your page never sees a key, a balance or the wallet's coins.
Two ways in, one message format (lotus-wallet-connect/1):
| Browser extension (Lotus RANK) | Web wallet (/wallet/ of a node) | |
|---|---|---|
| Transport | A private MessageChannel port | A redirect with a return URL |
| When | The user connected your site in the extension | Any visitor, no install |
| Answer | In the page, at once | In your return URL's fragment |
| Your origin | Read by the browser | The return URL's origin |
A plain lotus: payment link (QR codes, phone wallets) also carries the OP_RETURN data, as op_return_raw (see the last section).
The page-side module #
Every node serves a small ES module with no dependency: lotus-wallet-connect.js. Copy it into your site (it makes no network request of its own) and import it:
<script type="module">
import { connectExtension, webWalletLink, readWebWalletAnswer, paymentLink } from './lotus-wallet-connect.js';
</script>With the extension #
The extension is not present on every site. It joins a site only when the user presses Connect this site to the wallet in its popup, while on your page. After that, and after each reload, your page finds it:
const wallet = await connectExtension({ timeoutMs: 800 });
if (!wallet) {
// Not connected here (or no extension): show "Open the Lotus extension and choose
// Connect this site", and offer the web wallet or a lotus: link instead.
}
const { address, caip2 } = await wallet.request('wallet_connect');connectExtension creates a MessageChannel, posts { protocol: 'lotus-wallet-connect/1', type: 'handshake-init' } to your own origin with one port, and waits for handshake-ack on that port. Everything after goes over the port: other scripts of the page cannot read the answers.
A payment #
try {
const { txid } = await wallet.request('wallet_fulfillIntent', {
intent: {
kind: 'lotus-payment',
to: 'lotus_16PSJHKLkxiakqViQDC1rKbuWhdJW3xE9X3mqZk19',
amount: '1500000', // sats: 1.5 XPI (or amountXpi: '1.5')
opReturnRaw: '04504159000000080102030405060708', // optional: OP_RETURN data, without the 6a
label: 'Order 7', // optional: shown as "the site's description"
},
});
} catch (e) {
if (e.code === 4001) { /* the user refused */ }
}The wallet builds and signs the transaction, shows the recipient's full address, the amount, the real fee and the decoded data, and broadcasts it when the user presses Pay. You get the txid. Check the payment yourself (amount, recipient, OP_RETURN) on chain or in your node's mempool before you ship an order: the answer is the wallet's word, not a proof.
Rules for a payment:
- one recipient, a Lotus address of the wallet's network (
lotus_…on mainnet,lotusT…on the test network); CashAddr (ecash:,bitcoincash:) is refused; - at least 546 sats (0.000546 XPI);
opReturnRaw: hex, data pushes only, at most 223 bytes with the OP_RETURN byte, written with no coins on it. RANK votes and token (SLP) messages are refused: they have their own screens in the wallet;- the wallet always broadcasts what the user approved. It never hands a signed transaction back to the page (
broadcast: falseis refused).
The PayButton PAY format (04 50415900, version, data, payment id) is decoded for the user: version, note and payment id.
A message signature #
const r = await wallet.request('wallet_signMessage', { message: 'Sign in to Sample shop', nonce: 'a1b2c3' });
// r = { address, message, signature, scheme: 'bitcoin-signed-message' }The wallet never signs your text alone. It signs this, and returns it to you as message:
shop.example asks you to sign this message with your Lotus address:
lotus_16PSJ…
Sign in to Sample shop
Origin: https://shop.example
Chain ID: bip122:000000000abc0cde58ee7e919d3d4de1
Nonce: a1b2c3
Issued At: 2026-11-27T10:00:00.000ZCheck on your server that Origin is yours, that the nonce is the one you issued and not used before, and verify the signature with the node (verifymessage <address> <signature> <message>, the same format as signmessage). The user must scroll through the whole text before Sign works. The message is at most 2,000 characters, with no control or direction-changing characters.
Methods #
| Method | Window | Result |
|---|---|---|
wallet_getInfo | no | { protocol, chains, methods, intents } (no address) |
wallet_connect | once per site | { address, caip2 } |
wallet_getAddress | no (connected sites) | { address, caip2 } |
wallet_fulfillIntent | every time | { txid, broadcast: true } |
wallet_signMessage | every time | { address, message, signature, scheme } |
wallet_disconnect | no | { disconnected: true } |
Errors #
A refused request rejects with a WalletError whose code is:
| Code | Meaning |
|---|---|
| 4001 | The user refused, closed the window, or did not answer in 10 minutes. |
| 4100 | The site is not connected, or the wallet is locked or empty. |
| 4200 | Method or intent not supported. |
| 4290 | Too many requests: one waiting request per site, 6 windows and 60 requests a minute. |
| 4900 | The wallet is not reachable. |
| 4901 | The request is for another network than the wallet's. |
| -32602 | Invalid parameters (amount, address, data...). |
| -32603 | The wallet could not do it (for example, not enough spendable coins). |
With the web wallet (no extension) #
Send the visitor to the web wallet with the request and a return URL of your site:
location.href = webWalletLink('https://lotusia.network/wallet/', 'wallet_fulfillIntent',
{ intent: { kind: 'lotus-payment', to, amount: '1500000', opReturnRaw } },
'https://shop.example/order/7', { id: 'order-7' });The link is <wallet>/#/connect?req=<base64url JSON request>&return=<URL>. The wallet shows the return URL's origin as the site that asks (and warns when the page that sent the visitor is another site), asks the user, then sends them back to return#lotus-wallet-connect=<base64url JSON answer>. The fragment never reaches a server. On that page:
const answer = readWebWalletAnswer(); // { protocol, id, result } or { protocol, id, error }, or nullAnyone can link to your page with a made-up fragment: treat the answer as a claim and check payments on chain. The return URL must be https:// (or http://localhost while developing).
A compatible envelope #
The request fields follow a common wallet-connection message shape, so a page written for it works with this wallet for the methods both have: protocol, id, method, caip2, then params (or intent beside the envelope). The wallet also answers protocol: 'lotus-connect/1' handshakes and requests in that shape, takes wallet_requestSession as wallet_connect, and takes a bitcoin-utxo-intent payment: outputs: [{ addressOrScript, valueSats }], one address output and at most one 6a… output with value 0. Nothing else of that format is implemented (no session keys, no spending allowance, no signed transactions handed to the page).
Network ids (CAIP-2, the first 16 bytes of the genesis hash):
| Network | caip2 |
|---|---|
| Mainnet | bip122:000000000abc0cde58ee7e919d3d4de1 |
| Napoleon test network | bip122:0000000010da3e1e26eb590b207666c5 |
| Regtest | bip122:106050de32db2a668422cc34aa0f96d7 |
Leave caip2 empty to accept the wallet's network; the handshake tells you which one it is.
Payment links with OP_RETURN data #
A lotus: link may carry the data to write with the payment:
lotus:lotus_16PSJHKLkxiakqViQDC1rKbuWhdJW3xE9X3mqZk19?amount=1.5&op_return_raw=04504159000000080102030405060708op_return_raw is the hex of the OP_RETURN output without its first byte (6a), with the same rules as above. The web wallet shows it, decoded, in the payment's review. paymentLink(address, { amountXpi, label, opReturnRaw }) in the module builds such a link.
Payment links for a terminal #
New in 12.5.11. A merchant's terminal can ask for notary receipts and for a payment guarantee (payer bond) in the link:
lotus:lotus_16PSJHKLkxiakqViQDC1rKbuWhdJW3xE9X3mqZk19?amount=12.5&label=Coffee&receipts=3
lotus:lotus_16PSJHKLkxiakqViQDC1rKbuWhdJW3xE9X3mqZk19?amount=12.5&receipts=3&req-bond=20&bond-key=<merchant key>| Parameter | Value | Meaning |
|---|---|---|
receipts | 1 to 99 | The terminal waits for this many notary receipts. Informative: the threshold of the pinned notary set is the minimum. A wallet that knows it shows the payment's progress after sending; older wallets ignore it and pay as before |
req-bond | XPI, same rules as amount | A payer bond of at least this much is required. Being a req- parameter, it makes a wallet that cannot post a bond refuse the link instead of paying without one |
bond-key | 33-byte compressed public key, lower-case hex (02... or 03...) | The merchant key the bond must name: only that key can claim it. Required with req-bond |
A wallet refuses a link with any other req- parameter it does not know, a receipts value outside 1 to 99, or req-bond without a valid bond-key. The receipts name the transaction, not the sale: the terminal matches the payment by payee, amount (at least the amount asked) and time (seen after the code was shown). See Notary receipts and double-spend proofs.
Security notes for site authors #
- Any script running on your connected origin can use the wallet as your page: keep third-party scripts off your checkout pages.
- The wallet answers only top frames: a page that embeds yours in an iframe cannot use it.
- A connected site sees the visitor's receive address, and two connected sites can see that it is the same visitor. Ask for
wallet_connectonly when you need it. - Your page must still verify payments and signatures itself.
The design, the checks and the threat model are in extension/doc/WALLET-CONNECT.md in the source tree.
