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.
from ethersacanAPI import etherscan
myapi = etherscan('myapikey','networkname')Use networkname ='mainnet' for mainnet.
Use networkname ='ropsten' for Ropsten.
Use networkname ='rinkeby' for Rinkeby.
Use networkname ='kovan' for Kovan.
Accounts: Details
-
getBalance(address)
Get Ether Balance for a single Address. -
getBalanceMulti(address)
Get Ether Balance for multiple Addresses in a single call.
Address must be a list of addresses. -
getTransactions(address, fromblock, toblock)
Get a list of 'Normal' Transactions By Address. -
getInternalTransactionsByAddress(address, fromblock, toblock)
Get a list of 'Internal' Transactions by Address. -
getInternalTransactionsByTxHash(txhash, fromblock, toblock)
Get "Internal Transactions" by Transaction Hash. -
getERC20TransfersByAddress(address, fromblock, toblock)
Get a list of "ERC20 - Token Transfer Events" by Address. -
getERC20TransfersByContract(contractAddress, address, fromblock, toblock)
Get a list of "ERC20 - Token Transfer Events" by account Address and contract address. -
getMinedBlocks(address)
Get list of Blocks Mined by Address.
Contracts: Details
-
getContractABI(address)
Get Contract ABI for Verified Contract Source Codes. -
getSourceCode(address)
Get Contract Source Code for Verified Contract Source Codes.
Transactions: Details
-
getReceiptStatus(txhash)
Check Transaction Receipt Status (Only applicable for Post Byzantium fork transactions). -
getContractTxStatus(txhash)
Check Contract Execution Status (if there was an error during contract execution).
Blocks: Details
- getBlockRewards(blockNumber)
Get Block And Uncle Rewards by BlockNo.
Geth/Parity proxy: Details
-
getBlockNumber()
Returns the number of most recent block. -
getBlockByNumber(number)
Returns information about a block by block number. -
getBlockTransactionCountByNumber(number)
Returns the number of transactions in a block from a block matching the given block number. -
getUncleByBlockNumberAndIndex(number, index)
Returns information about a uncle by block number. -
getTransactionByHash(txhash)
Returns the information about a transaction requested by transaction hash. -
getTransactionByBlockNumberAndIndex(number, index)
Returns information about a transaction by block number and transaction index position. -
getTransactionCount(address)
Returns the number of transactions sent from an address. -
sendRawTransaction(signedTx)
Returns the receipt of a transaction by transaction hash. -
def getTransactionReceipt(txhash)
Creates new message call transaction or a contract creation for signed transactions. -
call(to, data)
Executes a new message call immediately without creating a transaction on the blockchain. -
getCode(address)
Returns code at a given address. -
getStorageAt(address, position)
Returns the value from a storage position at a given address. -
gasPrice()
Returns the current price per gas in wei. -
estimateGas(to, value, gasprice, gas)
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.
Logs: Details
- getLogs(self, fromBlock, toBlock, address, topics, topicsOperator)
topicsis a dictionary with possible entriestopic0,topic1,topic2
topicsOperatoris a dictionary with possible value:topics0_1_op,topics0_2_op, andtopics1_2_op.
It determines the type of filter applied to the topics. See the exemples below for details of usage.
Token: Details
-
getTokenTotalSupply(contractAddress)
Get ERC20-Token TotalSupply by ContractAddress -
getTokenBalance(address, contractAddress)
Get ERC20-Token Account Balance for TokenContractAddress.
Stats: Details
-
getEtherSupply()
Get Total Supply of Ether. -
getEtherPrice(self)
Get ETHER LastPrice Price.
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)