npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@test-talk/tolk-js

v0.6.0

Published

Tolk language compiler (smart contracts in TON)

Downloads

2

Readme

WASM wrapper for TON Tolk Language

Tolk is a new language for writing smart contracts in TON. Think of Tolk as the "next-generation FunC". Tolk compiler is literally a fork of FunC compiler, introducing pretty syntax, but leaving all low-level optimizations untouched.

tolk-js is a WASM wrapper for Tolk compiler. Blueprint uses tolk-js to compile .tolk files, so if you develop contracts with blueprint, you don't have to install tolk-js directly. However, you can use tolk-js without blueprint, it has a simple and straightforward API.

tolk-js works both in Node.js and browser (does not depend on filesystem).

Installation

yarn add @ton/tolk-js
// or
npm install @ton/tolk-js

CLI mode

Its purpose is to launch a Tolk compiler from command-line, without compiling ton repo from sources, without installing apt/homebrew packages, etc. Just run

npx @ton/tolk-js --output-json out.json contract.tolk

Output JSON will contain fiftCode, codeBoc64, codeHashHex, and other fields (launch to see).

There are some flags like --cwd, --output-fift, and others (run npx @ton/tolk-js --help).

Usage example

import {runTolkCompiler, getTolkCompilerVersion} from "@ton/tolk-js"

async function compileMainTolk() {
  // for example, file `main.tolk` is saved nearby
  // fsReadCallback (below) is called for both main.tolk and all its imports
  let result = await runTolkCompiler({
    entrypointFileName: 'main.tolk',
    fsReadCallback: path => fs.readFileSync(__dirname + '/' + path, 'utf-8')
  })
  if (result.status === 'error') {
    throw result.message
  }

  console.log(result.fiftCode)
  // using result.codeBoc64, you can construct a cell
  let codeCell = Cell.fromBoc(Buffer.from(result.codeBoc64, "base64"))[0]
  // result has several (probably useful) fields, look up TolkResultSuccess
}

async function showTolkVersion() {
  let version = await getTolkCompilerVersion()
  console.log(`Tolk v${version}`)
}

The only point to pay attention at is fsReadCallback. It's called for every .tolk file, input or imported, and you should synchronously return file contents. tolk-js does not access filesystem itself, it just provides a flexible callback, so you can make it easily work if you have file contents in memory, for example:

let sources = {
  'main.tolk': 'import "utils/math.tolk"',
  'utils/math.tolk': '...',
}

runTolkCompiler({
  entrypointFileName: 'main.tolk',
  fsReadCallback: path => sources[path],
})

The function runTolkCompiler() accepts the following properties (look up TolkCompilerConfig):

  • entrypointFileName — obvious
  • fsReadCallback — explained above
  • optimizationLevel (default 2) — controls Tolk compiler stack optimizer
  • withStackComments (default false) — Fift output will contain comments, if you wish to debug its output
  • experimentalOptions (default '') — you can pass experimental compiler options here

Embedded stdlib functions

Tolk standard functions (beginCell, assertEndOfSlice, and lots of others) are available out of the box (if you worked with FunC earlier, you had to download stdlib.fc and store in your project; in Tolk, you don't need any additional files).

It works, because all stdlib files are embedded into JS, placed near wasm. If you import "@stdlib/tvm-dicts" for example, tolk-js will handle it, fsReadCallback won't be called.

Note, that folder tolk-stdlib/ and files within it exist only for IDE purposes. For example, if you use blueprint or tolk-js directly, JetBrains and VS Code plugins locate this folder and auto-complete stdlib functions.