Utilities

This package contains various utility methods to help you quickly bootstrap your blockchain-powered application.

There are many utility methods exported from the utils package. We'll present a few examples of the more commonly used utility and useful methods, but take a look at the entire API here.

Installation

Install the package in your project directory with:

npm install @augustdigital/utils

You can import individual methods and constants from the utilities package with the following:

import { <METHOD> } from '@augustdigital/utils';

or the CommonJS way:

const augustUtils from '@augustdigital/utils';

Interacting with Contracts

Simulate Transaction

To see the final result of a read or write smart contract method without writing to the blockchain.

async function simulateTransaction(
  infura: IInfuraOptions,
  abi: string[] | any,
  functionName: string,
  options?: {
    args?: (string | number | bigint)[][];
    from?: string;
    to?: string;
  },
): ContractResult<any>

Formatting

Normalize Value

Formats any number type to an object containing the string value as well as the big number value.

function toNormalizedBn(
  value: string | bigint | number,
  decimals: number = 18,
): INormalizedNumber {
  raw: bigint;
  normalized: string;
}

Datetime

UNIX Timestamp to Date

Formats number type to a Date to assist in displaying on your UI. Especially useful when working with our subgraphs.

function unixToDate(epoch: number): Date

Get Date X Days Ago

Quickly get new past date by inputting the amount of days from today.

export function daysAgo(days: number): Date

Last updated