2.17.4 • Published 5 months ago

routescan-client v2.17.4

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

https://routescan.io/ Routescan/Etherscan client

routescan-client

Client for receiving blockchain data through block explorers (etherscan, routescan, etc.).
At the moment, the number of available methods is limited to those indicated in the examples below:

Donation

To support this project, you can send crypto to:

  • 0x3F2f0098310e654040f7794AB7E44Ac48E0eaF7B
  • TLPh66vQ2QMb64rG3WEBV5qnAhefh2kcdw

Accounts section

import { BlockExplorerCommon, BlockExplorerTag, BlockExplorerTopicOperation, Chain, BlockExplorerSort } from 'routescan-client';

const ROUTESCAN_API_KEY = 'YourApiKey';
const WALLET = '0x285f5F8Cd290Cff6596337C4eEC14e1a62235854';

async function main() {
  const blockExplorer = BlockExplorerCommon.build({
    chain: Chain.AvalancheCChainFuji,
    apiKey: ROUTESCAN_API_KEY
  });

  // Get AVAX balance for a single address:
  const balance = await blockExplorer.getAccountBalance({
    address: WALLET,
    tag: BlockExplorerTag.Latest
  });
  console.log(`Balance of ${WALLET} is ${balance}`);

  // Get AVAX balance for multiple addresses in a single call:
  const WALLET_SECOND = '0xCD5B8Ea4a848b1c576125f20F9aDe5F58FDf4D4f';
  const balances = await blockExplorer.getAccountsBalances({
    address: [WALLET, WALLET_SECOND].join(','),
    tag: BlockExplorerTag.Latest
  });
  console.log(balances);

  // Get a list of 'Normal' Transactions By Address
  const normalTxs = await blockExplorer.getNormalTxListByAddress({
    address: WALLET
  });
  console.log(normalTxs);

  // Get a list of 'internal' transactions by address:
  const internalTxs = await blockExplorer.getInternalTxListByAddress({
    address: WALLET
  });
  console.log(internalTxs);

  // Get 'internal transactions' by transaction hash
  const internalTxsByHash = await blockExplorer.getInternalTxListByTxHash({
    txhash: '0x40eb908387324f2b575b4879cd9d7188f69c8fc9d87c901b9e2daaea4b442170'
  });
  console.log(internalTxsByHash);

  // Get a list of 'ERC20 - token transfer events' by address:
  const tokenEvents = await blockExplorer.getErc20TokenTransferEventsList({
    address: '0x77134cbC06cB00b66F4c7e623D5fdBF6777635EC',
    contractaddress: '0x9702230A8Ea53601f5cD2dc00fDBc13d4dF4A8c7',
    page: 1,
    offset: 100,
    startblock: 34372864,
    endblock: 34472864,
    sort: BlockExplorerSort.Asc
  });
  console.log(tokenEvents);

  // Get ERC20-Token Account Balance for TokenContractAddress:
  const tokenBalance = await blockExplorer.getAccountTokenBalance({
    contractAddress: '0x57d90b64a1a57749b0f932f1a3395792e12e7055',
    address: WALLET,
    tag: BlockExplorerTag.Latest
  });
  console.log(`Balance of ${WALLET} is ${tokenBalance}`);
}

main();

Contracts section

import { BlockExplorerCodeFormat, BlockExplorerCommon, Chain } from 'routescan-client';

const ROUTESCAN_API_KEY = 'YourApiKey';
const CONTRACT_ADDRESS = '0x2A1D1C87d18dd13d7a1e91A42C9fFEc486EB6433';
const CONTRACT_NAME = 'HelloWorld';
const CONTRACT_SOURCE_CODE = 'contract source code string...';
const COMPILER_VERSION = 'v0.8.10+commit.fc410830';

async function main() {
  const blockExplorer = BlockExplorerCommon.build({
    chain: Chain.AvalancheCChainFuji,
    apiKey: ROUTESCAN_API_KEY
  });

  // Verify Source Code:
  const verified = await blockExplorer.verifySoliditySourceCode({
    codeformat: BlockExplorerCodeFormat.SoliditySingleFile,
    sourceCode: CONTRACT_SOURCE_CODE,
    contractaddress: CONTRACT_ADDRESS,
    contractname: CONTRACT_NAME,
    compilerversion: COMPILER_VERSION
  });
  console.log(verified);
}

Blocks section

