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

@web3-systems/chainscan-client

v0.1.0-beta.2

Published

A multichain Etherscan/Clone API client library.

Downloads

6

Readme

Chainscan Client

Build GPLv3 license

A multichain Etherscan/Clone API client library.

The @web3-systems/chainscan-client was designed to interface with multiple chainId explorer endpoints. That means support for Etherscan, Polygonscan and Snowtrace mainnet/testnet API service providers.

Current Supported Explorers

  • Etherscan (Ethereum)
    • Mainnet
    • Ropsten
    • Rinkeby
    • Goerli
    • Kovan
  • Polygonscan (Polygon)
    • Mainnet
    • Mumbai
  • Snowtrace (Avalanche)
    • Mainnet
    • Fuji

Installation

Install NPM package:

npm install @web3-systems/chainscan-client
yarn add @web3-systems/chainscan-client

Clone from Github:

git clone https://github.com/web3-systems/chainscan-client

Getting Started

The chainscan-client library is built to support multiple Etherscan/Clonescan service API providers.

A Chainscan client will handle keys and multiple clients, so developers can access Etherscan, Polygonscan and Avalanche with a single instance.

A new ChainscanClient is initialized with defaultChainId and apikey. All chains supported by that provider (e.x. 1,3,4,5) are now available using the single API key passed as the default for Etherscan.

To connect to a new service API provider a new API key must be supplied to the client instance - along with a chainId or provider name.

Initialize

Chain IDs are mapped to service provider(s).

If chainId 1,2,3,4,5,42 is passed Etherscan is the default client.

If chainId 137,8001 is passed Polygonscan is the default client.

If chainId 43114,43114 is passed Snowtrace is the default client.

import { ChainscanClient } from '@web3-systems/chainscan-client';

const client = new ChainscanClient(1, 'etherscan-apikey');

Multiple Connections

import { ChainscanClient } from '@web3-systems/chainscan-client';

let client: ChainscanClient;

// Set API key and default client for all Etherscan API endpoints: 1,2,3,3,5
client = new ChainscanClient(1, 'etherscan-apikey');

// Sets API key for all Polygoncanscan API endpoints: 137, 80001
client.setApiKey(137, 'polygonscan-apikey');

// Get Account Balance from default ChainscanClient
const balanceEthereum = await client.getAccountBalance('0x000...000');

// Get Account Balance using optional chainId parameter
const balancePolygon = await client.getAccountBalance('0x000...000', 137);
const balanceMumbai = await client.getAccountBalance('0x000...000', 80001);

Class: ChainscanClient

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new ChainscanClient(chainId, apiKey)

Parameters

| Name | Type | | :------ | :------ | | chainId | number | | apiKey | string |

Defined in

ChainscanClient.ts:48

Properties

chainIdDefault

chainIdDefault: number = 1

Defined in

ChainscanClient.ts:44


clients

Readonly clients: Clients = {}

Defined in

ChainscanClient.ts:46


keys

Readonly keys: ApiKeys = {}

Defined in

ChainscanClient.ts:45

Methods

client

client(chainId, apiKey): AxiosInstance

Parameters

| Name | Type | | :------ | :------ | | chainId | number | | apiKey | string |

Returns

AxiosInstance

Defined in

ChainscanClient.ts:60


connect

connect(chainId, apiKey?): AxiosInstance

Parameters

| Name | Type | | :------ | :------ | | chainId | number | | apiKey? | string |

Returns

AxiosInstance

Defined in

ChainscanClient.ts:65


getAccountBalance

getAccountBalance(address, chainId?): Promise<any>

Parameters

| Name | Type | | :------ | :------ | | address | string | | chainId? | number |

Returns

Promise<any>

Defined in

ChainscanClient.ts:96


getAccountBalanceMulti

getAccountBalanceMulti(addressList, chainId?): Promise<any>

Parameters

| Name | Type | | :------ | :------ | | addressList | string[] | | chainId? | number |

Returns

Promise<any>

Defined in

ChainscanClient.ts:101


getAccountERC20TransferEvents

getAccountERC20TransferEvents(contract, address, config, chainId?): Promise<any>

Parameters

| Name | Type | | :------ | :------ | | contract | string | | address | string | | config | BlockPagination | | chainId? | number |

Returns

Promise<any>

Defined in

ChainscanClient.ts:144


getAccountERC721TransferEvents

getAccountERC721TransferEvents(contract, address, config, chainId?): Promise<any>

Parameters

| Name | Type | | :------ | :------ | | contract | string | | address | string | | config | BlockPagination | | chainId? | number |

Returns

Promise<any>

Defined in

ChainscanClient.ts:154


getAccountMinedBlocks

getAccountMinedBlocks(address, config, chainId?): Promise<any>

Parameters

