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.

Libraries Views over P2P Documentation

Pick an interface

You are writingUseDocumentation
A web page, a bot, a script, an explorerThe REST API under /api/v1, in JSONREST API
Something that reacts to payments and blocksThe WebSocket /api/v1/wsPush interfaces
An app built on chronik-client/chronik and /chronik/v2Chronik
A light wallet that checks what it is toldP2P, with the address query and its Merkle proofsP2P integration
A web page that follows the chain itselfThe browser node, lotus-node.jsBrowser node library
A page that asks the visitor’s wallet for somethinglotus-wallet-connect.jsWallet connect
A pay or donation buttonThe RankButton, lotus-rankbutton.jsPay button
Votes, entities, tokens, files on chainThe protocol documents, then the module routesOn-chain protocols
Node administration, mining, the node walletJSON-RPC, with credentialsJSON-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>

Documentation

/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>

Documentation

/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' });

Documentation

/lib/demo.html

A page that runs the browser node and shows its peers, tip and checks.

Documentation

/lib/demo.js

The script of that demo page: LotusDemo.mount(element).

Documentation

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'));

Documentation

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>

Documentation

/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);

Documentation

/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');

Documentation

/lib/demo-rankbutton.html

A page with two RankButtons, a fixed price and a donation, and the log of their events.

Documentation

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.

MessageSent byMeaning
senduiqthe nodeThe families of views it answers, once after the handshake
getuiqthe appA request number, a family and one route of 1 to 256 bytes
uiqthe nodeThe status, the tip it answered at, and the body: at most 512 KiB
FamilyViews
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