https://github.com/ton-community/tlb-runtime
TL‑B Runtime is a library for parsing and (de)serializing binary data according to formal schemas
https://github.com/ton-community/tlb-runtime
abi schema tl-b tlb tlb-runtime tlb-simulator ton
Last synced: 3 months ago
JSON representation
TL‑B Runtime is a library for parsing and (de)serializing binary data according to formal schemas
- Host: GitHub
- URL: https://github.com/ton-community/tlb-runtime
- Owner: ton-community
- License: mit
- Created: 2025-08-25T14:55:15.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2025-09-26T17:25:54.000Z (4 months ago)
- Last Synced: 2025-10-03T12:12:58.778Z (3 months ago)
- Topics: abi, schema, tl-b, tlb, tlb-runtime, tlb-simulator, ton
- Language: TypeScript
- Homepage: https://npmjs.com/package/@ton-community/tlb-runtime
- Size: 202 KB
- Stars: 11
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# TL-B Runtime
TL‑B Runtime is a library for parsing and (de)serializing data according to [TL‑B schemas](https://docs.ton.org/v3/documentation/data-formats/tlb/tl-b-language), enabling programmatic work with binary structures and [Cell & Bag of Cells (BoC)](https://docs.ton.org/v3/documentation/data-formats/tlb/cell-boc)
## Quick Start
```bash
npm install @ton-community/tlb-runtime
```
## Usage
### Simple
```typescript
import { parseTLB } from '@ton-community/tlb-runtime';
interface Data {
kind: 'Foo';
x: number;
}
// language=tlb
const runtime = parseTLB('_ x:# = Foo;')
const pack = runtime.serialize({
kind: 'Foo',
x: 73,
})
if (pack.success) {
console.log({ pack: pack.value.endCell().toBoc().toString('base64')});
} else {
console.error(pack.error.message);
}
// { pack: 'te6cckEBAQEABgAACAAAAEmTxmY2' }
const unpack = runtime.deserialize('te6cckEBAQEABgAACAAAACoFpvBE')
if (unpack.success) {
console.log({ unpack: unpack.value});
} else {
console.error(unpack.error.message);
}
// { unpack: { kind: 'Foo', x: 42 } }
```
## TEP-74 Fungible tokens (Jettons)
```typescript
import { parseTLB } from '@ton-community/tlb-runtime';
// language=tlb
const schema = `nothing$0 {X:Type} = Maybe X;
just$1 {X:Type} value:X = Maybe X;
var_uint$_ {n:#} len:(#< n) value:(uint (len * 8)) = VarUInteger n;
addr_none$00 = MsgAddressExt;
addr_extern$01 len:(## 9) external_address:(bits len) = MsgAddressExt;
anycast_info$_ depth:(#<= 30) { depth >= 1 } rewrite_pfx:(bits depth) = Anycast;
addr_std$10 anycast:(Maybe Anycast) workchain_id:int8 address:bits256 = MsgAddressInt;
addr_var$11 anycast:(Maybe Anycast) addr_len:(## 9) workchain_id:int32 address:(bits addr_len) = MsgAddressInt;
_ _:MsgAddressInt = MsgAddress;
_ _:MsgAddressExt = MsgAddress;
burn#595f07bc
query_id:uint64
amount:(VarUInteger 16)
response_destination:MsgAddress
custom_payload:(Maybe ^Cell)
= InternalMsgBody;`
const runtime = parseTLB(schema)
const pack = runtime.serialize({
kind: 'InternalMsgBody',
query_id: 0,
amount: 1n,
response_destination: 'Ef8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADAU',
custom_payload: { kind: 'Maybe_nothing' }
})
if (pack.success) {
console.log(pack.value.endCell().toBoc().toString('base64'));
} else {
console.error(pack.error.message);
}
// te6cckEBAQEAMQAAXllfB7wAAAAAAAAAABAZ/gAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA8gPSJw==
const unpack = runtime.deserialize('te6cckEBAQEAMQAAXllfB7wAAAAAAAAAABKp/gAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA4/EP1Q==')
if (unpack.success) {
console.log(unpack.value);
} else {
console.error(unpack.error.message);
}
// { kind: 'InternalMsgBody', query_id: 0n, amount: 42n, response_destination: Ef8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADAU, custom_payload: { kind: 'Maybe_nothing' } }
```
## Development
```bash
yarn install
yarn build
yarn test
yarn lint
yarn lint:fix
```
## Release
```bash
yarn install --frozen-lockfile && yarn build && npm publish --tag=alpha --try-run
```