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 🙏

© 2025 – Pkg Stats / Ryan Hefner

tolk-codegen

v0.0.4

Published

## Example generator ### Create builder file in root folder ``builder.ts``

Downloads

18

Readme

Tolk file generator by typescript decorators

Example generator

Create builder file in root folder builder.ts

import {createBuildsTolkToFile, createStorageTolkToFile, createOpsFile, createParsersTolkToFile} from "tolk-codegen";

async function build() {
    createStorageTolkToFile(Store, "contract.store.tolk");
    createBuildsTolkToFile([TokenNotification], [], "contract.builders.tolk");
    createParsersTolkToFile([TokenNotification], [], "contract.parsers.tolk");
    createOpsFile([TokenNotification], "ops.tolk");
}

build();

Start builder use nodemon nodemon --watch 'wrappers/**/*.ts' --exec 'ts-node' ./builder.ts

Create Store

import {StoreUint, StoreAddress, StoreBit} from "tolk-codegen";
import {Address} from "@ton/core";

@DefineCell()
class Store {
    @StoreUint(32)
    seqno!: BigInt;

    @StoreAddress()
    owner!: Address;

    @StoreBit()
    stop!: boolean;
}

Output store contract.store.tolk

global seqno: int;
global owner: slice;
global stop: int;

@inline
fun saveStorage(){
    setContractData(
            beginCell()
                .storeUint(seqno, 32).storeSlice(owner).storeBool(stop)
                .endCell()
        );
}

@inline
fun loadStorage(){
    var sc = getContractData().beginParse();
    seqno = sc.loadUint(32);
    owner = sc.loadAddress();
    stop = sc.loadBool();
}

Create Message

import {DefineCell, DefineMessage, StoreCoins, StoreAddress, StoreSliceRemaining} from "tolk-codegen";
import {Address, Slice} from "@ton/core";

@DefineCell()
@DefineMessage(BigInt(0x7362d09c))
class TokenNotification extends BaseMessageWithQueryId{
    @StoreCoins()
    amount!: BigInt;

    @StoreAddress()
    from!: Address;

    @StoreSliceRemaining()
    forwardPayload!: Slice;
}

Output message builder contract.builders.tolk

@inline // buildCellTokenNotification(op: int, queryId: int, amount: int, from: slice, forwardPayload: slice);
fun buildCellTokenNotification(op: int, queryId: int, amount: int, from: slice, forwardPayload: slice): cell{
    var data = beginCell();
    data.storeUint(op, 32);
    data.storeUint(queryId, 64);
    data.storeCoins(amount);
    data.storeSlice(from);
    data.storeSlice(forwardPayload);
    return data.endCell();
}

Output message parser contract.parsers.tolk

@inline // var (op, queryId, amount, from, forwardPayload) = parseCellTokenNotification(data);
fun parseCellTokenNotification(data: cell): (int, int, int, slice, slice){
    return parseSliceTokenNotification(data.beginParse());
}

@inline // var (op, queryId, amount, from, forwardPayload) = parseSliceTokenNotification(sc);
fun parseSliceTokenNotification(sc: slice): (int, int, int, slice, slice){
    return (sc.loadUint(32), sc.loadUint(64), sc.loadCoins(), sc.loadAddress(), sc.loadBits(sc.getRemainingBitsCount()));
}

Output OP ops.tolk

const TokenNotificationOP = 0x7362d09c;

Example use classes

import {buildCell, parseCell} from "tolk-codegen";
import {Address, Cell} from "@ton/core";

export class MyContract implements Contract {
    constructor(readonly address: Address, readonly init?: { code: Cell; data: Cell }) {
    }

    static createFromAddress(address: Address) {
        return new MyContract(address);
    }
    
    async getContractData(provider: ContractProvider){
        return await provider.getState().then(value => {
            if(value.state.type =='active'){
                return parseCell(Cell.fromBoc(value.state.data!)[0], Store)
            }
            return null;
        })
    }

    async sendMessage(provider: ContractProvider, via: Sender, message: MyMessage | TokenNotification, value: bigint) {
        await provider.internal(via, {
            value,
            sendMode: SendMode.PAY_GAS_SEPARATELY,
            body: buildCell(message),
        });
    }
}