Skip to content
This repository has been archived by the owner on Jan 26, 2023. It is now read-only.

ton-community/ton

Repository files navigation

TON js client

Version npm

Cross-platform client for TON blockchain.

Features

  • 🚀 Create new wallets
  • 🍰 Get balance
  • ✈️ Transfers

Install

yarn add ton ton-crypto ton-core buffer

Browser polifil

// Add before using library
require("buffer");

Usage

To use this library you need HTTP API endpoint, you can use one of the public endpoints:

import { TonClient, WalletContractV4, internal } from "ton";
import { mnemonicNew, mnemonicToPrivateKey } from "ton-crypto";

// Create Client
const client = new TonClient({
  endpoint: 'https://toncenter.com/api/v2/jsonRPC',
});

// Generate new key
let mnemonics = await mnemonicNew();
let keyPair = await mnemonicToPrivateKey(mnemonics);

// Create wallet contract
let workchain = 0; // Usually you need a workchain 0
let wallet = WalletContractV4.create({ workchain, publicKey: keyPair.publicKey });
let contract = client.open(wallet);

// Get balance
let balance: bigint = await contract.getBalance();

// Create a transfer
let seqno: number = await contract.getSeqno();
let transfer = await contract.createTransfer({
  seqno,
  messages: [internal({
    value: '1.5',
    dest: 'EQCD39VS5jcptHL8vMjEXrzGaRcCVYto7HUn4bpAOg8xqB2N',
    body: 'Hello world'
  })]
});

Docs

Documentation

License

MIT