npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@henchtab/shrek

v0.1.3

Published

Ogres are like onions, and testing your smart contracts on the TON blockchain is no different!

Downloads

11

Readme

Shrek's Logger

The Logger class is a utility for logging information about contracts and transactions within a blockchain environment. It provides functionalities to label contracts, retrieve balances, and format transactions for easy readability.

Table of Contents

  1. Installation
  2. Usage
  3. Helper Functions

Installation

Before using the Logger class, ensure you have the required dependencies installed:

npm install @henchtab/shrek

Usage

Initialization

First, import the required modules and initialize the Logger class:

import { Blockchain } from "@ton/core";
import { Logger } from "@henchtab/shrek";

// Initialize the blockchain object (assuming it is already configured)
const blockchain = new Blockchain(/* configuration */);

// Initialize the Logger
const logger = new Logger(blockchain);

Adding Contract Labels

You can add labels to contracts for easy identification. This is useful when you want to refer to contracts by human-readable names rather than their addresses.

// Add a label to a contract
const contractAddress = "kQ..."; // Replace with actual address
logger.addContract(contractAddress, "MyContractLabel");

Retrieving Contract Labels

To retrieve the label associated with a contract, use the getContractLabel method:

const address = Address.parse("kQ..."); // Replace with actual address
const label = logger.getContractLabel(address);
console.log(label); // Output: MyContractLabel or shortened address

Getting Contract Balances

Retrieve the balance of a contract using the getContractBalance method:

const address = Address.parse("kQ..."); // Replace with actual address.
logger.getContractBalance(address).then((balance) => {
  console.log(`Balance: ${balance}`);
}).catch((error) => {
  console.error("Error fetching contract balance:", error);
});

Logging Contract Balances

To log all contract balances with their associated labels:

logger.logContracts().then(() => { // https://github.com/henchtab/shrek/blob/main/example/tests/Counter.spec.ts#L112
  console.log("Contract balances logged.");
});

Logging Transactions

To log transactions in a readable format:

const transactions = [/* Array of transactions */]; // https://github.com/henchtab/shrek/blob/main/example/tests/Counter.spec.ts#L35
logger.logTransactions(transactions, "Transaction log:").then(() => {
  console.log("Transactions logged.");
});

Helper Functions

The Logger class includes several helper functions to assist with common tasks:

  • shortenString(str: string): string

    • Shortens a string to the first and last 4 characters, separated by ellipses.
  • pow10(n: number): bigint

    • Calculates 10 raised to the power of n.
  • formatCoins(value: bigint | undefined | null, precision = 6): string

    • Formats a coin value to a readable string with a specified precision. Handles undefined or null values by returning "∞".

Example:

import { formatCoins, shortenString } from "@henchtab/shreak";

const longString = "1234567890abcdef";
console.log(shortenString(longString)); // Output: 1234...cdef

const coinValue = 123456789n;
console.log(formatCoins(coinValue)); // Output: 123.456789 (depending on precision)