Nocturnal Pumpkin Maelstrom

    @web3-systems/chainscan-client
    TypeScript icon, indicating that this package has built-in type declarations

    0.1.0-beta.2 • Public • Published

    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

    Keywords

    none

    Install

    npm i @web3-systems/chainscan-client

    DownloadsWeekly Downloads

    2

    Version

    0.1.0-beta.2

    License

    MIT

    Unpacked Size

    461 kB

    Total Files

    116

    Last publish

    Collaborators

    • sudokames
    • kamesdev