3.3.1 • Published 2 months ago

@truecarry/ton-lite-client v3.3.1

Weekly downloads
-
License
MIT
Repository
-
Last release
2 months ago

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:

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() { },
        }
    }
});
3.3.1

2 months ago

3.3.0

2 months ago

3.2.0

2 months ago

3.1.1

4 months ago

3.1.0

4 months ago

2.3.0

7 months ago

2.2.1

12 months ago

2.2.0

1 year ago

2.1.0

1 year ago

2.0.0-beta.8

1 year ago

2.0.0-beta.7

1 year ago

2.0.0-beta.6

1 year ago

2.0.0-beta.5

1 year ago

2.0.0-beta.4

1 year ago

2.0.0-beta.3

1 year ago

1.7.0

1 year ago

2.0.0-beta.2

1 year ago

2.0.0-beta.1

1 year ago

2.0.0-beta.0

1 year ago

1.6.1

2 years ago

1.5.10

2 years ago

1.5.9

2 years ago

1.5.8

2 years ago

1.5.7

2 years ago

1.5.6

2 years ago

1.5.5

2 years ago