Developer quick start
Developers12.5.9+

Developer quick start

Read the chain from a public node, start a regtest node of your own, send a transaction through the REST API and watch it arrive, in curl, JavaScript and Python.

Ten minutes from nothing to a transaction you built, sent and saw confirmed. Every command on this page was run against the public mainnet API (read-only) and against a regtest node of this release.

1. Read the chain from a public node #

Shell
API=https://givelotus.org/api/v1
curl -s $API/chain/tip
curl -s $API/blocks/1433870
curl -s "$API/blocks/1433870/txs?limit=5"
curl -s $API/txs/133d43d6249a12197575abe90d08ee08a6279995e58794b86f754e6943eb23b9
curl -s $API/addresses/lotus_16PSJKoMbdnGyVQyxhuLuZxSuHvqKUy8nv98cXTVm
JSON
{"hash":"0000000000e9ac9a69c67e8ae65ee025b6a356397d79bdd1a8dcf491cd0dbfb9","height":1433879,"time":1795722569,"n_tx":1,"size":959,"previous_hash":"00000000014254ebc30bcda4defc8ebd1d37e8688627c16f0ae97083a24c9445"}

Errors always have the same body, {"error": "<code>", "message": "...", "status": <http>}; test error, show message. A 503 with node_warming_up or syncing is temporary: retry after Retry-After. See REST API.

The node can also run any read-only JSON-RPC command for you, without credentials:

Shell
curl -s "$API/rpc/getblockhash?0=1"
curl -s "$API/rpc/validateaddress?0=lotus_16PSJKoMbdnGyVQyxhuLuZxSuHvqKUy8nv98cXTVm"

2. Run your own regtest node #

Regtest is a private chain where you mine blocks on demand. Use it for everything that sends.

Shell
lotusd -regtest -daemon -txindex=1
lotus-cli -regtest createwallet dev
ADDR=$(lotus-cli -regtest getnewaddress)
lotus-cli -regtest generatetoaddress 101 $ADDR   # mined coins mature after 100 blocks
lotus-cli -regtest getbalance                    # 260.000000
API=http://127.0.0.1:12604/api/v1
curl -s $API/health

The REST API listens on the JSON-RPC port: 10604 on mainnet, 11604 on testnet, 12604 on regtest, on localhost only by default. Regtest addresses start with lotusR.

3. Build, sign and send a transaction #

The node wallet builds and signs here so that the example stays short; your own software would sign with its own keys (Transaction id, Signature hash). The broadcast goes through the REST API, as it would from any client.

Shell
TO=$(lotus-cli -regtest getnewaddress)
RAW=$(lotus-cli -regtest createrawtransaction '[]' "{\"$TO\":10}")
FUNDED=$(lotus-cli -regtest fundrawtransaction $RAW | jq -r .hex)
SIGNED=$(lotus-cli -regtest signrawtransactionwithwallet $FUNDED | jq -r .hex)
curl -s -X POST $API/txs/broadcast \
  -H 'content-type: application/json' -d "{\"hex\":\"$SIGNED\"}"
# {"txid":"6478a5132143fae03178edab7fa5f33942181249fe2bb279c7a930ae58bd8045"}

A refused transaction answers 400 with error rejected and the reason in message (for example TX decode failed). Sending the same transaction twice answers its txid again.

Related routes:

RouteUse
POST /txs/broadcast-checkedThe same, with the token burn guard: refuses a transaction that would destroy SLP or ALP tokens. Use it in a wallet that holds tokens
POST /txs/token-checkWhat the guard would say, without sending
POST /txs/decodeDecode a raw transaction
POST /txs/broadcast-batchUp to 1,000 transactions, with a node-wide rate limit

4. Watch it arrive #

Until it is mined, the payment is in the mempool. An address the chain has never seen answers 404 address_not_found on GET /addresses/<address>, even with a payment waiting; add include_unconfirmed=1, or ask POST /scripts/facts, which answers for any address:

Shell
curl -s "$API/addresses/$TO?include_unconfirmed=1"
# ... "confirmed_balance_sats":0,"pending_incoming_sats":10000000,"unconfirmed_tx_count":1 ...
lotus-cli -regtest generatetoaddress 1 $ADDR
curl -s "$API/addresses/$TO"
# ... "balance_sats":10000000,"tx_count":1 ...

To be told instead of asking, subscribe on the push WebSocket (start the node with -wslisten=127.0.0.1:12650; the public node serves it at wss://givelotus.org/api/v1/ws):

JavaScript
const ws = new WebSocket('wss://givelotus.org/api/v1/ws', 'lotus-push.v1');
ws.onopen = () => ws.send(JSON.stringify({op: 'subscribe', id: 1,
  subs: [{type: 'blocks'}, {type: 'address', value: 'lotus_16PSJKoMbdnGyVQyxhuLuZxSuHvqKUy8nv98cXTVm'}]}));
ws.onmessage = m => console.log(JSON.parse(m.data));

Subscriptions belong to the connection: reconnect and subscribe again. See Push interfaces.

5. Where to go next #

Source share/www/docs/dev-quickstart.md in the lotusd repository
Checked against src/api/chain_handler.cpp src/api/tx_handler.cpp src/api/address_handler.cpp src/api/legacy_rpc_handler.cpp src/push/wsserver.cpp src/chainparamsbase.cpp