# tonweb

> TonWeb - JavaScript API for TON blockchain

Latest version **0.0.66** (published 2024-03-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install tonweb
pnpm add tonweb
yarn add tonweb
bun add tonweb
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.66 |
| Published | 2024-03-28 |
| First published | 2020-03-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 8 |
| Unpacked size | 951.7 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 766 |
| Maintainers | tolyayanot, rulon |
| Keywords | TON, Blockchain, API |

## Links

- npm: https://www.npmjs.com/package/tonweb
- Repository: https://github.com/toncenter/tonweb
- Homepage: https://github.com/toncenter/tonweb#readme
- Issues: https://github.com/toncenter/tonweb/issues
- npm.io page: https://npm.io/package/tonweb

## Dependencies (8)

- [bn.js](https://npm.io/package/bn.js.md) 5.1.1
- [tweetnacl](https://npm.io/package/tweetnacl.md) 1.0.3
- [ethjs-unit](https://npm.io/package/ethjs-unit.md) 0.1.6
- [node-fetch](https://npm.io/package/node-fetch.md) 2.6.7
- [isomorphic-webcrypto](https://npm.io/package/isomorphic-webcrypto.md) 2.3.8
- [@ledgerhq/hw-transport-webhid](https://npm.io/package/@ledgerhq/hw-transport-webhid.md) 5.48.0
- [@ledgerhq/hw-transport-webusb](https://npm.io/package/@ledgerhq/hw-transport-webusb.md) 5.48.0
- [@ledgerhq/hw-transport-web-ble](https://npm.io/package/@ledgerhq/hw-transport-web-ble.md) 5.48.0

## Alternatives

- [cli-color](https://npm.io/package/cli-color.md) — 3.4M weekly downloads
- [log](https://npm.io/package/log.md) — 1.3M weekly downloads
- [logstash-client](https://npm.io/package/logstash-client.md) — 4.5K weekly downloads
- [@nocobase/plugin-logger](https://npm.io/package/@nocobase/plugin-logger.md) — 2.0K weekly downloads
- [child-process-debug](https://npm.io/package/child-process-debug.md) — 695 weekly downloads

## Recent versions

- 0.0.66 (latest) — 2024-03-28
- 0.0.65 — 2024-03-28
- 0.0.64 — 2024-03-01
- 0.0.63 — 2024-02-18
- 0.0.62 — 2023-08-09
- 0.0.60 — 2023-02-16
- 0.0.59 — 2022-12-29
- 0.0.58 — 2022-10-30
- 0.0.57 — 2022-10-11
- 0.0.56 — 2022-10-03
- 0.0.55 — 2022-09-30
- 0.0.54 — 2022-08-05
- 0.0.53 — 2022-08-03
- 0.0.52 — 2022-07-29
- 0.0.50 — 2022-07-01
- … 42 more at https://npm.io/package/tonweb/versions

## README

![splash_js_sdk](https://user-images.githubusercontent.com/1449561/154848382-e89fef68-3aee-4ca6-8d52-1466bfdf2c89.png)

# TonWeb - JavaScript SDK for [The Open Network](https://ton.org)

[![NPM](https://img.shields.io/npm/v/tonweb.svg)](https://www.npmjs.org/package/tonweb)

## Install Web

`npm install tonweb` or `yarn add tonweb`

```js
import TonWeb from "tonweb";

const tonweb = new TonWeb();
```

or

`<script src="tonweb.js"></script>`

`const tonweb = new window.TonWeb();`

## Install NodeJS

`npm install tonweb` or `yarn add tonweb`

```js
const TonWeb = require('tonweb');

const tonweb = new TonWeb();
```

## Overview example

```js
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](https://toncenter.com) API is used. Please note that without the API key there will be a request rate limit.

You can start your own TON HTTP API instance as it is [open source](https://github.com/toncenter/ton-http-api).

Use mainnet TonCenter API with high ratelimit API key:

```js
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:

```js
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:

[tonweb](https://github.com/toncenter/tonweb/blob/master/src/README.md) - root class and methods

[tonweb-contract-wallet](https://github.com/toncenter/tonweb/blob/master/src/contract/wallet/README.md) - interaction with wallet's smart contracts.

[tonweb-contract](https://github.com/toncenter/tonweb/blob/master/src/contract/README.md) - abstract interface to interact with TON smart contracts.

[tonweb-boc](https://github.com/toncenter/tonweb/blob/master/src/boc/README.md) - serializations of Cell and BitString

[tonweb-utils](https://github.com/toncenter/tonweb/blob/master/src/utils/README.md) - work with TON Addresses, coin values, byte arrays, hex, hash functions.


**Also we use JSDoc in code**

## Roadmap

1. Unit-tests

2. Typescript

## Build

```bash
npm install 

npm run build
```

## Use as alternative to Fift for building binary messages to smart-contracts

```bash
npm install -g tonweb

export NODE_PATH=$(npm root --quiet -g)
```

Then create your_script.js

```js
const TonWeb = require('tonweb');

const tonweb = new TonWeb();

. . .

```

run script

```bash
node your_script.js
```

---
_Source: https://npm.io/package/tonweb · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
