[](https://www.npmjs.com/package/ton)
npm install @ton/ton
Cross-platform client for TON blockchain.
- 🚀 Create new wallets
- 🍰 Get balance
- ✈️ Transfers
``bash`
yarn add @ton/ton @ton/crypto @ton/core buffer
#### Browser polyfill
`js`
// Add before using library
require("buffer");
To use this library you need HTTP API endpoint, you can use one of the public endpoints:
- Mainnet: https://toncenter.com/api/v2/jsonRPC
- Testnet: https://testnet.toncenter.com/api/v2/jsonRPC
`ts
import { TonClient, WalletContractV4, internal } from "@ton/ton";
import { mnemonicNew, mnemonicToPrivateKey } from "@ton/crypto";
// Create Client
const client = new TonClient({
endpoint: 'https://toncenter.com/api/v2/jsonRPC',
});
// Generate new key
const mnemonic = await mnemonicNew();
const keyPair = await mnemonicToPrivateKey(mnemonic);
// Create wallet contract
const wallet = WalletContractV4.create({
workchain: 0, // basechain
publicKey: keyPair.publicKey,
});
const contract = client.open(wallet);
// Get balance
const balance = await contract.getBalance();
// Create a transfer
const seqno = await contract.getSeqno();
const transfer = await contract.createTransfer({
seqno,
secretKey: keyPair.secretKey,
messages: [internal({
value: '1.5',
to: 'EQCD39VS5jcptHL8vMjEXrzGaRcCVYto7HUn4bpAOg8xqB2N',
body: 'Hello world',
})]
});
`
We use biome as our formatter. It's prettier compatible and fast
`sh`
yarn run format
By default tests are running using multiple worker threads. It's faster, but
undesirable during debugging. SINGLETHREADED env variable covers this case
`sh`
SINGLETHREADED=1 yarn run test
We use test coverage to eliminate blind spots in our tests.
#### How to?
The goal is to make all functions runned at least once
1. Build a coverage report
`sh`
yarn run coverage
2. Coverage report is build to the /coverage directory
3. Open /coverage/index.html` to check the report
This library is developed by the Whales Corp. and maintained by Dan Volkov.
MIT