About
Tana ledger service

Tags
No tags available

Languages
TypeScript 95%, JavaScript 4%, Dockerfile 0%, Shell 0%

tana-ledger

blockchain state management service for Tana.

overview

tana-ledger is the core state layer of the blockchain. it manages user accounts, tracks balances across multiple currencies, validates and stores transactions, produces blocks, and executes smart contracts.

how it works

when a transaction arrives, the ledger validates signatures and business rules, applies state changes (balance updates, contract state), and includes the transaction in the next block. during block production, the ledger batches pending transactions, executes any contract logic, computes merkle roots, and persists the finalized block.

transaction flow

transaction submitted
        |
        v
signature verification
        |
        v
business rule validation
        |
        v
state transition applied
        |
        v
included in block
        |
        v
block finalized

smart contracts

contracts are TypeScript modules stored in t4 by their SHA256 hash. when a transaction invokes a contract, the ledger fetches the code from t4, executes it in tana-runtime (an isolated V8 sandbox), and applies the resulting state changes.

contracts can read and write to key-value storage, query user balances, and emit events. all contract operations are deterministic to ensure validators reach the same state.

architecture

built with TypeScript using Hono for HTTP and Drizzle ORM for PostgreSQL. the ledger maintains tables for users, balances, transactions, blocks, contracts, and validators.

block production

blocks are produced on a schedule or when transactions are pending. the ledger consumes transactions from tana-queue, validates each one, executes contract logic, and assembles the block with proper signatures and merkle proofs.

api

  • GET /users - list users
  • POST /users - create user
  • GET /balances/:userId - get balances
  • POST /transactions - submit transaction
  • GET /blocks - list blocks
  • POST /contracts/deploy - deploy contract
  • POST /contracts/:id/invoke - invoke contract

integration

tana-ledger coordinates with tana-consensus for block finalization, tana-queue for transaction ingestion, t4 for contract storage, and tana-runtime for contract execution.