0.2.1 • Published 11 months ago

ton-node-kit v0.2.1

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

ton-node-kit

npm version

Useful utilities for working with TON in NodeJS

Install

npm install ton-node-kit

Usage

import { Address, TonClient } from '@ton/ton';
import type { Transaction } from '@ton/ton';

import {
  getTxComment,
  getTxSender,
  getTxValueAmount,
  withRetry,
  checkIsInternal,
} from 'ton-node-kit';

const myAddress = Address.parse('<your-wallet-address>');

const client = new TonClient({
  endpoint: 'https://testnet.toncenter.com/api/v2/jsonRPC',
  apiKey: process.env.TON_API_KEY,
});

const TRANSACTION_LIMIT = 1;
const RETRY_LIMIT = 30;
const RETRY_DELAY_MS = 100;

const getTransactions = async () => {
  return (await withRetry(
    () =>
      client.getTransactions(myAddress, {
        limit: TRANSACTION_LIMIT,
        archival: true,
      }),
    RETRY_LIMIT,
    RETRY_DELAY_MS,
  )) as Transaction[];
};

const transactions = await getTransactions();

for (const tx of transactions) {
  if (checkIsInternal(tx)) {
    const commentText = getTxComment(tx);
    const tonValue = getTxValueAmount(tx);
    const nanoValue = getTxValueAmount(tx, {
      currency: 'nano',
      returnBigint: true,
    });
    const sender = getTxSender(tx);
    const hexAddress = getTxSender(tx, { hex: true });

    console.log('Transaction', {
      commentText,
      tonValue,
      nanoValue,
      sender,
      hexAddress,
    });
  }

  // Transaction {
  //   commentText: 'Hello, TON!',
  //   nanoValue: 50000000n,
  //   tonValue: '0.05'
  //   sender: <sender-object>,
  //   hexAddress: '0:....'
  // }
}
0.2.1

11 months ago

0.2.0

11 months ago

0.1.0

11 months ago