{"id":22243429,"url":"https://github.com/ton-community/func-js","last_synced_at":"2025-04-10T01:09:10.188Z","repository":{"id":59398795,"uuid":"533760709","full_name":"ton-community/func-js","owner":"ton-community","description":"FunC compiler package","archived":false,"fork":false,"pushed_at":"2025-02-13T12:50:55.000Z","size":9116,"stargazers_count":173,"open_issues_count":13,"forks_count":71,"subscribers_count":18,"default_branch":"master","last_synced_at":"2025-04-10T01:08:58.211Z","etag":null,"topics":["blockchain","compiler","func","hacktoberfest","ton","webassembly"],"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":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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}},"created_at":"2022-09-07T12:41:56.000Z","updated_at":"2025-04-09T10:43:59.000Z","dependencies_parsed_at":"2024-05-28T21:07:32.338Z","dependency_job_id":"1a916cde-4008-48f7-8221-033660e690b2","html_url":"https://github.com/ton-community/func-js","commit_stats":{"total_commits":68,"total_committers":4,"mean_commits":17.0,"dds":0.5147058823529411,"last_synced_commit":"b8af0812fabde5c293784b34b0c34d421c3ed8cf"},"previous_names":["the-ton-tech/ton-compiler"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ton-community%2Ffunc-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ton-community%2Ffunc-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ton-community%2Ffunc-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ton-community%2Ffunc-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ton-community","download_url":"https://codeload.github.com/ton-community/func-js/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248137887,"owners_count":21053775,"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","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":["blockchain","compiler","func","hacktoberfest","ton","webassembly"],"created_at":"2024-12-03T04:26:50.992Z","updated_at":"2025-04-10T01:09:10.151Z","avatar_url":"https://github.com/ton-community.png","language":"TypeScript","readme":"# TON FunC compiler\n\n[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://makeapullrequest.com)\n[![Version npm](https://img.shields.io/npm/v/@ton-community/func-js.svg?logo=npm)](https://www.npmjs.com/package/@ton-community/func-js)\n\nCross-platform bindings and CLI for TON FunC compiler.\n\n## Features\n\n- 🚀 No need to compile of download FunC binaries\n- 📦 Works both in Node.js \u0026 WEB (WASM support is required)\n- ⚙️ Compiles straight to BOC with code Cell\n- ⚙️ Assembly is returned for debugging purposes\n- 📁 Does not depend on filesystem\n\n## How it works\n\nInternally this package uses both FunC compiler and Fift interpreter combined to single lib compiled to WASM.\n\nSimple schema:\n```\n(your code) -\u003e WASM(FunC -\u003e Fift -\u003e BOC)\n```\n\nSources for the internal lib could be found [here](https://github.com/ton-blockchain/ton/tree/testnet/crypto/funcfiftlib).\n\n## Install\n\n```bash\nyarn add @ton-community/func-js\n```\n\nor \n\n```bash\nnpm i @ton-community/func-js\n```\n\n## CLI\nUsage: `npx func-js ./stdlib.fc ./wallet.fc --boc ./output.boc`\n\nSee more output options by running `npx func-js -h`\n\n## Usage example\n\n```typescript\nimport {compileFunc, compilerVersion} from '@ton-community/func-js';\nimport {Cell} from 'ton';\n\nasync function main() {\n    // You can get compiler version \n    let version = await compilerVersion();\n    \n    let result = await compileFunc({\n        // Targets of your project\n        targets: ['main.fc'],\n        // Sources\n        sources: {\n            \"stdlib.fc\": \"\u003cstdlibCode\u003e\",\n            \"main.fc\": \"\u003ccontractCode\u003e\",\n            // The rest of the files which are included in main.fc if any\n        }\n    });\n\n    if (result.status === 'error') {\n        console.error(result.message)\n        return;\n    }\n\n    // result.codeBoc contains base64 encoded BOC with code cell \n    let codeCell = Cell.fromBoc(Buffer.from(result.codeBoc, \"base64\"))[0];\n    \n    // result.fiftCode contains assembly version of your code (for debug purposes)\n    console.log(result.fiftCode)\n}\n```\n\nInstead of a source map, you can also use a source array, like so:\n```typescript\nlet result = await compileFunc({\n    // Sources\n    sources: [\n        {\n            filename: \"stdlib.fc\",\n            content: \"\u003cstdlibCode\u003e\",\n        },\n        {\n            filename: \"main.fc\",\n            content: \"\u003ccontractCode\u003e\",\n        },\n        // The rest of the files which are included in main.fc if any\n    ]\n});\n```\nNotice that passing a sources *array* makes `targets` optional (if not passed, `targets` will be set to `filename`s of `sources` in the order they were given).\n\nYou can also pass a resolver (a function of type `(path: string) =\u003e string`) into `sources` instead of a source map object or array, for example if `main.fc` and all contracts used by it (such as `stdlib.fc`) are located in the same directory as the compiling .ts/.js file, you can use the following:\n```typescript\nimport { readFileSync } from \"fs\";\nimport { compileFunc } from \"@ton-community/func-js\";\n\nlet result = await compileFunc({\n    // Targets of your project\n    targets: ['main.fc'],\n    // Sources\n    sources: (path) =\u003e readFileSync(__dirname + '/' + path).toString()\n});\n```\nAnd the resolver will be called for each required source file (including the targets) using the same name as in the `#include` statement. Note however that the resolver must be synchronous and must return a string; if you need the resolver to get files from the network, you can repeatedly run the compiler with the known sources, check if the compilation failed, download the required sources and rerun the compiler until compilation succeeds.\n\nNote that all FunC source files contents used in your project should be passed to `sources` (if it is a source map or array) or be resolvable by it (if it is a resolver), including:\n- targets\n- stdlib.fc (if you use it)\n- all files included in targets\n\n## License\n\nThis package is released under the [MIT License](LICENSE).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fton-community%2Ffunc-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fton-community%2Ffunc-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fton-community%2Ffunc-js/lists"}