Web3.py: Add documentation for connecting to POA chains

Created on 20 Mar 2018  路  11Comments  路  Source: ethereum/web3.py

What was wrong?

Its not obvious that geth_poa_middleware must be used to connect to POA chains.

How can it be fixed?

Maybe a good solution in the docs is a page just following the "Quickstart" with specific guides for connecting in different scenarios. Something like "Getting Started with ...", with sections for Rinkeby, Infura, geth --dev, parity, etc

All 11 comments

BTW, there is some example code in the docs, but it's probably not discoverable (ie~ needs to be moved elsewhere):

http://web3py.readthedocs.io/en/latest/middleware.html#geth-style-proof-of-authority

BTW, there is some example code in the docs, but it's probably not discoverable (ie~ needs to be moved elsewhere):

http://web3py.readthedocs.io/en/latest/middleware.html#geth-style-proof-of-authority

carver can you help me out a bit ?

is there any way i can privately correspond with you, i need a bit of help with using this POA middleware

i would be grateful for a few minutes of your time @carver

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 !

Looks like a great section of code to contribute to the documentation as a sort of "guide"

Looks like a great section of code to contribute to the documentation as a sort of "guide"

can you please guide me how to do this ?

cc @cburgdorf and/or @kclowes

For now I think https://github.com/ethereum/web3.py/blob/4a98f1a60ca24366fca7b33ddb226c62d679b015/docs/examples.rst would be the appropriate file to add it to, but I think @cburgdorf has some ideas on adding a "Guides" section to the docs which would potentially be a more appropriate long term place for this to live.

To contribute this guide you'd open a pull request modifying that ./docs/examples.rst file to include a new section with your code and explanations from above.

cc @cburgdorf and/or @kclowes

For now I think https://github.com/ethereum/web3.py/blob/4a98f1a60ca24366fca7b33ddb226c62d679b015/docs/examples.rst would be the appropriate file to add it to, but I think @cburgdorf has some ideas on adding a _"Guides"_ section to the docs which would potentially be a more appropriate long term place for this to live.

To contribute this guide you'd open a pull request modifying that ./docs/examples.rst file to include a new section with your code and explanations from above.

ok, thank you so much for your guidance.

So... i'm a bit new to using Version Control and Github, in general. so before your message, i created a pull request to quickstart.rst

and i later read your comment and now i have submitted a pull request to examples.rst

how do i inform the owners of the repo regarding this small mistake?

@SyedMuhamadYasir There should be a button at the bottom of the pull request that says "Close pull request". You can just close the one that is wrong. Thanks!

@SyedMuhamadYasir There should be a button at the bottom of the pull request that says "Close pull request". You can just close the one that is wrong. Thanks!

thank you !

please do take a look at the valid pull request and suggest any additions if you deem it neccessary

Something that contributed to the difficulty here was using the v5 docs while the installed version of web3.py was v4. So that seems like a whole separate thing to address in the docs: helping people choose the right doc version to read.

(cleaning up old issues)

Relevant links if you landed on this page:

Was this page helpful?
0 / 5 - 0 ratings