Home

Awesome

<p align="center"><a href="https://github.com/everx-labs/ever-sdk-js/"><img src="media/ton-sdk-blue.png" height="60"/></a></p> <h1 align="center">JavaScript SDK for TVM compatible networks </h1> <p align="center">Client Library built for Everscale, Venom blockchain, TON, Gosh</p> <p align="center">for Web, Node.js and React Native platforms</p>

Have a question? Get quick help in our channel:

Chat on Telegram

Table of Content

Useful links

Library distribution

This SDK is distributed via npm packages:

You can find their source code in this repository.

Installation

Prerequisites

Package probably works OK on other Node.js versions, but we use 14 version in our testing pipelines so we quarantee its stable work only on 14 version.

Install core package

npm i --save @eversdk/core

Install bridge package (depends on target JS platform)

The bridge package will download precompiled binaries from TON Labs cloud storage. If you want to rebuild binary from sources see [build binaries](#build binaries) section.

NodeJs

npm i --save @eversdk/lib-node

Web

npm i --save @eversdk/lib-web

Important! Each time you run npm install the new version of the eversdk.wasm and index.js is downloaded. So you have to always update the eversdk.wasm inside your web package before publishing (starting local web server, creating web bundle etc.). If you use Webpack the best way is to use CopyPlugin.

React Native

npm i --save @eversdk/lib-react-native

Setup library

You must initialize the library before the first use. The best place to do it is an initialization code of your application.

You need to attach the chosen binary module to the TonClient class.

NodeJs:

const {TonClient} = require("@eversdk/core");
const {libNode} = require("@eversdk/lib-node");

// Application initialization

TonClient.useBinaryLibrary(libNode)

Web:

import {TonClient} from "@eversdk/core";
import {libWeb} from "@eversdk/lib-web";

// Application initialization

TonClient.useBinaryLibrary(libWeb);

By default the library loads wasm module from relative URL /eversdk.wasm.

You can specify alternative URL if you want to place (or rename) wasm module.

import {TonClient} from "@eversdk/core";
import {libWeb, libWebSetup} from "@eversdk/lib-web";

// Setup alternative URL for WASM module.
libWebSetup({
    binaryURL: "/assets/eversdk_1_30_1.wasm",
});

TonClient.useBinaryLibrary(libWeb);

By default, lib web starts a separate worker that will utilize core (wasm).

So main thread never freezes – it is fine for UI. But in some cases (e.g. when worker already exists in application or extension) separate worker is a bad approach.

In this case application can suppress separate worker with:

import {TonClient} from "@eversdk/core";
import {libWeb, libWebSetup} from "@eversdk/lib-web";

// Disable separate worker
libWebSetup({
    disableSeparateWorker: true,
});

TonClient.useBinaryLibrary(libWeb);

React Native (iOS/Android):

import {TonClient} from "@eversdk/core";
import {libReactNative} from "@eversdk/lib-react-native";

// Application initialization

TonClient.useBinaryLibrary(libReactNative);

React Native (Web):

If you use React Native in Web, work the same way as described in Web section (see above).

Use library

All library functions are incorporated into TonClient class. Each client module is represented as a property of the TonClient object.

To start use library you must create an instance of the TonClient class:

const client = new TonClient();
const keys = await client.crypto.generate_random_sign_keys();

You can pass a configuration object in TonClient constructor:

const client = new TonClient({
    network: { 
        endpoints: ['net.ton.dev']
    } 
});

In the end, close client to close all the sockets related to it:

 client.close();

You can find reference guide to TonClient here: EVER-SDK API Documentation

Build bridge binaries

You can build binaries from sources.

If you install a bridge package from the npmjs you can build it with the following commands (e.g. for nodejs):

cd node_modules/@eversdk/lib-node/build
cargo run

Build binaries

If you checkout this repository you can build binaries for all bridges.

cd packages/lib-node/build
cargo run
cd ../../lib-web/build
cargo run
cd ../../../lib-react-native/android/build
cargo run
cd ../../ios/build
cargo run

Also the archives will be created to be published on the TON Labs cloud storage. Archives will be placed into the following folders:

Run tests

This suite has test packages:

Preparation to run tests

You need to provide EVERCLOUD_AUTH_PROJECT environemnt variable. This is ProjectId. Take it from one of your project at https://dashboard.evercloud.dev/projects. (without secret / secret should be disabled)

cd packages/core
npm i
npx tsc
cd ../tests
npm i
npx tsc

Run tests on node js

cd packages/tests-node
npm i
node run

Run tests on web browser

cd packages/tests-web
npm i -f webpack
npm i -f webpack-cli
npm i -f
node run

Run tests on react native platform

cd packages/tests-react-native
npm i
node run ios
node run android

To control where your tests will run use this environments

TON_USE_SE=true TON_NETWORK_ADDRESS=http://localhost node run

Download precompiled binaries

Instead of building library yourself, you can download the latest precompiled binaries from TON Labs SDK Binaries Store.

BinaryTargetMajorDownload links
Node.js AddOnWin321eversdk.node
 macOS x86_641eversdk.node
 macOS aarch641eversdk.node
 Linux1eversdk.node
React Native ModuleAndroid x86_641libeversdk.so
 Android i6861libeversdk.so
 Android armv71libeversdk.so
 Android aarch641libeversdk.so
 iOS1libeversdk.a
WASM ModuleBrowser1eversdk.wasm, index.js

Downloaded archive is gzipped file


Copyright 2018-2020 TON Labs LTD.