TON Javascript Web SDK
Community links:
Documentation
GraphQL API and SDK documentation
The JavaScript SDK implements the client-side libraries used by applications working with TON OS GraphQL API.
This package supports web (browser), mobile-web, and server (Node.js) clients.
Common Javascript SDK is distributed via npm package.
Attention! Because the JS library uses pre-compiled core sdk rust library, you need to install it via platform-dependable web package that will automatically install common js package + download and link pre-compiled rust core to your project:
npm install ton-client-web-js
To get started using TON Javascript SDK, see Add SDK to your Application.
ton-client-web-js
Using Requirements
You can run ton-client-web-js
in a browser.
In this example, we'll use webpack to manage assets. Since it requires Node.js, you’ll need to install the latest version.
Let's start with a clean webpack project:
mkdir HelloTonClientcd HelloTonClientnpm init -ynpm install webpack webpack-cli --save-dev
Now create the starting files in the root directory of the project:
|- /src
|- index.js
|- /dist
|- index.html
Here, the src
file contains our source code for further webpack usage, and dist
contains files that are directly served to the browser.
Next, create dist/index.html
in your directory. It will act as the browser entry point:
Example
Webpack will later use src
to generate main.js
.
Use npm to install ton-client-web-js
package:
npm install ton-client-web-js
To copy tonclient.wasm
from node_modules\ton-client-web-js
use copy-webpack-plugin
in webpack.config.js
.
Install copy-webpack-plugin
npm install copy-webpack-plugin --save-dev
Next, create webpack.config.js
in your directory
const CopyPlugin = ; moduleexports = mode: 'development' plugins: patterns: from: './node_modules/ton-client-web-js/tonclient.wasm' ;
Finally, add the code below to src/index.js
:
; { documentbody;} window;
To finish the example, let's build a dist/main.js
from our source:
npx webpack
To check if it works we'll need a simple HTTP server:
npm install light-server
Now you can run your app:
npx light-server -s dist
Doing so will show you the links to the app within the browser. Open your browser and take a look at your first app! Hit CTRL-C to stop the server.
See https://docs.ton.dev/86757ecb2/p/92b041-overview for documentation
Copyright 2018-2020 TON DEV SOLUTIONS LTD.