import { BlockExplorerClosest, BlockExplorerCommon, Chain } from 'routescan-client';

const ROUTESCAN_API_KEY = 'YourApiKey';

async function main() {
  const blockExplorer = BlockExplorerCommon.build({
    chain: Chain.AvalancheCChainFuji,
    apiKey: ROUTESCAN_API_KEY
  });

  // Get estimated block countdown time by blockNo:
  const blockCountdown = await blockExplorer.getBlockCountdownTime({
    blockno: 167015880000
  });
  console.log('Block countdown', blockCountdown);

  // Get block number by timestamp:
  const timestamp = 1619638524;
  const blockNumberByTimestamp = await blockExplorer.getBlockNumberByTimestamp({
    timestamp,
    closest: BlockExplorerClosest.After
  });
  console.log(`Block number after ${timestamp} is ${blockNumberByTimestamp}`);
}

main();

Geth/Parity Proxy section

import { BlockExplorerCommon, Chain } from 'routescan-client';

const ROUTESCAN_API_KEY = 'YourApiKey';

async function main() {
  const blockExplorer = BlockExplorerCommon.build({
    chain: Chain.AvalancheCChainFuji,
    apiKey: ROUTESCAN_API_KEY
  });

  // Get number of most recent block:
  const blockNumber = await blockExplorer.eth_blockNumber();
  console.log(blockNumber);

  // Get information about a block by block number:
  const block = await blockExplorer.eth_getBlockByNumber({
    boolean: true,
    tag: '0x10d4f'
  });
  console.log(block);

  // Get information about a uncle by block number:
  const uncleBlock = await blockExplorer.eth_getUncleByBlockNumberAndIndex({
    tag: '0xC63276',
    index: '0x0'
  });
  console.log(uncleBlock);

  // Get the number of transactions in a block:
  const blockTxCount = await blockExplorer.eth_getBlockTransactionCountByNumber({
    tag: '0x10FB78'
  });
  console.log(blockTxCount);

  // Get the information about a transaction requested by transaction hash:
  const tx = await blockExplorer.eth_getTransactionByHash({
    txhash: '0xbc78ab8a9e9a0bca7d0321a27b2c03addeae08ba81ea98b03cd3dd237eabed44'
  });
  console.log(tx);

  // Get information about a transaction by block number and transaction index position:
  const txSecond = await blockExplorer.eth_getTransactionByBlockNumberAndIndex({
    tag: '0xC6331D',
    index: '0x11A'
  });
  console.log(txSecond);

  // Get the number of transactions performed by an address:
  const txCount = await blockExplorer.eth_getTransactionCount({
    address: '0x4bd5900Cb274ef15b153066D736bf3e83A9ba44e'
  });
  console.log(txCount);

  // Submits a pre-signed transaction for broadcast to the Ethereum network:
  const txHash = await blockExplorer.eth_sendRawTransaction({
    hex: '0xf904808000831cfde080'
  });
  console.log(txHash);

  // Get the receipt of a transaction by transaction hash:
  const txReceipt = await blockExplorer.eth_getTransactionReceipt({
    txhash: '0xadb8aec59e80db99811ac4a0235efa3e45da32928bcff557998552250fa672eb'
  });
  console.log(txReceipt);

  // Executes a new message call immediately without creating a transaction on the block chain:
  const callResult = await blockExplorer.eth_call({
    to: '0xAEEF46DB4855E25702F8237E8f403FddcaF931C0',
    data: '0x70a08231000000000000000000000000e16359506c028e51f16be38986ec5746251e9724',
    tag: BlockExplorerTag.Latest
  });
  console.log(callResult);

  // Returns code at a given address:
  const codeInHex = await blockExplorer.eth_getCode({
    address: '0xf75e354c5edc8efed9b59ee9f67a80845ade7d0c',
    tag: BlockExplorerTag.Latest
  });
  console.log(codeIndex);

  // Returns the value from a storage position at a given address:
  const storageValue = await blockExplorer.eth_getStorageAt({
    address: '0x6e03d9cce9d60f3e9f2597e13cd4c54c55330cfd',
    position: '0x0',
    tag: BlockExplorerTag.Latest
  });
  console.log(storageValue);

  // Returns the current price per gas in wei:
  const gasPrice = await blockExplorer.eth_gasPrice();
  console.log(gasPrice);

  // Makes a call or transaction, which won't be added to the blockchain and returns the used gas:
  const gas = await blockExplorerEth.eth_estimateGas({
    data: '0x4e71d92d',
    to: '0xf0160428a8552ac9bb7e050d90eeade4ddd52843',
    value: '0xff22',
    gasPrice: '0x51da038cc',
    gas: '0x5f5e0ff'
  });
  console.log(gas);
}

