Lambit Documentation
Lambit is a functional TypeScript to Bitcoin Script compiler. Contracts are authored as pure TypeScript expression trees, then compiled into artifact-style JSON with ABI and locking script output.
Start Here
- Overview
- Installation
- Bitcoin Basics
- How to Write a Contract: Basics
- How to Write a Contract: Built-in Functions
- How to Write a Contract: Script Context
- How to Write a Contract: Stateful Contracts
- How to Test a Contract
- How to Deploy & Call
- How to Debug a Contract
- Examples
- TicTacToe Tutorial
What Lambit provides
| Area | Summary |
|---|---|
| DSL | Unified named contract() overloads plus explicit method(schema, fn) declarations. |
| Expressions | Typed combinators for logic, arithmetic, bytes, crypto, and build-time array transforms. |
| Compiler | Stack compilation, state lowering, and artifact assembly into JSON v10-compatible output. |
| Tests | Golden fixtures, compiler tests, and docs example validation. |
Quick example
The standard P2PKH helper provides the byte-minimal address check plus signature
check. Use pubKey2Addr(pubkey) when authoring custom P2PKH-style predicates; it
documents address intent while lowering to the same OP_HASH160 script surface as
hash160(pubkey).
import {
P2PKH,
} from '@opcat-labs/lambit';
const p2pkh = P2PKH({ addr: '00112233445566778899aabbccddeeff00112233' });
console.log(P2PKH.name); // P2PKH
console.log(p2pkh.artifact.hex); // 76a9<addr>88ac
Wrap the same predicate in assert(...) when you want assertion metadata at an explicit
verify boundary.
import {
contract,
method,
TypeTag,
and,
assert,
eq,
pubKey2Addr,
checkSig,
} from '@opcat-labs/lambit';
const AssertP2PKH = contract(
'AssertP2PKH',
{ addr: TypeTag.Ripemd160 },
({ props }) => ({
unlock: method(
{ sig: TypeTag.Sig, pubkey: TypeTag.PubKey },
(sig, pubkey) => assert(and(eq(pubKey2Addr(pubkey), props.addr), checkSig(sig, pubkey))),
),
}),
);
const assertP2pkh = AssertP2PKH({ addr: '00112233445566778899aabbccddeeff00112233' });
console.log(assertP2pkh.artifact.hex); // 76a9<addr>88ac6951
note
The repository validates published TypeScript examples through docs tests so the public guide snippets stay aligned with the current API.
Repository
- GitHub: OPCAT-Labs/lambit
- Source README: README.md
What's Next
- Start with Basics
- Review Built-in Functions before writing branch-heavy or loop-authored contracts
- Then continue to Stateful Contracts
- Use How to Deploy & Call when you are ready to fund and spend a contract