Documentation Index
Fetch the complete documentation index at: https://ton.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
The source code can be found
here.
Install Web
npm install tonweb
# or
yarn add tonweb
import TonWeb from "tonweb";
const tonweb = new TonWeb();
or
<script src="tonweb.js"></script>
<script>
const tonweb = new window.TonWeb();
</script>
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.
Note: without the API key, request rate limits apply.
You can start your own TON HTTP API instance (it’s 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:
ℹ️ JSDoc is used throughout the codebase.
Roadmap
- Unit-tests
- TypeScript support
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 your_script.js:
const TonWeb = require('tonweb');
const tonweb = new TonWeb();
// Your code here...
Run the script: