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.
- 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
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
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
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
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) {
...
}
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();
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",
});
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();
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
fromapi.json
. Thenyarn tcs
to build *d.ts files and runlerna 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
├── 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
ton-client-ts is Apache-2.0 licensed.