@repla/sdk-ts
v0.3.0
Published
REPLA TypeScript SDK -- programmatic interface to sequencer runtime + Anchor settler.
Readme
@repla/sdk-ts
TypeScript SDK for the REPLA framework — a workbench for Solana game-specific L3 rollups. It gives you three things: an HTTP client for the REPLA backend API, the byte-identical state-root hash the Rust sequencer runtime uses, and helpers for deriving the on-chain settler program's PDAs.
REPLA settles game state to Solana via an Anchor program and runs live state inside a MagicBlock-backed sequencer. The settler program is currently deployed on mainnet.
Install
npm i @repla/sdk-tsRequires Node ≥ 20.
Exports
| Export | Kind | What it does |
| --- | --- | --- |
| ReplaClient | class | HTTP client for the REPLA backend API (/api/health, /api/launch, /api/stats, /api/settle). |
| computeStateRoot(payloads) | fn | 32-byte root over raw payloads; byte-identical to the Rust runtime's batch.rs. |
| stateRootFromOps(ops) / merkleRoot(leaves) | fn | Apply 40-byte ledger ops ({ account, delta }) to a sorted balance ledger and Merkle-commit the resulting state; byte-identical to the Rust runtime's state machine. |
| bytesToHex(bytes) | fn | Lowercase hex encoding of a byte array. |
| REPLA_PROGRAM_ID | const | Settler program id (mainnet 42LxZ…). |
| registryPda / sequencerPda / l3Pda / settlementPda | fn | Derive the settler program's PDAs. |
| l3IdFromString(hex) | fn | Parse a 64-char hex id into a 32-byte Uint8Array. |
| defaultConnection() / PUBLIC_MAINNET_RPC | fn / const | Convenience Connection to the public mainnet-beta RPC. |
| LaunchConfig, LaunchResponse, StatsResponse, SettleRequest, Engine, GameType, LedgerOp | type | Request / response shapes for the API, plus the ledger op shape. |
REPLA API client
ReplaClient is a thin HTTP client over the REPLA backend service. It does not
sign or send Solana transactions itself — it calls the REPLA API, which queues
the on-chain work and reports status.
import { ReplaClient } from '@repla/sdk-ts';
const client = new ReplaClient({ apiUrl: 'https://api.repla.fun' });
const health = await client.health(); // { ok, version, network }
const stats = await client.stats(); // { sequencer_count, l3_count, settlement_count, ... }
const launch = await client.launchL3({
game_name: 'my-game',
engine: 'web',
owner: 'YOUR_OWNER_PUBKEY',
});
const settle = await client.settle({
l3_id: '00'.repeat(32),
from_slot: 1,
to_slot: 200,
state_root: '00'.repeat(32),
action_count: 0,
sequencer: 'YOUR_SEQUENCER_PUBKEY',
}); // { queued, tx_intent }Pass a custom fetchImpl (new ReplaClient({ apiUrl, fetchImpl })) to run the
client outside a runtime that has a global fetch.
State root
import { computeStateRoot, bytesToHex } from '@repla/sdk-ts';
const payloads = [new Uint8Array([0x61]), new Uint8Array([0x62, 0x62])];
const root = computeStateRoot(payloads);
console.log(bytesToHex(root));computeStateRoot takes the ordered action payloads and returns the 32-byte
root: each payload is prefixed with its 4-byte little-endian length, then the
whole stream is hashed once with SHA-256. This is byte-identical to the Rust
sequencer runtime (packages/sequencer-runtime/src/batch.rs), so the same
inputs produce the same root the chain settles against.
PDAs
import { PublicKey } from '@solana/web3.js';
import {
registryPda,
sequencerPda,
l3Pda,
settlementPda,
l3IdFromString,
} from '@repla/sdk-ts';
const [registry] = registryPda();
const [sequencer] = sequencerPda(new PublicKey('OPERATOR_PUBKEY'));
const l3Id = l3IdFromString('00'.repeat(32));
const [l3] = l3Pda(l3Id);
const [settlement] = settlementPda(l3Id, 200n); // toSlot is a bigintEach helper returns the [PublicKey, bump] tuple from
PublicKey.findProgramAddressSync and derives against REPLA_PROGRAM_ID by
default; pass a different program id as the last argument to target another
deployment.
On-chain
Anchor settler program (mainnet):
42LxZbUQHUSiBvuVzo1YtAxbjDbxLDLHNmQhyG5wabVV.
Mainnet deploy is scheduled into the launch sequence.
Related
- repla-cli — terminal interface, uses this SDK under the hood.
- @repla/magicblock-adapter — binds the sequencer runtime to MagicBlock Ephemeral Rollups.
Links
- Site — https://repla.fun
- Diorama — https://repla.fun/diorama
- Bench — https://repla.fun/bench
- Reference crate — https://github.com/replalabs/repla-core
- X — https://x.com/replagg
License
Apache-2.0.
