Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ton-node-kit

Package Overview
Dependencies
Maintainers
0
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ton-node-kit

Useful utilities for working with TON in NodeJS

  • 0.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-50%
Maintainers
0
Weekly downloads
 
Created
Source

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:....'
  // }
}

Keywords

FAQs

Package last updated on 05 Sep 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc