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 🙏

© 2025 – Pkg Stats / Ryan Hefner

ts-etherscan

v1.0.3

Published

A Typescript Etherscan wrapper for their V2 API.

Downloads

42

Readme

Etherscan Client for TypeScript

A partially-still-in-progress-featured TypeScript client for interacting with the Etherscan API. This library provides easy access to transaction details, token transfers, gas tracking, and more.


Current Features

  • Transaction History: Fetch normal and internal transactions.
  • Token Transfers: Query ERC20 and ERC721 transfers.
  • Balances: Get balance for single or multiple accounts.
  • Gas Tracking: Retrieve gas prices, historical gas data, and confirmation times.
  • TypeScript Support: Fully typed API responses and utilities.

Installation

Install the package via npm:

npm install ts-etherscan@1.0.3

Usage

Examples

  1. Fetch Transaction List

Description:

This example fetches the first 100 normal transactions for the provided Ethereum address, starting from block 0 to the latest block, sorted in ascending order.

import { EtherscanClient } from "ts-etherscan";

const etherscan = new EtherscanClient({ apiKey: "YOUR_ETHERSCAN_API_KEY" });

(async () => {
  const address = "0xYourEthereumAddress";

  const transactions = await etherscan.getTransactionList(address, 0, 99999999, 1, 100, "asc");
  console.log("Transactions:", transactions);
})();
  1. Fetch Internal Transactions

Description: Internal transactions are interactions between smart contracts. This example fetches up to 100 internal transactions for the given address.

import { EtherscanClient } from "ts-etherscan";

const etherscan = new EtherscanClient({ apiKey: "YOUR_ETHERSCAN_API_KEY" });

(async () => {
  const address = "0xYourEthereumAddress";

  const internalTransactions = await etherscan.getInternalTransactions(address, 0, 99999999, 1, 100, "asc");
  console.log("Internal Transactions:", internalTransactions);
})();
  1. Fetch ERC20 Token Transfers

Description: This fetches all ERC20 token transfers associated with the given address. You can optionally filter by a specific contract address.

import { EtherscanClient } from "ts-etherscan";

const etherscan = new EtherscanClient({ apiKey: "YOUR_ETHERSCAN_API_KEY" });

(async () => {
  const address = "0xYourEthereumAddress";

  const tokenTransfers = await etherscan.getERC20Transfers(address);
  console.log("ERC20 Transfers:", tokenTransfers);
})();
  1. Get Gas Oracle

Description: The getGasOracle method retrieves current gas prices (in Gwei) for low, medium, and high transaction priorities.

import { EtherscanClient } from "ts-etherscan";

const etherscan = new EtherscanClient({ apiKey: "YOUR_ETHERSCAN_API_KEY" });

(async () => {
  const gasPrices = await etherscan.getGasOracle();
  console.log("Gas Prices:", gasPrices);
})();
  1. Estimate Confirmation Time

Description: This example estimates the time (in seconds) it would take for a transaction to confirm at a gas price of 50 Gwei.

import { EtherscanClient } from "ts-etherscan";

const etherscan = new EtherscanClient({ apiKey: "YOUR_ETHERSCAN_API_KEY" });

(async () => {
  const gasPrice = 50; // Gas price in Gwei
  const confirmationTime = await etherscan.getEstimatedConfirmationTime(gasPrice);
  console.log(`Estimated Confirmation Time: ${confirmationTime} seconds`);
})();
  1. Fetch Wallet Balance

Description: This fetches the balance for the provided Ethereum address, returning the value in Wei.

import { EtherscanClient } from "ts-etherscan";

const etherscan = new EtherscanClient({ apiKey: "YOUR_ETHERSCAN_API_KEY" });

(async () => {
  const address = "0xYourEthereumAddress";

  const balanceInWei = await etherscan.getBalance(address);
  console.log("Balance (in Wei):", balanceInWei);
})();
  1. Fetch Historical Gas Price

Description: This example retrieves the average gas price for a specific date. The date must be in the YYYY-MM-DD format.

import { EtherscanClient } from "ts-etherscan";

const etherscan = new EtherscanClient({ apiKey: "YOUR_ETHERSCAN_API_KEY" });

(async () => {
  const date = "2024-01-01"; // Date in YYYY-MM-DD format

  const historicalGasPrice = await etherscan.getHistoricalGasPrice(date);
  console.log(`Average Gas Price on ${date}:`, historicalGasPrice);
})();
  1. Calculate Gas Spent

Description: This example calculates the total gas spent for two successful transactions, converting the result from Wei to Ether for easier readability.

import { calculateGasSpentWei, weiToEther } from "ts-etherscan/utils";

const transactions = [
  { gasUsed: BigInt(21000), gasPrice: BigInt(50), isError: "0" },
  { gasUsed: BigInt(50000), gasPrice: BigInt(100), isError: "0" },
];

const totalGasSpentWei = calculateGasSpentWei(transactions);
const totalGasSpentEther = weiToEther(totalGasSpentWei);

console.log(`Total Gas Spent: ${totalGasSpentEther} Ether`);