rootchain-sdk
v1.0.2
Published
The Official TypeScript SDK for RootChain - High-precision RPC client.
Maintainers
Readme
rootchain-sdk
The rootchain-sdk provides a clean, heavily-typed API wrapper over the rootchain-rpc JSON-RPC 2.0 endpoints. It empowers developers to build rich, reactive Web3 interfaces on top of the RootChain ecosystem with absolute minimal overhead.
📦 Installation
This package is optimized for modern toolchains (Node >= 18, Bun, Vite).
npm install rootchain-sdk
# or
bun add rootchain-sdk
# or
yarn add rootchain-sdk
# or
pnpm add rootchain-sdk⚡ Core Features
- 100% Type-Safe: Comprehensive types for transactions, blocks, receipts, and RRC network structs.
- Offline Transaction Building: Deterministically serialize and sign payloads completely offline, mitigating key-leakage attacks.
- JSON-RPC Provider Wrapper: Native
JsonRpcProviderfor network data, account querying, and telemetry extraction. - Key Derivation: Securely derive Ed25519 paths via standard BIP-39 mnemonic recovery phrases.
- WASM Deployment Ready: Methods and structures natively adapted for deploying and querying sandboxed webassembly bytecodes.
🚀 Quick Start Guide
1. Initialize the Provider
Connect directly to your local node or remote rootchain-rpc endpoint:
import { JsonRpcProvider } from 'rootchain-sdk';
// Initialize the generic provider
const provider = new JsonRpcProvider('http://localhost:8545');
// Fetch network status
const { height, chain_id } = await provider.getChainInfo();
console.log(`Connected to ${chain_id} at block ${height}`);2. Wallet & Account Derivation
Derive your private keys deterministically and check your native balance securely:
import { Wallet } from 'rootchain-sdk';
// Instantiate a wallet connected to the provider
const privateKeyHex = "0x4f3c..."; // Ensure 32-bytes representation
const wallet = new Wallet(privateKeyHex, provider);
// Resolve public key representation
const address = await wallet.getAddress();
// Retrieve canonical balance and account nonce
const { balance, nonce } = await provider.getBalance(address);
console.log(`Remaining Balance: ${balance} micro-ROOT`);3. Issue a Raw Transaction
Seamlessly instruct the provider to broadcast signed Transfer transitions directly to the PoA network:
const txReceipt = await wallet.sendTransaction({
tx_type: "Transfer",
to: "0x8888...", // 32-byte recipient Hash
amount: 1000000000000n, // BigInt for safe u128 handling
fee: 1000n, // Network execution fee
payload: new Uint8Array() // Zero-length buffer for standardized transfers
});
console.log(`Transaction successfully queued with hash: ${txReceipt.hash}`);
// Optionally, await network determinism
await provider.waitForTransaction(txReceipt.hash);
console.log('Transaction explicitly finalized within an immutable block!');📚 Advanced Documentation
Submitting Equivocation Proofs
The SDK provides a built-in helper for submitting proofs of validator misbehavior:
const proof = {
validator: "0xaddr...",
height: 500,
round: 1,
hash_a: "0x...",
signature_a: "0x...",
hash_b: "0x...",
signature_b: "0x..."
};
const { hash } = await provider.submitEquivocationProof(proof);
console.log(`Equivocation proof submitted: ${hash}`);For deeper operational hooks into rootchain-std execution contracts (ContractCall and ContractDeploy), refer to the advanced ecosystem tutorials outlined in the /docs directory.
