Connect a web page to a Lotus wallet
Developers12.5.10+

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)
TransportA private MessageChannel portA redirect with a return URL
WhenThe user connected your site in the extensionAny visitor, no install
AnswerIn the page, at onceIn your return URL's fragment
Your originRead by the browserThe 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:

html
<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:

JavaScript
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 #

JavaScript
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: false is refused).

The PayButton PAY format (04 50415900, version, data, payment id) is decoded for the user: version, note and payment id.

A message signature #

JavaScript
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:

Text
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.000Z

Check 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 #

MethodWindowResult
wallet_getInfono{ protocol, chains, methods, intents } (no address)
wallet_connectonce per site{ address, caip2 }
wallet_getAddressno (connected sites){ address, caip2 }
wallet_fulfillIntentevery time{ txid, broadcast: true }
wallet_signMessageevery time{ address, message, signature, scheme }
wallet_disconnectno{ disconnected: true }

Errors #

A refused request rejects with a WalletError whose code is:

CodeMeaning
4001The user refused, closed the window, or did not answer in 10 minutes.
4100The site is not connected, or the wallet is locked or empty.
4200Method or intent not supported.
4290Too many requests: one waiting request per site, 6 windows and 60 requests a minute.
4900The wallet is not reachable.
4901The request is for another network than the wallet's.
-32602Invalid parameters (amount, address, data...).
-32603The 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:

JavaScript
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:

JavaScript
const answer = readWebWalletAnswer(); // { protocol, id, result } or { protocol, id, error }, or null

Anyone 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):

Networkcaip2
Mainnetbip122:000000000abc0cde58ee7e919d3d4de1
Napoleon test networkbip122:0000000010da3e1e26eb590b207666c5
Regtestbip122:106050de32db2a668422cc34aa0f96d7

Leave caip2 empty to accept the wallet's network; the handshake tells you which one it is.

A lotus: link may carry the data to write with the payment:

Text
lotus:lotus_16PSJHKLkxiakqViQDC1rKbuWhdJW3xE9X3mqZk19?amount=1.5&op_return_raw=04504159000000080102030405060708

op_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.

New in 12.5.11. A merchant's terminal can ask for notary receipts and for a payment guarantee (payer bond) in the link:

Text
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>
ParameterValueMeaning
receipts1 to 99The 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-bondXPI, same rules as amountA 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-key33-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_connect only 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.

Source share/www/docs/wallet-connect.md in the lotusd repository
Checked against share/www/lib/lotus-wallet-connect.js share/www/wallet/src/lib/walletConnect.ts extension/src/background/connect.ts extension/src/content/connect.ts extension/doc/WALLET-CONNECT.md share/www/wallet/src/lib/payuri.ts doc/finality/ux.md