Docs
v1

Guide

Developer quickstart

Read the chain over HTTP, then install the Tenrai SDK to read a balance, send TRAI and follow the payment until it is final.

On this page

1. Make a request

The Tenrai API answers plain HTTP with JSON. No key, no account:

Shell
curl https://api.tenrai-technologies.org/v1/chain/head
JSON
{
  "chain_id": "…",
  "height": 20141,
  "cut_id": "77f71e53…",
  "state_root": "5486a81e…",
  "validator_set_id": "cce43cf4…",
  "params_hash": "8cb441b2…"
}

height is the newest finalized cut. Everything at or below it is final.

A node of your own serves the same routes at http://127.0.0.1:28701. The examples below work against either.

2. Install the SDK

The SDK covers every route, the WebSocket streams and a wallet that signs locally. It runs in Node.js 22.12 or later and in browsers.

Shell
npm install @tenrai/sdk

3. Read a balance

JavaScriptbalance.mjs
import { TenraiClient, formatTrai } from "@tenrai/sdk";

const tenrai = new TenraiClient();
const { balance } = await tenrai.address.balance("trai1…");
console.log(`${formatTrai(balance)} TRAI`);

Amounts are atoms in decimal strings; one TRAI is 100,000,000 atoms. formatTrai and parseTrai convert without floating point.

To use your own node:

JavaScript
const tenrai = new TenraiClient({ url: "http://127.0.0.1:28701", target: "node" });

4. Send TRAI

JavaScriptsend.mjs
import { TenraiClient, parseTrai } from "@tenrai/sdk";
import { Wallet } from "@tenrai/sdk/wallet";

const tenrai = new TenraiClient();
const wallet = await Wallet.fromMnemonic(process.env.TENRAI_MNEMONIC, { network: "mainnet" });

const sent = await wallet.send(tenrai, { to: "trai1…", amount: parseTrai("2.5") });
const final = await tenrai.transactions.waitForFinal(sent.transactionId, {
  validUntil: sent.validUntil,
});
console.log(final.lifecycle, final.finalized_cut?.height);

The wallet builds and signs inside WebAssembly; the recovery phrase never leaves your process. waitForFinal resolves with finalized, or with failed and the reason.

5. Follow the chain

JavaScript
const events = tenrai.events({ afterHeight: lastHeight });
events.on("cut", (event) => save(event.cut.height));

Every finalized cut arrives once, in order. After a lost connection the stream resumes where it stopped.

Next

Type to search guides, concepts and reference pages.