SDK Reference
The Lithosphere TypeScript SDK ships as two layered packages:
@lithosphere/blockchain-core— low-level primitives: network registry, typed ABIs (LEP-100, WLITHO, LITHONative),LithoError+ErrorCode, and shared types. Zero runtime dependencies — safe to include in browser bundles.@lithosphere/sdk— high-levelLithoClientwith retry/backoff, balance helpers, and transaction polling. Depends onblockchain-corefor ABIs and types; built on rawfetchso it works in Node 18+ and modern browsers without a transitive viem/ethers/web3 dep.
For contract writes and signing, pair the SDK with viem or ethers — the ABIs exported here plug directly into both.
Install
pnpm add @lithosphere/sdk
# pulls @lithosphere/blockchain-core transitivelyQuickstart — read the head block in 30 seconds
import { LithoClient } from '@lithosphere/sdk';
const client = new LithoClient('mainnet');
const height = await client.getBlockNumber();
console.log(`Lithosphere head block: ${height}`);Run it: save as head.ts, pnpm tsx head.ts. Should print the current block height against https://rpc.litho.ai in under one second.
Quickstart — balance lookup with proper error handling
Quickstart — LEP-100 token balance via viem
LithoClient
LithoClientConstructor
rpcUrlOrNetwork is either a registered network name ('mainnet', 'staging', 'devnet', 'local') or a fully-qualified http(s) RPC URL.
config (optional):
Retry uses exponential backoff: delay * 2^attempt. Only retries on transient failures (NETWORK_ERROR, RPC_TIMEOUT, RATE_LIMITED). JSON-RPC errors (invalid params, contract reverts) fail immediately — retrying won't help.
Methods
getChainId()
Promise<number>
Returns the configured chainId without calling RPC when known.
getBlockNumber()
Promise<number>
Current head block as decimal.
getBalance(addr, opts?)
Promise<AccountBalance>
Native LITHO balance with formatted (decimal string) and balance (bigint wei).
getTransaction(hash)
Promise<TransactionResponse | null>
Returns null for unknown hash.
getTransactionReceipt(hash)
Promise<TransactionReceipt | null>
Returns null while pending.
waitForTransaction(hash, confirmations?, timeoutMs?, pollIntervalMs?)
Promise<TransactionReceipt>
Throws LithoError(TIMEOUT) if not confirmed within the budget.
getNetworkConfig()
NetworkConfig | null
The registered NetworkConfig that matches this client's RPC URL.
All return types are exported from @lithosphere/sdk (re-exported from @lithosphere/blockchain-core).
NETWORKS registry
NETWORKS registryThe mainnet, staging, and devnet profiles currently all point at the live Makalu testnet (there is no separate mainnet chain yet — see chain-parameters.md). The local profile targets http://localhost:8545.
Errors
Every failure path throws LithoError with a typed code. instanceof LithoError and switch (err.code) are the supported patterns.
Underlying causes are preserved on err.cause (standard ES2022 Error.cause).
Typed ABIs
Three exports cover the contracts that ship with Lithosphere:
A versioned bundle of every compiled contract (ABI + bytecode + deployedBytecode + link references + a summary index.json) is uploaded by the Contract Artifacts (ABI + bytecode) job in ci-contracts.yaml as the contract-abis workflow artifact. Useful for deployment automation, on-chain verification tooling, and SDK consumers who want predictable addresses across networks. Grab the latest via:
A machine-readable copy of the api's GraphQL schema is checked in at schema.graphql — drop it into your GraphQL client of choice for typed access. CI's Schema Sync Check job re-prints src/schema.ts and fails if the artifact drifts, so the committed file is always a faithful representation of what /graphql actually serves.
These are JSON ABIs vendored at Makalu/packages/blockchain-core/src/abis/. The contract artifacts in Makalu/contracts/artifacts/ are the source of truth — drift between the two is blocked at CI time by the abi-sync-check job in ci-contracts.yaml. To re-sync after a contract change:
For tight viem / abitype inference, re-assert as const at the call site:
For most callers the default typing is sufficient — viem.readContract and ethers.Contract both accept the wider Abi type.
Project scaffolding
create-litho-app remains the fastest path from zero to a working project:
The CLI scaffolds an SDK-consuming starter that imports @lithosphere/sdk out of the box. The sdk template in this monorepo (Makalu/templates/sdk-template/, package name @lithosphere/sdk-template) is the source-of-truth for that scaffold and is intentionally not published to npm — it's copied into the new project on create-litho-app invocation.
Examples
Hardhat example — call contracts via Hardhat scripts
Foundry example — solc + foundry test runner
ethers.js example — read + sign transactions in Node
wagmi example — full Next.js + wagmi setup
Versioning
This SDK follows semver:
Patch — bug fixes only, no API changes.
Minor — additive (new methods / networks / types).
Major — breaking changes (reserved for v1.0.0+).
See the release process for the publish workflow and CHANGELOG.md in each package directory for the history.
Last updated