from web3 import *

etherscan_provider = Web3.HTTPProvider( 'https://api.etherscan.io/api')
w3 = Web3(etherscan_provider)

signed_txn = w3.eth.account.signTransaction(dict(
    gas = 2000000,
    gasPrice= 234567897654321,
    value= 100000,
    chainId = 1



File "/root/eth/lib/python3.6/site-packages/eth_utils/conversions.py", line 142, in hexstr_if_str                                                                             
ValueError: when sending a str, it must be a hex string. Got: 'Error! Missing Or invalid Module name'   

What's the problem?


1 Answer 1


The etherscan API is not a JSON-RPC-compatible API. If you want to use a remote node with web3, you can use something like Infura.

According to their documentation, there are ways to invoke the JSON-RPC methods, but they don't actually implement the API externally. For example, to get the latest block number in the JSON-RPC API, you would send a POST like this:

curl -X POST --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":83}' localhost:8545

(which web3.py does for you behind the scenes of w3.eth.blockNumber)

In the etherscan API, you would send a GET, like this:

curl https://api.etherscan.io/api?module=proxy&action=eth_blockNumber&apikey=YourApiKeyToken

The two APIs are simply different. It would be possible to create a new specialized EtherscanProvider to work inside web3.py, instead of the normal HTTPProvider, but it would take a bit of work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.