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

@truecarry/ton-lite-client

v3.3.1

Published

ton-lite-client is a JS library that allows you to get information from TON Blockchain through it's native ADNL protocol.

Downloads

641

Readme

ton-lite-client

ton-lite-client is a JS library that allows you to get information from TON Blockchain through it's native ADNL protocol.

To get servers list, use official urls:

  • Mainnet: https://ton.org/global.config.json
  • Testnet: https://ton.org/testnet-global.config.json

Example of getting account state:

import { LiteClient, LiteRoundRobinEngine, LiteSingleEngine, LiteEngine } from "ton-lite-client";
import { Address } from "@ton/core";

function intToIP(int: number) {
    var part1 = int & 255;
    var part2 = ((int >> 8) & 255);
    var part3 = ((int >> 16) & 255);
    var part4 = ((int >> 24) & 255);

    return part4 + "." + part3 + "." + part2 + "." + part1;
}

let server = {
    "ip": 1097649206,
    "port": 29296,
    "id": {
        "@type": "pub.ed25519",
        "key": "p2tSiaeSqX978BxE5zLxuTQM06WVDErf5/15QToxMYA="
    }
}

async function main() {
    const engines: LiteEngine[] = [];
    engines.push(new LiteSingleEngine({
        host: `tcp://${intToIP(server.ip)}:${server.port}`,
        publicKey: Buffer.from(server.id.key, 'base64'),
    }));
    const engine: LiteEngine = new LiteRoundRobinEngine(engines);
    const client = new LiteClient({ engine });
    console.log('get master info')
    const master = await client.getMasterchainInfo()
    console.log('master', master)

    const address = Address.parse('kQC2sf_Hy34aMM7n9f9_V-ThHDehjH71LWBETy_JrTirPIHa');
    const accountState = await client.getAccountState(address, master.last)
    console.log('Account state:', accountState)
}

main()

By default, LiteClient uses cache for 4 things: blocks, blockHeaders, shards, account states at given block. All caches are LRU maps with capacity of 1000 elements. If your use case needs different caching strategy - you can bring your own map.

For example, you can cap every map at 100 000 elements:

const client = new LiteClient({
    engine,
    cacheMap: 100000,
});

Or you can cache only account states (not recommended, just example):

const client = new LiteClient({
    engine, cacheMap: (kind) => {
        if (kind === 'accounts') {
            return new Map()
        }

        return {
            get(key) { },
            set(key, value) { },
            delete(key: any) { },
            clear() { },
        }
    }
});