Skip to content
This repository has been archived by the owner on Mar 21, 2023. It is now read-only.
/ everscale-client-ts Public archive

Zero dependency cross-platform bindings for TON-SDK written in TypeScript

License

Notifications You must be signed in to change notification settings

RSquad/everscale-client-ts

Repository files navigation

ton-client-ts

ton-client-ts is a zero dependency cross-platform bindings for TON-SDK written in TypeScript. It can be used on both browser and node.js.

Overview

  • The library is fully typed
  • Complete generated in-code documentation
  • All binding units are covered with tests
  • All functionality of TON-SDK v1.1.2 is fully supported
  • The bindings interface is identical to the interface of the root library, nothing has been changed
  • All calls are asynchronous
  • Easy installation via platform-dependent npm packages

How does it works?

Here is a mono-repository built with lerna and yarn workspaces that includes the core web and node packages. The core package is a set of bindings, web and node packages provide the necessary library out of the box and are published as npm modules

The interface and class modules are generated from the api provided by the TON-SDK binary according to the current version

Quick start

To start coding, first of all, add bindings library to your project.

For node.js npm install --save @ton-client-ts/node

For web npm install --save @ton-client-ts/web

You can also use bundles from /packages/dist/main.js

Here and below there would be example for node.js. The usage of web package is the same.

Next, import TonClient from platform-depended lib

import { TonClient } from '@ton-client-ts/node';

Initialize client with config

const tonClient = new TonClient({ network: { server_address: "net.ton.dev" } });

Enjoy using!

const { version } = await tonClient.client.version();
console.log(version) // -> 1.1.2

Compatibility and support

TON-SDK v1.1.2

nodejs

  • Windows x86_64
  • Linux x64
  • macOS x64

web

  • Edge 86
  • Firefox 82
  • Google Chrome 86
  • Safari 14

and more, check — https://caniuse.com/?search=wasm

Example usage

Multisig deployment

  import { TonClient } from '@ton-client-ts/node';
  import { abi, tvc } from './multisig.package';

  const tonClient = new TonClient({ network: { server_address: "net.ton.dev" } });

  const deploySet = {
    tvc,
  };
  const callSet = {
    function_name: "constructor",
    input: {
      owners: [0x<public_key>],
      reqConfirms: 1,
    },
  };

  const signer = {
    type: "Keys",
    keys: { public: <public_key>, secret: <secret_key> },
  };

  try {
    await tonClient.abi.encode_message({
      abi: { type: "Contract", value: abi },
      signer,
      deploy_set: deploySet,
      call_set: callSet,
    });
	...
  } catch (err) {
    ...
  }

Generate keypair

  import { TonClient } from '@ton-client-ts/node';

  const tonClient = new TonClient({ network: { server_address: "net.ton.dev" } });

  const { public: publicKey, secret: secretKey } = await tonClient.crypto.generate_random_sign_keys();

Simple GraphQL collection request

  import { TonClient } from '@ton-client-ts/node';

  const tonClient = new TonClient({ network: { server_address: "net.ton.dev" } });

  const now = +(Date.now() / 1000).toFixed();

  const { result } = await tonClient.net.wait_for_collection({
    collection: "transactions",
    filter: {
      now: { gt: now },
    },
    result: "id now",
  });

Full TonClient lifecycle example

  import { TonClient } from '@ton-client-ts/node';

  const tonClient = new TonClient({ network: { server_address: "net.ton.dev" } })

  ...

  tonClient.destroy();

  // If you want to remove library hadler use this static method
  TonClient.deinit();

Development, testing and building

You have to use yarn to build and develop the library. This monorepo uses yarm workspaces to manage dependenices.

Install and link the dependencies at root directory yarn

Then build packages yarn build

It will run yarn generate for modules generation All modules are generated by script in ./packages/core/src/generator/src/index.ts from api.json. Then yarn tcs to build *d.ts files and run lerna run build:webpack --stream to build packages bundles

Now library is ready to do some usefull stuff.

To run tests execute command yarn test

To run web package in developer mode execute command yarn dev

Useful links

File structure with build artifacts

├── README.md # Thats what you are reading right now ;)
├── babel.config.js
├── jest.config.base.js
├── jest.config.js
├── lerna.json
├── package.json
├── packages
│   ├── core # package with general bindings functionality
│   │   ├── dist
│   │   │   └── main.js # main built core entry
│   │   ├── generator # TON-SDK modules generator
│   │   │   ├── package-lock.json
│   │   │   ├── package.json
│   │   │   ├── src
│   │   │   │   ├── api-freeton-builder.ts
│   │   │   │   ├── api.json
│   │   │   │   ├── builders.ts
│   │   │   │   ├── index.ts
│   │   │   │   └── utils.ts
│   │   │   └── tsconfig.json
│   │   ├── package.json
│   │   ├── src
│   │   │   ├── errors.ts # TonClientError class defenition
│   │   │   ├── index.ts # core package dev entry point
│   │   │   ├── modules/ # generated TON-SDK modules
│   │   │   └── utils.module.ts # TON-SDK module extends
│   │   ├── tsclib/  # compiled TS
│   │   ├── tsconfig.json
│   │   ├── tsconfig.tsbuildinfo
│   │   └── types/ # package type defenitions
│   ├── node # package that provides correct binary for core and exports TonClient for node.js usage
│   │   ├── dist
│   │   │   ├── main.js # main built node entry
│   │   │   ├── tonclient-linux.node # node.js linux binary
│   │   │   ├── tonclient-mac.node # node.js mac binary
│   │   │   └── tonclient-win.node # node.js win binary
│   │   ├── jest.config.js
│   │   ├── jest.setup.js
│   │   ├── package.json
│   │   ├── src
│   │   │   ├── index.ts # node package dev entry point
│   │   │   ├── tonclient-linux.node # node.js linux binary
│   │   │   ├── tonclient-mac.node # node.js mac binary
│   │   │   └── tonclient-win.node # node.js win binary
│   │   ├── tests/ # bindings test-suites
│   │   ├── tsconfig.json
│   │   ├── tsconfig.tsbuildinfo
│   │   └── types/ # package type defenitions
│   └── web
│       ├── dist
│       │   ├── index.html # html is used for dev mode and web debugging
│       │   ├── main.js # main built web entry
│       │   └── tonclient.wasm # web binary
│       ├── package.json
│       ├── src
│       │   ├── index.ts # web package dev entry point
│       │   ├── load.js # wasm web-worker loader
│       │   └── tonclient.wasm # web binary
│       ├── tsconfig.json
│       ├── tsconfig.tsbuildinfo
│       └── types/ # package type defenitions
├── tsconfig.json
├── tsconfig.settings.json
├── webpack.config.node.js
├── webpack.config.web.dev.js
├── webpack.config.web.js
└── yarn.lock

License

ton-client-ts is Apache-2.0 licensed.

About

Zero dependency cross-platform bindings for TON-SDK written in TypeScript

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published