# ton-inspector

> Easily find and confirm TON Blockchain transactions.

Latest version **1.0.2** (published 2023-02-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install ton-inspector
pnpm add ton-inspector
yarn add ton-inspector
bun add ton-inspector
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2023-02-07 |
| First published | 2023-02-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 8.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | kirillmelcin |
| Maintainers | kirillmelcin |
| Keywords | ton |

## Links

- npm: https://www.npmjs.com/package/ton-inspector
- Repository: https://github.com/kirillmelcin/ton-inspector
- Homepage: https://github.com/kirillmelcin/ton-inspector#readme
- Issues: https://github.com/kirillmelcin/ton-inspector/issues
- npm.io page: https://npm.io/package/ton-inspector

## Dependencies (1)

- [axios](https://npm.io/package/axios.md) ^1.3.2

## 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

- 1.0.2 (latest) — 2023-02-07
- 1.0.1 — 2023-02-07
- 1.0.0 — 2023-02-07

## README

# TON Inspector
Easily find and confirm TON Blockchain transactions.

- [Features](#-features)
- [Install](#-install)
- [Basic usage](#-basic-usage)
- [Available functions](#-available-functions)
- [Examples](#-examples)

## 🌻 Features
- Find transactions with (or without) specific message
- Generate random messages to indentify transactions
- Generate payment links

## 🔮 Install

```sh
npm i ton-inspector
```

## 💡 Basic usage
```javascript
const inspector = require('ton-inspector') 

inspector.setApiKey('<Place your api key here>')
const amount = inspector.convertTonToNano(1) // Converting to nanocoins is required
inspector.findTransaction('<TON wallet address>', amount, '<Message>')
  .then(wallet => console.log(wallet))  // returns the source wallet
  .catch(err => console.log(err))
```

## 🚀 Available functions

**setApiKey(_api_key_)**

Authorize requests to TON API with your own API key. This function must be used together with findTransaction()
| Parameter | Type | Required | Description |
| ------ | ------ | ------  | ------ |
| api_key | _String_ | yes | Sets the TON api key. Use the function before findTransaction() |

You can get your own TON API key using Telegram: [@tonapibot](https://t.me/tonapibot)

Example:
```javascript
inspector.setApiKey('<Place your api key here>')
// then you can use findTransaction()
```

**findTransaction(_destination, amount, message, retries_)**

This function is to find the last transaction sent to the _destination_ wallet with following _amount_ of TON Coins and _Message_. The function sends requests to blockchain every 2 second trying to find the transaction. Maximum number of _retries_ is limited.

| Parameter | Type | Required | Description |
| ------ | ------ | ------  | ------ |
| destination | _String_ | yes | TON wallet address |
| amount | _Integer_ | yes | Amount of TON Coins. _Notice:_ you must convert your amount to nanocoins before using the function. Use convertToNano(_amount_) for that |
| message | _String_ | no | Defines the message the transaction should be accompanied with |
| retries | _String_ | no | Number of retries (Default: 5, max: 20).  |

Example:
```javascript
const amount = inspector.convertTonToNano(10) // convert 10 TON to 10000000000 nanocoins
inspector.findTransaction('EQD3I34Ce9RpdNEpgoUB5dgWvywD4dSTVea4g2Da7eW-ETAK', amount, 'Z6W4J')
    .then(wallet => console.log(wallet)) // returns the wallet from where the transaction was sent
    .catch(err => console.log(err)) // returns an error if the transaction was not found
```

**convertTonToNano(_amount_)**

This function converts amount of TON coins into nanocoins.
For instance: 1.15 TON => 1150000000 nanocoins

| Parameter | Type | Required | Description |
| ------ | ------ | ------  | ------ |
| amount | _Integer_ or _float_ | yes | Amount of TON Coins |

Example:
```javascript
const amount = inspector.convertTonToNano(10)
console.log(amount) // 10000000000
```

**randomMsg(_length_)**

This function generates random message. You can use the message as an unique transaction identificator.
See examples for more info.

| Parameter | Type | Required | Description |
| ------ | ------ | ------  | ------ |
| length | _Integer_ | no | Length of the message (default: 5, min: 3, max: 10) |

Example:
```javascript
console.log(inspector.randomMsg()) // 7XL8Q
console.log(inspector.randomMsg(7)) // LF541AR
```

**generateLink(_destination, amount, message_)**

This function generates payment link. For example, you can use the link in QR code or in a payment button. Link opens up TON Coin wallet app (e.g. Tonkeeper, Tonhub) with pre-generated transaction.
See examples for more info.

| Parameter | Type | Required | Description |
| ------ | ------ | ------  | ------ |
| destination | _String_ | yes | TON wallet address |
| amount | _Integer_ | yes | Amount of TON Coins. _Notice:_ you must convert your amount to nanocoins before using the function. Use convertToNano(_amount_) for that |
| message | _String_ | no | Defines the message the transaction should be accompanied with |

Example:
```javascript
const wallet = 'EQD3I34Ce9RpdNEpgoUB5dgWvywD4dSTVea4g2Da7eW-ETAK' // destination wallet address
const amount = inspector.convertTonToNano(10) // convert 10 TON to 10000000000 nanocoins
const msg = inspector.randomMsg() // generates random message with default length: LZCZ9

const link = inspector.paymentLink(wallet, amount, msg)
console.log(link) // ton://transfer/EQD3I34Ce9RpdNEpgoUB5dgWvywD4dSTVea4g2Da7eW-ETAK?amount=10000000000&text=LZCZ9
```

## 📚 Examples

Coming soon

## License

MIT

## Contact

Feel free to give feedback, share ideas and report bugs.

Telegram: [@kirillmelcin](https://t.me/kirillmelcin)

Email: hi@kirillmelcin.ru

Wallet: EQD3I34Ce9RpdNEpgoUB5dgWvywD4dSTVea4g2Da7eW-ETAK

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