So i have trouble using a smart contract on Rinkeby through infura as it gives an "extra-data" error, which as far as i have read, is due to Rinkeby being a POA testnet. There are suggestions of using a middle-ware for this, but there's no good documentation to describe how it can be done ...

Also, the extra-data error occurs when calling a state-changing function ( like assigning a new value to a storage variable ), not when calling a read only function ( like a "getter" method )

anyone has any idea how to fix this ?


easy solution RIGHT HERE;

Import your required libraries

from web3 import Web3, HTTPProvider

Intialize your infura node in a variable

w3 = Web3(Web3.HTTPProvider("https://rinkeby.infura.io/v3/YOUR_INFURA_KEY"))

aand.. the most SIMPLE part, which TOOK OVER THREE WEEKS to figure out because the documentation is absolutely horrenous ;

inject the damn middle-ware in the variable holding your infura node;

w3.middleware_stack.inject(geth_poa_middleware, layer=0)

just remember that you have to sign all transactions LOCALLY, as infura does not handle any keys from your wallet

transaction = contract.functions.function_Name(params)
signed_tx = w3.eth.account.signTransaction(transaction, private_key)

and then send;

txn_hash = w3.eth.sendRawTransaction(signed.rawTransaction) 
txn_receipt = w3.eth.waitForTransactionReceipt(txn_hash)

there you go, an all in one solution !

P.S : use print(txn_receipt) to get transaction id to view in etherscan

| improve this answer | |
  • from web3.middleware import geth_poa_middleware – jonincanada Nov 8 '19 at 0:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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