| Name | Type | | :------ | :------ | | address | string | | config | AccountMinedBlocksConfig | | chainId? | number |

Returns

Promise<any>

Defined in

ChainscanClient.ts:164


getAccountTransactions

getAccountTransactions(address, config, chainId?): Promise<void>

Parameters

| Name | Type | | :------ | :------ | | address | string | | config | BlockPagination | | chainId? | number |

Returns

Promise<void>

Defined in

ChainscanClient.ts:106


getAccountTransactionsInternal

getAccountTransactionsInternal(address, config, chainId?): Promise<any>

Parameters

| Name | Type | | :------ | :------ | | address | string | | config | BlockPagination | | chainId? | number |

Returns

Promise<any>

Defined in

ChainscanClient.ts:115


getAccountTransactionsInternalByBlockRange

getAccountTransactionsInternalByBlockRange(startblock, endblock, config, chainId?): Promise<any>

Parameters

| Name | Type | | :------ | :------ | | startblock | string | | endblock | string | | config | BlockPagination | | chainId? | number |

Returns

Promise<any>

Defined in

ChainscanClient.ts:129


getAccountTransactionsInternalByHash

getAccountTransactionsInternalByHash(txhash, chainId?): Promise<any>

Parameters

| Name | Type | | :------ | :------ | | txhash | string | | chainId? | number |

Returns

Promise<any>

Defined in

ChainscanClient.ts:124


getBlockCountdown

getBlockCountdown(blockno, chainId?): Promise<any>

Parameters

| Name | Type | | :------ | :------ | | blockno | string | | chainId? | number |

Returns

Promise<any>

Defined in

ChainscanClient.ts:177


getBlockDailyAvgBlockSize

getBlockDailyAvgBlockSize(startdate, enddate, sort?, chainId?): Promise<any>

Parameters

| Name | Type | Default value | | :------ | :------ | :------ | | startdate | string | undefined | | enddate | string | undefined | | sort | "asc" | "desc" | 'asc' | | chainId? | number | undefined |

Returns

Promise<any>

Defined in

ChainscanClient.ts:182


getBlockFromTimestamp

getBlockFromTimestamp(timestamp, closest, chainId?): Promise<any>

Parameters

| Name | Type | | :------ | :------ | | timestamp | string | | closest | "before" | "after" | | chainId? | number |

Returns

Promise<any>

Defined in

ChainscanClient.ts:192


getBlockReward

getBlockReward(blockno, chainId?): Promise<any>

Parameters

| Name | Type | | :------ | :------ | | blockno | string | | chainId? | number |

Returns

Promise<any>

Defined in

ChainscanClient.ts:201


getContractAbi

getContractAbi(address, chainId?): Promise<any>

Parameters

| Name | Type | | :------ | :------ | | address | string | | chainId? | number |

Returns

Promise<any>

Defined in

ChainscanClient.ts:210


getContractSourceCode

getContractSourceCode(address, chainId?): Promise<any>

Parameters

| Name | Type | | :------ | :------ | | address | string | | chainId? | number |

Returns

Promise<any>

Defined in

ChainscanClient.ts:215


getLogs

getLogs(address, config, chainId?): Promise<any>

Parameters

| Name | Type | | :------ | :------ | | address | string | | config | LogsGetConfig | | chainId? | number |

Returns

Promise<any>

Defined in

ChainscanClient.ts:224


getStatsTokenSupply

getStatsTokenSupply(contractaddress, chainId?): Promise<any>

Parameters

| Name | Type | | :------ | :------ | | contractaddress | string | | chainId? | number |

Returns

Promise<any>

Defined in

ChainscanClient.ts:233


getTransactionReceiptStatus

getTransactionReceiptStatus(address, chainId?): Promise<any>

Parameters

| Name | Type | | :------ | :------ | | address | string | | chainId? | number |

Returns

Promise<any>

Defined in

ChainscanClient.ts:242


getTransactionStatus

getTransactionStatus(address, chainId?): Promise<any>

Parameters

| Name | Type | | :------ | :------ | | address | string | | chainId? | number |

Returns

Promise<any>

Defined in

ChainscanClient.ts:247


setApiKey

setApiKey(chainId, apiKey): void

Parameters

| Name | Type | | :------ | :------ | | chainId | number | | apiKey | string |

Returns

void

Defined in

ChainscanClient.ts:77


setApiKeyByServiceProvider

setApiKeyByServiceProvider(serviceProvider, apiKey): void

Parameters

| Name | Type | | :------ | :------ | | serviceProvider | string | | apiKey | string |

Returns

void

Defined in

ChainscanClient.ts:82


setChainId

setChainId(chainId): void

Parameters

| Name | Type | | :------ | :------ | | chainId | number |

Returns

void

Defined in

ChainscanClient.ts:88