main();

Logs section

import { BlockExplorerCommon, BlockExplorerTopicOperation, Chain } from 'routescan-client';

const ROUTESCAN_API_KEY = 'YourApiKey';

async function main() {
  const blockExplorer = BlockExplorerCommon.build({
    chain: Chain.AvalancheCChainFuji,
    apiKey: ROUTESCAN_API_KEY
  });

  // Get event logs by address:
  const logs = await blockExplorer.getEventLogsByAddress({
    address: '0x9e66eba102b77fc75cd87b5e60141b85573bc8e8',
    fromBlock: 37000000,
    toBlock: 37200000,
    page: 1,
    offset: 1000
  });
  console.log(logs);

  // Get event logs by topics:
  const topicsLogs = await blockExplorer.getEventLogsByTopics({
    fromBlock: 37000000,
    toBlock: 37200000,
    topic0: '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
    topic0_1_opr: BlockExplorerTopicOperation.And,
    topic1: '0x0000000000000000000000000000000000000000000000000000000000000000',
    page: 1,
    offset: 1000
  });
  console.log(topicsLogs.length);

  // Get Event Logs by Address filtered by Topics:
  const addressLogs = await blockExplorer.getEventLogsByAddressFiltered({
    address: '0x9e66eba102b77fc75cd87b5e60141b85573bc8e8',
    fromBlock: 37000000,
    toBlock: 37200000,
    topic0: '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
    topic0_1_opr: BlockExplorerTopicOperation.And,
    topic1: '0x0000000000000000000000000000000000000000000000000000000000000000',
    page: 1,
    offset: 1000
  });
  console.log(addressLogs.length);

  // Returns code at a given address:
  const codeInHex = await blockExplorer.eth_getCode({
    address: '0xf75e354c5edc8efed9b59ee9f67a80845ade7d0c',
    tag: BlockExplorerTag.Latest
  });
  console.log(codeInHex);
}

main();

Transactions section

import { BlockExplorerCommon, BlockExplorerTopicOperation, Chain } from 'routescan-client';

const ETHEREUM_API_KEY = 'YourApiKey';

async function main() {
  const blockExplorer = BlockExplorerCommon.build({
    chain: Chain.Ethereum,
    apiKey: ETHEREUM_API_KEY
  });

  // Check Contract Execution Status:
  const txStatus = await blockExplorer.getContractExecutionStatus({
    txhash: '0x15f8e5ea1079d9a0bb04a4c58ae5fe7654b5b2b4463375ff7ffb490aa0032f3a'
  });
  console.log(txStatus);

  // Check Transaction Receipt Status:
  const receiptStatus = await blockExplorer.checkTransactionReceiptStatus({
    txhash: '0x513c1ba0bebf66436b5fed86ab668452b7805593c05073eb2d51d3a52f480a76'
  });
  console.log(receiptStatus);
}

main();

Supported networks table

Client also support other etherscan-compatible block explorers, but in this case you must provide custom url parameter.

You must use the API key of the corresponding block explorer!!!
Just register an account on corresponding site and generate an API key.

