Git Product home page Git Product logo

tonweb's Introduction

splash_js_sdk

TonWeb - JavaScript SDK for The Open Network

NPM

Install Web

npm install tonweb or yarn add tonweb

import TonWeb from "tonweb";

const tonweb = new TonWeb();

or

<script src="tonweb.js"></script>

const tonweb = new window.TonWeb();

Install NodeJS

npm install tonweb or yarn add tonweb

const TonWeb = require('tonweb');

const tonweb = new TonWeb();

Overview example

const tonweb = new TonWeb();

const wallet = tonweb.wallet.create({publicKey});

const address = await wallet.getAddress();

const nonBounceableAddress = address.toString(true, true, false);

const seqno = await wallet.methods.seqno().call();

await wallet.deploy(secretKey).send(); // deploy wallet to blockchain

const fee = await wallet.methods.transfer({
    secretKey,
    toAddress: 'EQDjVXa_oltdBP64Nc__p397xLCvGm2IcZ1ba7anSW0NAkeP',
    amount: TonWeb.utils.toNano(0.01), // 0.01 TON
    seqno: seqno,
    payload: 'Hello',
    sendMode: 3,
}).estimateFee();

const Cell = TonWeb.boc.Cell;
const cell = new Cell();
cell.bits.writeUint(0, 32);
cell.bits.writeAddress(address);
cell.bits.writeGrams(1);
console.log(cell.print()); // print cell data like Fift
const bocBytes = cell.toBoc();

const history = await tonweb.getTransactions(address);

const balance = await tonweb.getBalance(address);

tonweb.sendBoc(bocBytes);

API

By default, mainnet toncenter.com API is used. Please note that without the API key there will be a request rate limit.

You can start your own TON HTTP API instance as it is open source.

Use mainnet TonCenter API with high ratelimit API key:

const tonweb = new TonWeb(new TonWeb.HttpProvider('https://toncenter.com/api/v2/jsonRPC', {apiKey: 'YOUR_MAINNET_TONCENTER_API_KEY'}));

Use testnet TonCenter API with high ratelimit API key:

const tonweb = new TonWeb(new TonWeb.HttpProvider('https://testnet.toncenter.com/api/v2/jsonRPC', {apiKey: 'YOUR_TESTNET_TONCENTER_API_KEY'}));

Documentation

Each part is documented separately:

tonweb - root class and methods

tonweb-contract-wallet - interaction with wallet's smart contracts.

tonweb-contract - abstract interface to interact with TON smart contracts.

tonweb-boc - serializations of Cell and BitString

tonweb-utils - work with TON Addresses, coin values, byte arrays, hex, hash functions.

Also we use JSDoc in code

Roadmap

  1. Unit-tests

  2. Typescript

Build

npm install 

npm run build

Use as alternative to Fift for building binary messages to smart-contracts

npm install -g tonweb

export NODE_PATH=$(npm root --quiet -g)

Then create your_script.js

const TonWeb = require('tonweb');

const tonweb = new TonWeb();

. . .

run script

node your_script.js

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.