export interface RouteScanTx { blockNumber: string; blockHash: string; timeStamp: string; hash: string; nonce: string; transactionIndex: string; from: string; to: string; value: string; gas: string; gasPrice: string; input: string; methodId: string; functionName: string; contractAddress: string; cumulativeGasUsed: string; txreceipt_status: string; gasUsed: string; confirmations: string; isError: string; } export interface RouteScanBalanceMultiResult { account: string; balance: string; } export interface RouteScanTokenTx { blockNumber: string; timeStamp: string; hash: string; nonce: string; blockHash: string; from: string; contractAddress: string; to: string; value: string; tokenName: string; tokenSymbol: string; tokenDecimal: string; transactionIndex: string; gas: string; gasPrice: string; gasUsed: string; cumulativeGasUsed: string; input: string; confirmations: string; } export interface RouteScanInternalTx { blockNumber: string; timeStamp: string; hash: string; from: string; to: string; value: string; contractAddress: string; input: string; type: string; gas: string; gasUsed: string; isError: string; errCode: string; } export interface RouteScanNftTx { blockNumber: string; timeStamp: string; hash: string; nonce: string; blockHash: string; from: string; contractAddress: string; to: string; tokenID: string; tokenName: string; tokenSymbol: string; tokenDecimal: string; transactionIndex: string; gas: string; gasPrice: string; gasUsed: string; cumulativeGasUsed: string; input: string; confirmations: string; } export interface RouteScanSourceCodeResult { SourceCode: string; ABI: string; ContractName: string; CompilerVersion: string; OptimizationUsed: string; Runs: string; ConstructorArguments: string; EVMVersion: string; Library: string; LicenseType: string; Proxy: string; Implementation: string; SwarmSource: string; } export interface RouteScanTxReceiptStatus { status: string; } export interface RouteScanBlockReward { blockNumber: string; timeStamp: string; blockMiner: string; blockReward: string; uncles: { miner: string; unclePosition: string; blockreward: string; }[]; uncleInclusionReward: string; } export interface RouteScanBlockCountdown { CurrentBlock: string; CountdownBlock: string; RemainingBlock: string; EstimateTimeInSec: string; } export interface RouteScanLog { address: string; topics: string[]; data: string; blockNumber: string; timeStamp: string; gasPrice: string; gasUsed: string; logIndex: string; transactionHash: string; transactionIndex: string; } export interface RouteScanProxyTx { blockHash: string; blockNumber: string; from: string; gas: string; gasPrice: string; hash: string; input: string; nonce: string; to: string; transactionIndex: string; value: string; v: string; r: string; s: string; } export interface RouteScanProxyBlock { number: string; hash: string; parentHash: string; nonce: string; sha3Uncles: string; logsBloom: string; transactionsRoot: string; stateRoot: string; miner: string; difficulty: string; totalDifficulty: string; extraData: string; size: string; gasLimit: string; gasUsed: string; timestamp: string; transactions: RouteScanProxyTx[] | string[]; uncles: string[]; } export interface RouteScanResponse { status: string; message: string; result: T; } const BASE_URL = "https://api.routescan.io/v2/network"; type Sort = "asc" | "desc"; export class RouteScanAPI { static async getTxList( network: string, chainId: number, address: string, startblock: number = 0, endblock: number = 99999999, page: number = 1, offset: number = 10, sort: Sort = "asc" ): Promise> { const url = `${BASE_URL}/${network}/evm/${chainId}/etherscan/api?module=account&action=txlist&address=${address}&startblock=${startblock}&endblock=${endblock}&page=${page}&offset=${offset}&sort=${sort}`; const res = await fetch(url); const data = await res.json() as RouteScanResponse; return data; } static async getBalance( network: string, chainId: number, address: string ): Promise> { const url = `${BASE_URL}/${network}/evm/${chainId}/etherscan/api?module=account&action=balance&address=${address}&tag=latest`; const res = await fetch(url); const data = await res.json() as RouteScanResponse; return data; } static async getBalanceMulti( network: string, chainId: number, addresses: string[] ): Promise> { const url = `${BASE_URL}/${network}/evm/${chainId}/etherscan/api?module=account&action=balancemulti&address=${addresses.join(',')}&tag=latest`; const res = await fetch(url); const data = await res.json() as RouteScanResponse; return data; } static async getTokenTransfers( network: string, chainId: number, address: string, contractaddress?: string, startblock: number = 0, endblock: number = 99999999, page: number = 1, offset: number = 10, sort: Sort = "asc" ): Promise> { let url = `${BASE_URL}/${network}/evm/${chainId}/etherscan/api?module=account&action=tokentx&address=${address}&startblock=${startblock}&endblock=${endblock}&page=${page}&offset=${offset}&sort=${sort}`; if (contractaddress) { url += `&contractaddress=${contractaddress}`; } const res = await fetch(url); const data = await res.json() as RouteScanResponse; return data; } static async getInternalTxListByAddress( network: string, chainId: number, address: string, startblock: number = 0, endblock: number = 99999999, page: number = 1, offset: number = 10, sort: Sort = "asc" ): Promise> { const url = `${BASE_URL}/${network}/evm/${chainId}/etherscan/api?module=account&action=txlistinternal&address=${address}&startblock=${startblock}&endblock=${endblock}&page=${page}&offset=${offset}&sort=${sort}`; const res = await fetch(url); const data = await res.json() as RouteScanResponse; return data; } static async getNftTransfers( network: string, chainId: number, address: string, contractaddress?: string, startblock: number = 0, endblock: number = 99999999, page: number = 1, offset: number = 10, sort: Sort = "asc" ): Promise> { let url = `${BASE_URL}/${network}/evm/${chainId}/etherscan/api?module=account&action=tokennfttx&address=${address}&startblock=${startblock}&endblock=${endblock}&page=${page}&offset=${offset}&sort=${sort}`; if (contractaddress) { url += `&contractaddress=${contractaddress}`; } const res = await fetch(url); const data = await res.json() as RouteScanResponse; return data; } static async getBalanceHistory( network: string, chainId: number, address: string, blockno: number ): Promise> { const url = `${BASE_URL}/${network}/evm/${chainId}/etherscan/api?module=account&action=balancehistory&address=${address}&blockno=${blockno}`; const res = await fetch(url); const data = await res.json() as RouteScanResponse; return data; } static async getAbi( network: string, chainId: number, address: string ): Promise> { const url = `${BASE_URL}/${network}/evm/${chainId}/etherscan/api?module=contract&action=getabi&address=${address}`; const res = await fetch(url); const data = await res.json() as RouteScanResponse; return data; } static async getSourceCode( network: string, chainId: number, address: string ): Promise> { const url = `${BASE_URL}/${network}/evm/${chainId}/etherscan/api?module=contract&action=getsourcecode&address=${address}`; const res = await fetch(url); const data = await res.json() as RouteScanResponse; return data; } static async getTxReceiptStatus( network: string, chainId: number, txhash: string ): Promise> { const url = `${BASE_URL}/${network}/evm/${chainId}/etherscan/api?module=transaction&action=gettxreceiptstatus&txhash=${txhash}`; const res = await fetch(url); const data = await res.json() as RouteScanResponse; return data; } static async getBlockReward( network: string, chainId: number, blockno: number ): Promise> { const url = `${BASE_URL}/${network}/evm/${chainId}/etherscan/api?module=block&action=getblockreward&blockno=${blockno}`; const res = await fetch(url); const data = await res.json() as RouteScanResponse; return data; } static async getBlockCountdown( network: string, chainId: number, blockno: number ): Promise> { const url = `${BASE_URL}/${network}/evm/${chainId}/etherscan/api?module=block&action=getblockcountdown&blockno=${blockno}`; const res = await fetch(url); const data = await res.json() as RouteScanResponse; return data; } static async getLogs( network: string, chainId: number, fromBlock: number | 'latest', toBlock: number | 'latest', address?: string, topics?: (string | null)[], page: number = 1, offset: number = 1000 ): Promise> { let url = `${BASE_URL}/${network}/evm/${chainId}/etherscan/api?module=logs&action=getLogs&fromBlock=${fromBlock}&toBlock=${toBlock}&page=${page}&offset=${offset}`; if (address) { url += `&address=${address}`; } if (topics) { for (let i = 0; i < topics.length; i++) { if (topics[i]) { url += `&topic${i}=${topics[i]}`; } } } const res = await fetch(url); const data = await res.json() as RouteScanResponse; return data; } static async ethBlockNumber( network: string, chainId: number ): Promise> { const url = `${BASE_URL}/${network}/evm/${chainId}/etherscan/api?module=proxy&action=eth_blockNumber`; const res = await fetch(url); const data = await res.json() as RouteScanResponse; return data; } static async ethGetBlockByNumber( network: string, chainId: number, blockNumber: string, fullTransactions: boolean = false ): Promise> { const url = `${BASE_URL}/${network}/evm/${chainId}/etherscan/api?module=proxy&action=eth_getBlockByNumber&tag=${blockNumber}&boolean=${fullTransactions}`; const res = await fetch(url); const data = await res.json() as RouteScanResponse; return data; } }