3
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,
    nonce=0,
    to='0xABA024480E6B9e92B7e3332a2a3eb104F183D18C',
    value= 100000,
    chainId = 1
),
'0x2850d0xxxxxxxxxxxxxxxxxxxxxxxxxx')


w3.eth.sendRawTransaction(signed_txn.rawTransaction)

Return

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

What's the problem?

0

1 Answer 1

2

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 that you have read and understand our privacy policy and code of conduct.

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