@web3-systems/chainscan-client v0.1.0-beta.2
Chainscan Client
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-clientyarn add @web3-systems/chainscan-clientClone from Github:
git clone https://github.com/web3-systems/chainscan-clientGetting 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
- client
- connect
- getAccountBalance
- getAccountBalanceMulti
- getAccountERC20TransferEvents
- getAccountERC721TransferEvents
- getAccountMinedBlocks
- getAccountTransactions
- getAccountTransactionsInternal
- getAccountTransactionsInternalByBlockRange
- getAccountTransactionsInternalByHash
- getBlockCountdown
- getBlockDailyAvgBlockSize
- getBlockFromTimestamp
- getBlockReward
- getContractAbi
- getContractSourceCode
- getLogs
- getStatsTokenSupply
- getTransactionReceiptStatus
- getTransactionStatus
- setApiKey
- setApiKeyByServiceProvider
- setChainId
Constructors
constructor
• new ChainscanClient(chainId, apiKey)
Parameters
| Name | Type |
|---|---|
chainId | number |
apiKey | string |
Defined in
Properties
chainIdDefault
• chainIdDefault: number = 1
Defined in
clients
• Readonly clients: Clients = {}
Defined in
keys
• Readonly keys: ApiKeys = {}
Defined in
Methods
client
▸ client(chainId, apiKey): AxiosInstance
Parameters
| Name | Type |
|---|---|
chainId | number |
apiKey | string |
Returns
AxiosInstance
Defined in
connect
▸ connect(chainId, apiKey?): AxiosInstance
Parameters
| Name | Type |
|---|---|
chainId | number |
apiKey? | string |
Returns
AxiosInstance
Defined in
getAccountBalance
▸ getAccountBalance(address, chainId?): Promise<any>
Parameters
| Name | Type |
|---|---|
address | string |
chainId? | number |
Returns
Promise<any>
Defined in
getAccountBalanceMulti
▸ getAccountBalanceMulti(addressList, chainId?): Promise<any>
Parameters
| Name | Type |
|---|---|
addressList | string[] |
chainId? | number |
Returns
Promise<any>
Defined in
getAccountERC20TransferEvents
▸ getAccountERC20TransferEvents(contract, address, config, chainId?): Promise<any>
Parameters
| Name | Type |
|---|---|
contract | string |
address | string |
config | BlockPagination |
chainId? | number |
Returns
Promise<any>
Defined in
getAccountERC721TransferEvents
▸ getAccountERC721TransferEvents(contract, address, config, chainId?): Promise<any>
Parameters
| Name | Type |
|---|---|
contract | string |
address | string |
config | BlockPagination |
chainId? | number |
Returns
Promise<any>
Defined in
getAccountMinedBlocks
▸ getAccountMinedBlocks(address, config, chainId?): Promise<any>
Parameters
| Name | Type |
|---|---|
address | string |
config | AccountMinedBlocksConfig |
chainId? | number |
Returns
Promise<any>
Defined in
getAccountTransactions
▸ getAccountTransactions(address, config, chainId?): Promise<void>
Parameters
| Name | Type |
|---|---|
address | string |
config | BlockPagination |
chainId? | number |
Returns
Promise<void>
Defined in
getAccountTransactionsInternal
▸ getAccountTransactionsInternal(address, config, chainId?): Promise<any>
Parameters
| Name | Type |
|---|---|
address | string |
config | BlockPagination |
chainId? | number |
Returns
Promise<any>
Defined in
getAccountTransactionsInternalByBlockRange
▸ getAccountTransactionsInternalByBlockRange(startblock, endblock, config, chainId?): Promise<any>
Parameters
| Name | Type |
|---|---|
startblock | string |
endblock | string |
config | BlockPagination |
chainId? | number |
Returns
Promise<any>
Defined in
getAccountTransactionsInternalByHash
▸ getAccountTransactionsInternalByHash(txhash, chainId?): Promise<any>
Parameters
| Name | Type |
|---|---|
txhash | string |
chainId? | number |
Returns
Promise<any>
Defined in
getBlockCountdown
▸ getBlockCountdown(blockno, chainId?): Promise<any>
Parameters
| Name | Type |
|---|---|
blockno | string |
chainId? | number |
Returns
Promise<any>
Defined in
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
getBlockFromTimestamp
▸ getBlockFromTimestamp(timestamp, closest, chainId?): Promise<any>
Parameters
| Name | Type |
|---|---|
timestamp | string |
closest | "before" | "after" |
chainId? | number |
Returns
Promise<any>
Defined in
getBlockReward
▸ getBlockReward(blockno, chainId?): Promise<any>
Parameters
| Name | Type |
|---|---|
blockno | string |
chainId? | number |
Returns
Promise<any>
Defined in
getContractAbi
▸ getContractAbi(address, chainId?): Promise<any>
Parameters
| Name | Type |
|---|---|
address | string |
chainId? | number |
Returns
Promise<any>
Defined in
getContractSourceCode
▸ getContractSourceCode(address, chainId?): Promise<any>
Parameters
| Name | Type |
|---|---|
address | string |
chainId? | number |
Returns
Promise<any>
Defined in
getLogs
▸ getLogs(address, config, chainId?): Promise<any>
Parameters
| Name | Type |
|---|---|
address | string |
config | LogsGetConfig |
chainId? | number |
Returns
Promise<any>
Defined in
getStatsTokenSupply
▸ getStatsTokenSupply(contractaddress, chainId?): Promise<any>
Parameters
| Name | Type |
|---|---|
contractaddress | string |
chainId? | number |
Returns
Promise<any>
Defined in
getTransactionReceiptStatus
▸ getTransactionReceiptStatus(address, chainId?): Promise<any>
Parameters
| Name | Type |
|---|---|
address | string |
chainId? | number |
Returns
Promise<any>
Defined in
getTransactionStatus
▸ getTransactionStatus(address, chainId?): Promise<any>
Parameters
| Name | Type |
|---|---|
address | string |
chainId? | number |
Returns
Promise<any>
Defined in
setApiKey
▸ setApiKey(chainId, apiKey): void
Parameters
| Name | Type |
|---|---|
chainId | number |
apiKey | string |
Returns
void
Defined in
setApiKeyByServiceProvider
▸ setApiKeyByServiceProvider(serviceProvider, apiKey): void
Parameters
| Name | Type |
|---|---|
serviceProvider | string |
apiKey | string |
Returns
void
Defined in
setChainId
▸ setChainId(chainId): void
Parameters
| Name | Type |
|---|---|
chainId | number |
Returns
void
Defined in
4 years ago
4 years ago