ton
- library for Web, Node and React Native
Popular library for TON written in Typescript, well tested and used in production in a lot of projects.
Install
yarn add ton buffer
For browsers Buffer
is needed:
// Add before using libraryrequire("buffer");
Usage
To connect to blockchain you need HTTP API endpoint, you can use one of the public endpoints
import { TonClient } from "ton";// Create Clientconst client = new TonClient({ endpoint: 'https://toncenter.com/api/v2/jsonRPC',});// Open Walletconst wallet = await client.openWallet('<public-key>');console.log(wallet.address);console.log(await wallet.getBalance());// Transfering coinslet seqno = await wallet.getSeqNo();// In case of failure you can safely retry calling this methodawait wallet.transfer({ to: 'some-address', amount: 10.0, seqno, secretKey: '<secret>' });