Skip to content
/ tonweb Public
forked from toncenter/tonweb

JavaScript API for TON (Telegram Open Network)

License

Notifications You must be signed in to change notification settings

sekmet/tonweb

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TonWeb - JavaScript API for TON (Telegram Open Network)

NPM

TonWeb interface is close as possible to the web3.js.

TonWeb has only 3 external dependencies (BN.js, tweetnacl, ethjs-unit) and is not too big (~200kb).

Used by gram-wallet.org and gram-wallet plugin.

Install Web

npm install 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

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 Gram
    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);

Usage with NEWTON

const tonweb = new TonWeb(new TonWeb.HttpProvider('https://toncenter.com/api/newton_test/v2/jsonRPC'));

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, gram values, byte arrays, hex, hash functions.

Also we use JSDoc in code

Build

npm install 

npx webpack --mode=none

Authors

Emelyanenko Kirill, mail: [email protected]

Anatoliy Makosov, mail: [email protected]

About

JavaScript API for TON (Telegram Open Network)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 83.0%
  • HTML 17.0%