{"id":22243437,"url":"https://github.com/ton-community/tlb-codegen","last_synced_at":"2025-07-28T01:32:47.950Z","repository":{"id":207077912,"uuid":"718250276","full_name":"ton-community/tlb-codegen","owner":"ton-community","description":"Generate TypeScript code from TL-B scheme","archived":false,"fork":false,"pushed_at":"2025-07-14T16:34:22.000Z","size":460,"stargazers_count":24,"open_issues_count":5,"forks_count":10,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-07-14T21:18:36.435Z","etag":null,"topics":["tlb","ton","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ton-community.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"contributing.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-11-13T17:38:56.000Z","updated_at":"2025-07-14T16:34:22.000Z","dependencies_parsed_at":"2023-11-27T00:25:54.929Z","dependency_job_id":"663cd6f5-f4c9-4622-bb14-48dde7fc7391","html_url":"https://github.com/ton-community/tlb-codegen","commit_stats":null,"previous_names":["polyprogrammist/tlbgenerator"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/ton-community/tlb-codegen","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ton-community%2Ftlb-codegen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ton-community%2Ftlb-codegen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ton-community%2Ftlb-codegen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ton-community%2Ftlb-codegen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ton-community","download_url":"https://codeload.github.com/ton-community/tlb-codegen/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ton-community%2Ftlb-codegen/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267451039,"owners_count":24089291,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-27T02:00:11.917Z","response_time":82,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["tlb","ton","typescript"],"created_at":"2024-12-03T04:26:51.236Z","updated_at":"2025-07-28T01:32:47.521Z","avatar_url":"https://github.com/ton-community.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TLB Generator\nThis package allows you to generate `Typescript` code for serializing and deserializing structures according to the `TLB` scheme provided. \n\n[Here](https://docs.ton.org/develop/data-formats/tl-b-language) you can find documentation for creating TLB schemes, and more advanced article is [here](https://docs.ton.org/develop/data-formats/tl-b-types). \n\nThis package uses [TLB-Parser](https://github.com/ton-community/tlb-parser) to get AST of the scheme. \n\n## Installation \n\n```bash\nnpm install @ton-community/tlb-codegen\n```\n\n## Usage\n\n### CLI\n\nCreate a file with TLB scheme according to the [documentation](https://docs.ton.org/develop/data-formats/tl-b-language). This is an example of such a file (call it `example.tlb`):\n```\nt$_ x:# y:(uint 5) = A;\n```\n\nThen do:\n```bash\nnpx tlb example.tlb\n```\n\nIt will create a file called `example.ts` with the following code:\n```typescript\nexport interface A {\n    readonly kind: 'A';\n    readonly x: number;\n    readonly y: number;\n}\nexport function loadA(slice: Slice): A {\n    let x: number = slice.loadUint(32);\n    let y: number = slice.loadUint(5);\n    return {\n        kind: 'A',\n        x: x,\n        y: y,\n    }\n\n}\nexport function storeA(a: A): (builder: Builder) =\u003e void {\n    return ((builder: Builder) =\u003e {\n        builder.storeUint(a.x, 32);\n        builder.storeUint(a.y, 5);\n    })\n\n}\n```\n\nYou also can set an output file with `-o` option: `npx tlb -o other_file.ts example.tlb`.\n\nOne of the examples where you can see various abilities of the tool is [block.tlb](https://github.com/ton-blockchain/ton/blob/master/crypto/block/block.tlb). The generation result for it is [here](https://github.com/PolyProgrammist/tlbgenerator/blob/master/test/generated_files/generated_block.ts).  \n\n### Node JS\nAlso you can use the tool from inside JS or TS code.\n\n```typescript\nimport { generateCode } from \"@ton-community/tlb-codegen\"\ngenerateCode('example.tlb', 'example.ts', \"typescript\")\n```\n\n\n## Integration with @ton/core\n\nIt is integrated with [@ton/core](https://github.com/ton-org/ton-core/) in a way it uses several built-in types from there.\n\nBuilt-in types supported are:\n - `Bool` -\u003e `boolean` (loaded with `loadBoolean`, stored with `storeBit`)\n - `MsgAddressInt` -\u003e `Address` (loaded with `loadAddress`, stored with `storeAddress`)\n - `MsgAddressExt` -\u003e `ExternalAddress | null` (loaded with `loadMaybeExternalAddress`, stored with `storeAddress`)\n - `MsgAddress` -\u003e `Address | ExternalAddress | null` (loaded with `loadAddressAny`, stored with `storeAddress`)\n - `VarUInteger` -\u003e `bigint` (loaded with `loadVarUintBig`, stored with `storeVarUint`)\n - `VarInteger` -\u003e `bigint` (loaded with `loadVarIntBig`, stored with `storeVarInt`)\n - `Bit` -\u003e `boolean` (loaded with `loadBit`, stored with `storeBit`)\n - `Grams` -\u003e `bigint` (loaded with `loadCoins`, stored with `storeCoins`)\n - `HashmapE n Value` -\u003e `Dictionary\u003cbigint, Value\u003e` (or `Dictionary\u003cnumber, Value\u003e` if n \u003c= 64) (loaded with `Dictionary.load`, stored with `storeDict`)\n - `HashmapAugE n Value Extra` -\u003e `Dictionary\u003cbigint, {value: Value, extra: Extra}\u003e` (or `number` instead of `bigint` if `n \u003c= 64`) (loaded with `Dictionary.load`, stored with `storeDict`)\n\n\u003e Please note that the tricky thing here with `HashmapAugE` is that in `TLB` scheme extra is [stored](https://github.com/ton-blockchain/ton/blob/062b7b4a92dd67e32d963cf3f04b8bc97d8b7ed5/crypto/block/block.tlb#L49) not only with values, but in intermediate nodes as well. However `Dictionary` in [@ton/core](https://github.com/ton-org/ton-core) doesn't store the intermediate nodes. That is why `HashmapAugE` can be correctly loaded by the generated code, but storing is incorrect.  \n\n\u003e Please note that `BinTree` is not supported yet. In the future it will be supported as built-in type `BinTree` from [@ton/core](https://github.com/ton-org/ton-core).\n\n## License\n\nThis package is released under the [MIT License](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fton-community%2Ftlb-codegen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fton-community%2Ftlb-codegen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fton-community%2Ftlb-codegen/lists"}