EtherscanAPI
A python wrapper for EtherScan API.
Install / Use
/learn @jfdelgad/EtherscanAPIREADME
etherscanAPI Python
A python wrapper for EtherScan API. (unofficial)
This library allows to interface with etherscan. It implements the requests to the modules:
- Accounts.
- Contracts.
- Transactions.
- Blocks.
- GETH / PARITY Proxy.
- Logs.
- Tokens.
- Stats.
All methods return the field Result of the request as described in etherscan website.
Usage:
from ethersacanAPI import etherscan
myapi = etherscan('myapikey','networkname')
Use networkname ='mainnet' for mainnet.<br> Use networkname ='ropsten' for Ropsten.<br> Use networkname ='rinkeby' for Rinkeby.<br> Use networkname ='kovan' for Kovan.<br> <br>
Methods Description:
Accounts: Details
-
getBalance(address)<br> Get Ether Balance for a single Address.<br>
-
getBalanceMulti(address)<br> Get Ether Balance for multiple Addresses in a single call.<br> Address must be a list of addresses.<br>
-
getTransactions(address, fromblock, toblock)<br> Get a list of 'Normal' Transactions By Address.<br>
-
getInternalTransactionsByAddress(address, fromblock, toblock)<br> Get a list of 'Internal' Transactions by Address.<br>
-
getInternalTransactionsByTxHash(txhash, fromblock, toblock)<br> Get "Internal Transactions" by Transaction Hash.<br>
-
getERC20TransfersByAddress(address, fromblock, toblock)<br> Get a list of "ERC20 - Token Transfer Events" by Address.<br>
-
getERC20TransfersByContract(contractAddress, address, fromblock, toblock)<br> Get a list of "ERC20 - Token Transfer Events" by account Address and contract address.<br>
-
getMinedBlocks(address)<br> Get list of Blocks Mined by Address.<br><br>
Contracts: Details
-
getContractABI(address)<br> Get Contract ABI for Verified Contract Source Codes.<br>
-
getSourceCode(address)<br> Get Contract Source Code for Verified Contract Source Codes.<br><br>
Transactions: Details
-
getReceiptStatus(txhash)<br> Check Transaction Receipt Status (Only applicable for Post Byzantium fork transactions).<br>
-
getContractTxStatus(txhash)<br> Check Contract Execution Status (if there was an error during contract execution).<br><br>
Blocks: Details
- getBlockRewards(blockNumber)<br> Get Block And Uncle Rewards by BlockNo.<br><br>
Geth/Parity proxy: Details
-
getBlockNumber()<br> Returns the number of most recent block.<br>
-
getBlockByNumber(number)<br> Returns information about a block by block number.<br>
-
getBlockTransactionCountByNumber(number)<br> Returns the number of transactions in a block from a block matching the given block number.<br>
-
getUncleByBlockNumberAndIndex(number, index)<br> Returns information about a uncle by block number.<br>
-
getTransactionByHash(txhash)<br> Returns the information about a transaction requested by transaction hash.<br>
-
getTransactionByBlockNumberAndIndex(number, index)<br> Returns information about a transaction by block number and transaction index position.<br>
-
getTransactionCount(address)<br> Returns the number of transactions sent from an address.<br>
-
sendRawTransaction(signedTx)<br> Returns the receipt of a transaction by transaction hash.<br>
-
def getTransactionReceipt(txhash)<br> Creates new message call transaction or a contract creation for signed transactions.<br>
-
call(to, data)<br> Executes a new message call immediately without creating a transaction on the blockchain.<br>
-
getCode(address)<br> Returns code at a given address.<br>
-
getStorageAt(address, position)<br> Returns the value from a storage position at a given address.<br>
-
gasPrice()<br> Returns the current price per gas in wei.<br>
-
estimateGas(to, value, gasprice, gas)<br> Makes a call or transaction, which won't be added to the blockchain and returns the used gas, which can be used for estimating the used gas.<br><br>
Logs: Details
- getLogs(self, fromBlock, toBlock, address, topics, topicsOperator)<br>
topicsis a dictionary with possible entriestopic0,topic1,topic2<br>topicsOperatoris a dictionary with possible value:topics0_1_op,topics0_2_op, andtopics1_2_op.<br> It determines the type of filter applied to the topics. See the exemples below for details of usage.<br><br>
Token: Details
-
getTokenTotalSupply(contractAddress)<br> Get ERC20-Token TotalSupply by ContractAddress
-
getTokenBalance(address, contractAddress)<br> Get ERC20-Token Account Balance for TokenContractAddress.<br><br>
Stats: Details
-
getEtherSupply()<br> Get Total Supply of Ether.<br>
-
getEtherPrice(self)<br> Get ETHER LastPrice Price.<br>
Examples:
from etherscanAPI import etherscan
apikey = 'yourAPIkey'
myapi = etherscan(apikey, 'mainnet') #
# Get the balance of an account
address = '0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae'
myapi.getBalance(address)
# Get contract logs at address='0x33990122638b9132ca29c723bdf037f1a891a70c' with topic0 = '0xf63780e752c6a54a94fc52715dbc5518a3b4c3c2833d301a204226548a2a8545', fromblock:379224 to block 4000000
# topicsOperator should be an empty dictionary if only one topic is used.
topics = {'topic0':'0xf63780e752c6a54a94fc52715dbc5518a3b4c3c2833d301a204226548a2a8545'}
topicsOperator = {}
myapi.getLogs(379224,400000,'0x33990122638b9132ca29c723bdf037f1a891a70c', topics, topicsOperator)
# Get contract logs using two topics
# topicsOperator is empty if only one topic is used
topics = {'topic0':'0xf63780e752c6a54a94fc52715dbc5518a3b4c3c2833d301a204226548a2a8545',
'topic1':'0x72657075746174696f6e00000000000000000000000000000000000000000000'}
topicsOperator = {'topic0_1_opr':'and'}
myapi.getLogs(379224,400000,'0x33990122638b9132ca29c723bdf037f1a891a70c', topics, topicsOperator)
Related Skills
node-connect
352.0kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
111.1kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
352.0kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
352.0kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
