Build on Lotus
A full node serves everything on this page itself: the REST API, the push interfaces, both Chronik protocols, the P2P protocol and the libraries for web pages. There is no separate indexer to install and no key to ask for.
Pick an interface
| You are writing | Use | Documentation |
|---|---|---|
| A web page, a bot, a script, an explorer | The REST API under /api/v1, in JSON | REST API |
| Something that reacts to payments and blocks | The WebSocket /api/v1/ws | Push interfaces |
An app built on chronik-client | /chronik and /chronik/v2 | Chronik |
| A light wallet that checks what it is told | P2P, with the address query and its Merkle proofs | P2P integration |
| A web page that follows the chain itself | The browser node, lotus-node.js | Browser node library |
| A page that asks the visitor’s wallet for something | lotus-wallet-connect.js | Wallet connect |
| A pay or donation button | The RankButton, lotus-rankbutton.js | Pay button |
| Votes, entities, tokens, files on chain | The protocol documents, then the module routes | On-chain protocols |
| Node administration, mining, the node wallet | JSON-RPC, with credentials | JSON-RPC |
Libraries
Every Lotus node serves these files under /lib/. A web site includes them from any node, or copies them: they have no dependency and no build step.
Browser node
Run a Lotus node in a web page: P2P over WebSocket, the block headers checked in the page.
/lib/lotus-loader.js
Makes a page a Lotus browser node in one script tag: a status chip, one set of connections for all the tabs of a site.
<script src="https://<node>/lib/lotus-loader.js" defer></script>
<script>
addEventListener('load', () => LotusLoader.ready.then(node => console.log(node.getTip())));
</script>/lib/lotus-node.js
The browser node itself, as a classic script: window.Lotus. It speaks the P2P protocol over WebSocket and checks the block headers.
<script src="https://<node>/lib/lotus-node.js"></script>
<script>
Lotus.connect({ network: 'mainnet' }).then(node => node.on('tip', t => console.log(t.height)));
</script>/lib/lotus-node.mjs
The same browser node as an ES module.
import Lotus from 'https://<node>/lib/lotus-node.mjs';
const node = await Lotus.connect({ network: 'mainnet' });Wallet connect
Ask the visitor's wallet for an address, a payment or a signature.
/lib/lotus-wallet-connect.js
Asks the visitor's Lotus wallet for an address, a payment or a signature: the extension, or the web wallet by a redirect. The page never sees a key.
import { connectExtension } from 'https://<node>/lib/lotus-wallet-connect.js';
const wallet = await connectExtension({ timeoutMs: 800 }); // null: no extension
if (wallet) console.log(await wallet.request('wallet_connect'));Pay button
Take payments in XPI on any web page.
/lib/lotus-rankbutton.js
The RankButton: a pay button for any web page. One attribute per option, nothing evaluated; the payment is seen over P2P.
<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>/lib/lotus-pay.js
The core of the button: payment requests, the PAY reference, addresses, amounts in sats, and the watch of a payment.
import { paymentRequest } from 'https://<node>/lib/lotus-pay.js';
const req = paymentRequest({ to: 'lotus_16PSJMStv9sve3DfhDpiwUCa7RtqkyNBoS8RjFZSt', amountXpi: '1.5', label: 'Order 7' });
console.log(req.uri, req.paymentId);/lib/lotus-qr.js
A QR code as SVG, with no dependency.
import { qrSvg } from 'https://<node>/lib/lotus-qr.js';
document.querySelector('#qr').innerHTML = qrSvg('lotus:lotus_16PSJMStv9sve3DfhDpiwUCa7RtqkyNBoS8RjFZSt?amount=1');/lib/demo-rankbutton.html
A page with two RankButtons, a fixed price and a donation, and the log of their events.
REST
Public routes need no credentials and no API key. Amounts are whole satoshis unless a field says otherwise: 1 XPI is 1,000,000 satoshis. The node describes its routes itself, in an OpenAPI document.
curl -s https://givelotus.org/api/v1/chain
curl -s https://givelotus.org/api/v1/games/BETB/stats
curl -s https://givelotus.org/api/v1/openapi.json | jq '.paths | keys[]'
Public nodes sit behind a proxy that may answer 429 or 403 on its own. For anything that matters, run your own node.
RANK API
RANK votes, profiles, posts and entities are read under /api/v1/social/. An app written for the RANK API finds it under /rank/api/v1 of a node.
Views over P2P
An app that already speaks P2P to a node needs no HTTP: the message getuiq names a public GET route and the node sends back the JSON REST would send, with its tip. Read only. An answer is the index of one node; compare two peers, or check the proofs where they exist.
| Message | Sent by | Meaning |
|---|---|---|
senduiq | the node | The families of views it answers, once after the handshake |
getuiq | the app | A request number, a family and one route of 1 to 256 bytes |
uiq | the node | The status, the tip it answered at, and the body: at most 512 KiB |
| Family | Views |
|---|---|
NODE (1) | Chain, upgrades, modules, network, statistics |
VOIX (2) | Messages, relays, phone book |
CHILD (3) | Child chains and their notarization |
FINALITY (4) | Notary receipts and double-spend proofs |
LAUNCH (5) | Launch pools |
TOKENS (6) | SLP and ALP tokens |
CHAIN (7) | Blocks, transactions, addresses, mempool, parent chains |
GAMES (9) | Games, players, leaderboards |
POOL (10) | The mining pool |
RANK (11) | RANK votes, profiles, posts |
CONTRACT (12) | Contracts |
REST (13) | Every other public GET route of the node |
const node = await Lotus.connect({ network: 'mainnet' });
const r = await node.ui('games/BETB/stats'); // getuiq
r.json; // the body REST would send
r.height; // the tip of the node that answered
r.peer; // which node
Transactions are sent as transactions, signed by the app. Other P2P messages: getaddrtxs (address history with proofs), getsoccounts (RANK counts), getfinality (receipts of one payment), getheaders.
Where to go next
- Quick start: read the chain and send a transaction, on a public node and on your own.
- RANK and entities API, Network map API, VOIX for developers.
- Launch pools, Payment receipts, Notarization, Games.
- API reference and Compatibility map.