IDNameBlock explorerBlock explorer API url
1Ethereumhttps://etherscan.iohttps://api.etherscan.io/api
17000EthereumHoleskyhttps://etherscan.iohttps://api-holesky.etherscan.io/api
11155111EthereumSepoliahttps://etherscan.iohttps://api-sepolia.etherscan.io/api
10Optimismhttps://optimistic.etherscan.iohttps://api-optimistic.etherscan.io/api
11155420OptimismSepoliahttps://optimistic.etherscan.iohttps://api-sepolia-optimistic.etherscan.io/api
14FlareMainnethttps://routescan.iohttps://api.routescan.io/v2/network/mainnet/evm/14/etherscan/api
114FlareTestnethttps://routescan.iohttps://api.routescan.io/v2/network/testnet/evm/114/etherscan/api
56BinanceSmartChainhttps://bscscan.comhttps://api.bscscan.com/api
97BinanceSmartChainTestnethttps://bscscan.comhttps://api-testnet.bscscan.com/api
137Polygonhttps://polygonscan.comhttps://api.polygonscan.com/api
80002PolygonAmoyhttps://polygonscan.comhttps://api-amoy.polygonscan.com/api
185Minthttps://routescan.iohttps://api.routescan.io/v2/network/mainnet/evm/185/etherscan/api
1687MintSepoliahttps://routescan.iohttps://api.routescan.io/v2/network/testnet/evm/1687/etherscan/api
204BinanceOpBnbMainnethttps://opbnb.bscscan.comhttps://api-opbnb.bscscan.com/api
5611BinanceOpBnbTestnethttps://opbnb.bscscan.comhttps://api-opbnb-testnet.bscscan.com/api
250Fantomhttps://ftmscan.comhttps://api.ftmscan.com/api
4002FantomTestnethttps://ftmscan.comhttps://api-testnet.ftmscan.com/api
5000Mantlehttps://mantlescan.xyzhttps://api.mantlescan.xyz/api
5003MantleSepoliahttps://mantlescan.xyzhttps://api-sepolia.mantlescan.xyz/api
8453Basehttps://basescan.orghttps://api.basescan.org/api
84532BaseSepoliahttps://basescan.orghttps://api-sepolia.basescan.org/api
42161Arbitrumhttps://arbiscan.iohttps://api.arbiscan.io/api
42170ArbitrumNovahttps://arbiscan.iohttps://api-nova.arbiscan.io/api
421614ArbitrumSepoliahttps://arbiscan.iohttps://api-sepolia.arbiscan.io/api
43114AvalancheCChainhttps://routescan.iohttps://api.routescan.io/v2/network/mainnet/evm/43114/etherscan/api
43113AvalancheCChainFujihttps://routescan.iohttps://api.routescan.io/v2/network/testnet/evm/43113/etherscan/api
42220Celohttps://celoscan.iohttps://api.celoscan.io/api
44787CeloAlfajoreshttps://celoscan.iohttps://api-alfajores.celoscan.io/api
59144Lineahttps://lineascan.buildhttps://api.lineascan.build/api
59141LineaSepoliahttps://lineascan.buildhttps://api-sepolia.lineascan.build/api
167000Taikohttps://taikoscan.iohttps://api.taikoscan.io/api
167000TaikoHeklaL2https://taikoscan.iohttps://api-hekla.taikoscan.io/api
432204Dexalothttps://routescan.iohttps://api.routescan.io/v2/network/mainnet/evm/432204/etherscan/api
432201DexalotTestnethttps://routescan.iohttps://api.routescan.io/v2/network/testnet/evm/432201/etherscan/api
2.11.0

8 months ago

2.11.1

8 months ago

2.17.4

5 months ago

2.17.2

6 months ago

2.17.3

6 months ago

2.17.0

6 months ago

2.17.1

6 months ago

2.15.0

8 months ago

2.13.0

8 months ago

2.11.2

8 months ago

2.13.1

8 months ago

2.11.3

8 months ago

2.12.0

8 months ago

2.16.0

8 months ago

2.14.0

8 months ago

2.10.9

9 months ago

2.10.8

9 months ago

2.10.1

1 year ago

2.10.2

1 year ago

2.10.7

11 months ago

2.10.5

11 months ago

2.10.6

11 months ago

2.10.3

11 months ago

2.10.0

1 year ago

2.9.0

1 year ago

2.9.2

1 year ago

2.9.1

1 year ago

2.9.3

1 year ago

2.5.0

1 year ago

2.7.0

1 year ago

2.6.0

1 year ago

2.7.2

1 year ago

2.8.0

1 year ago

2.7.1

1 year ago

2.4.0

1 year ago

2.3.1

1 year ago

2.3.0

1 year ago

2.2.0

1 year ago

2.1.0

1 year ago

2.0.3

1 year ago

2.0.2

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago

1.6.1

1 year ago

1.6.0

1 year ago

1.5.9

1 year ago

1.5.8

1 year ago

1.5.5

1 year ago

1.5.4

1 year ago

1.5.3

1 year ago

1.5.2

1 year ago

1.4.0

1 year ago

1.5.7

1 year ago

1.5.6

1 year ago

1.2.0

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.3.0

1 year ago

1.2.1

1 year ago

1.1.2

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago