Take payments in XPI on any web page

The RankButton is a pay button in one script tag, served by every Lotus node. It needs no account, no server and no key: you give it your Lotus address, and the payment goes from the payer’s wallet to that address.

1
Script tag: one ES module, no build step, no framework
0
Keys on your page: it holds an address, nothing that can spend
17 bytes
Payment reference on the chain, inside the free data bytes of a transaction
7
Languages of the dialog: the page’s, the browser’s, or the one you set

Try it on the test network

This button is real and runs on the Lotus test network: its coins have no value. A wallet on mainnet refuses the address.

The button is loading.

    The dialog shows the amount, the QR code and the lotus: link that Lotus Desktop and the phone app open, the Lotus extension when the visitor connected it to the site, and the web wallet (here, the one of the test network). Nobody holds the key of the address shown: test coins sent to it stay there. To see a payment arrive, put an address of your own test network wallet and pay it from another one.

    Put it on your page

    Replace the address with yours. The price, a tip, the number of confirmations: each option is one attribute, read as data. Nothing is evaluated.

    <script type="module" src="https://<node>/lib/lotus-rankbutton.js"></script>
    
    <button data-rankbutton
            data-to="lotus_16PSJMStv9sve3DfhDpiwUCa7RtqkyNBoS8RjFZSt"
            data-amount="10"
            data-label="Order 7"
            data-confirmations="1"></button>
    AttributeMeaning
    data-toYour Lotus address: lotus_ on mainnet, lotusT on the test network. Copy it as it is: upper and lower case matter.
    data-amountThe price in XPI, at most 6 decimals. Without it, or with data-editable, the visitor types the amount.
    data-labelShown by the wallets as the description the site gives. Not written on the chain.
    data-textA short public text written on the chain with the payment.
    data-confirmationsWhen the button says “Paid”: 0 when full nodes relay the payment, N after N confirmations proven against the block headers the page checked. Default 1.
    data-tipTip choices in percent, for example 0,5,10, chosen by the visitor.
    data-payment-idnone: no payment reference; 1 to 999 satoshis are added so that the amount is unique.
    data-lang, data-wallet, data-peers, data-button-textThe language, the web wallet to open, the nodes tried first, the text of the button.

    Follow the payment

    The element receives DOM events with the transaction id, the payment id, the amounts and the confirmations.

    EventWhen
    rankbutton:openThe dialog opened.
    rankbutton:seenA full payment was seen, before your “Paid” moment.
    rankbutton:paidYour moment, as set by data-confirmations.
    rankbutton:unmatchedThe amount reached the address without this order’s reference. Never counted as paid.
    rankbutton:closeThe dialog closed.

    Before you deliver anything, check the payment on your own node: the transaction pays your address at least the amount, and its payment reference is the one of the order. The events are what one page saw. A plain payment is not final at once: use 0 confirmations only where nothing is delivered, such as a donation.

    How the payment is found

    Over P2P

    The button starts a browser node that speaks to full nodes over WebSocket. It asks them for the transactions that pay your address or carry the payment reference. It uses no HTTP API.

    Checked in the page

    Confirmations are counted on the headers the page verified, with a Merkle proof of the transaction. A reorganisation that removes the block takes “Paid” back.

    One payment, one order

    Each dialog has 8 random bytes as payment reference, written in an OP_RETURN output. One payment cannot count for two orders, and the wallets show the reference before the payer signs.

    Also in the module

    • From code. RankButton.render on an element, RankButton.open without one, RankButton.useNode for a page that already runs a browser node.
    • The core alone. lotus-pay.js: payment requests, addresses, amounts in satoshis, the payment reference, and the watch of a payment.
    • Donations to a node. A node started with -donationaddress shows a donation button on its network page.
    • Game wallets. A game page can be funded with a button and send the rest back to the wallet that paid, read from the funding transaction itself.

    Documentation of the button Connect a page to a wallet For developers