Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update examples.rst with Infura/rinkeby steps #1444

Merged
merged 1 commit into from Sep 5, 2019

Conversation

@SyedMuhamadYasir
Copy link
Contributor

commented Sep 4, 2019

Using Infura Rinkeby Node

Import your required libraries

from web3 import Web3, HTTPProvider

Initialize a web3 instance with an Infura node

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

Inject the middleware into the middleware onion

w3.middleware_onion.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).buildTransaction()
transaction.update({ 'gas' : appropriate_gas_amount })  
transaction.update({ 'nonce' : web3.eth.getTransactionCount('Your_Wallet_Address') })
signed_tx = w3.eth.account.signTransaction(transaction, private_key)

P,S : the two updates are done to the transaction dictionary, since it might not contain gas & nonce amounts, so you have to add them manually.

And then send the transaction

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

What was wrong?

Related to Issue # ; not sure about which issue this might correspond to, but there was terrible documentation regarding how to inject the POA middleware and calling a state-changing transaction also yielded alot of errors in my experimentation. so i thought to contribute a combined solution, outlining the simple yet subtle step of injecting middle-ware and also how to constuct a raw transaction to interact with a state-changing function in your smart contract.

How was it fixed?

It can be seen in the code. However, to put it briefly, i just simplified the steps on injecting the geth-style middleware in web3.py, when using an Infura Rinkeby node and i also outlined the steps on how to properly construct a transaction for calling a state-changing function in a smart-contract deployed on Rinkeby testnet.

Todo:

Cute Animal Picture

Put a link to a cute animal picture inside the parenthesis-->

@carver

This comment has been minimized.

Copy link
Collaborator

commented Sep 4, 2019

Note that this example would have to be updated for v5. It's using v4 things, like middleware_stack.

@SyedMuhamadYasir

This comment has been minimized.

Copy link
Contributor Author

commented Sep 4, 2019

Note that this example would have to be updated for v5. It's using v4 things, like middleware_stack.

feel free to add edit ( if you can )

or you can simply suggest them to me

thanks !

docs/examples.rst Outdated Show resolved Hide resolved
docs/examples.rst Outdated Show resolved Hide resolved
docs/examples.rst Outdated Show resolved Hide resolved
docs/examples.rst Outdated Show resolved Hide resolved
docs/examples.rst Outdated Show resolved Hide resolved
@kclowes

This comment has been minimized.

Copy link
Contributor

commented Sep 4, 2019

@SyedMuhamadYasir Looks like the two failures are just flaky tests, so don't worry about those. I'm happy to update if you want, just let me know!

@SyedMuhamadYasir

This comment has been minimized.

Copy link
Contributor Author

commented Sep 4, 2019

@SyedMuhamadYasir Looks like the two failures are just flaky tests, so don't worry about those. I'm happy to update if you want, just let me know!

thanks for reassuring me on those tests

yeah, go ahead !

P.S : should i update the stuff in this pull request before you make the changes ?

@kclowes

This comment has been minimized.

Copy link
Contributor

commented Sep 4, 2019

@SyedMuhamadYasir please go ahead and update if you have the time, thank you!

@SyedMuhamadYasir

This comment has been minimized.

Copy link
Contributor Author

commented Sep 4, 2019

@SyedMuhamadYasir please go ahead and update if you have the time, thank you!

done !

please take a look :)

@kclowes
Copy link
Contributor

left a comment

👍 this is looking good! I just ran through the actual commands locally and added a few more comments. Thank you!

docs/examples.rst Outdated Show resolved Hide resolved
docs/examples.rst Outdated Show resolved Hide resolved
docs/examples.rst Show resolved Hide resolved
@SyedMuhamadYasir

This comment has been minimized.

Copy link
Contributor Author

commented Sep 5, 2019

all recommended changes applied, kindly check

@kclowes
kclowes approved these changes Sep 5, 2019
Copy link
Contributor

left a comment

Looks good to me @SyedMuhamadYasir! Thank you!

@SyedMuhamadYasir

This comment has been minimized.

Copy link
Contributor Author

commented Sep 5, 2019

Looks good to me @SyedMuhamadYasir! Thank you!

Great 😄

any further steps i have to take to complete my contribution ?

@kclowes

This comment has been minimized.

Copy link
Contributor

commented Sep 5, 2019

If you're feeling up to it, it would be helpful if you could make a new file called newsfragments/1444.doc.rst with one line explaining what this PR does. If not, I'm happy to do it and should get to it later today!

@kclowes kclowes force-pushed the SyedMuhamadYasir:patch-2 branch from 921db96 to 7e9e351 Sep 5, 2019

@kclowes

This comment has been minimized.

Copy link
Contributor

commented Sep 5, 2019

Thank you @SyedMuhamadYasir!

@kclowes kclowes merged commit 917d2fb into ethereum:master Sep 5, 2019

27 of 28 checks passed

ci/circleci: py37-integration-parity-ipc Your tests failed on CircleCI
Details
ci/circleci: docs Your tests passed on CircleCI!
Details
ci/circleci: lint Your tests passed on CircleCI!
Details
ci/circleci: py36-core Your tests passed on CircleCI!
Details
ci/circleci: py36-ens Your tests passed on CircleCI!
Details
ci/circleci: py36-ethpm Your tests passed on CircleCI!
Details
ci/circleci: py36-integration-ethtester-pyevm Your tests passed on CircleCI!
Details
ci/circleci: py36-integration-goethereum-http-1.7.2 Your tests passed on CircleCI!
Details
ci/circleci: py36-integration-goethereum-http-1.8.22 Your tests passed on CircleCI!
Details
ci/circleci: py36-integration-goethereum-ipc-1.7.2 Your tests passed on CircleCI!
Details
ci/circleci: py36-integration-goethereum-ipc-1.8.22 Your tests passed on CircleCI!
Details
ci/circleci: py36-integration-goethereum-ws-1.7.2 Your tests passed on CircleCI!
Details
ci/circleci: py36-integration-goethereum-ws-1.8.22 Your tests passed on CircleCI!
Details
ci/circleci: py36-integration-parity-http Your tests passed on CircleCI!
Details
ci/circleci: py36-integration-parity-ipc Your tests passed on CircleCI!
Details
ci/circleci: py36-integration-parity-ws Your tests passed on CircleCI!
Details
ci/circleci: py37-core Your tests passed on CircleCI!
Details
ci/circleci: py37-ens Your tests passed on CircleCI!
Details
ci/circleci: py37-ethpm Your tests passed on CircleCI!
Details
ci/circleci: py37-integration-ethtester-pyevm Your tests passed on CircleCI!
Details
ci/circleci: py37-integration-goethereum-http-1.7.2 Your tests passed on CircleCI!
Details
ci/circleci: py37-integration-goethereum-http-1.8.22 Your tests passed on CircleCI!
Details
ci/circleci: py37-integration-goethereum-ipc-1.7.2 Your tests passed on CircleCI!
Details
ci/circleci: py37-integration-goethereum-ipc-1.8.22 Your tests passed on CircleCI!
Details
ci/circleci: py37-integration-goethereum-ws-1.7.2 Your tests passed on CircleCI!
Details
ci/circleci: py37-integration-goethereum-ws-1.8.22 Your tests passed on CircleCI!
Details
ci/circleci: py37-integration-parity-http Your tests passed on CircleCI!
Details
ci/circleci: py37-integration-parity-ws Your tests passed on CircleCI!
Details
@SyedMuhamadYasir

This comment has been minimized.

Copy link
Contributor Author

commented Sep 7, 2019

Thank you @SyedMuhamadYasir!

You are most welcome @kclowes !

and thank you for helping me out with the process !

i'll be working with Ethereum (and web3.py) in the time to come and i hope to make more contributions to the repo

see you ^_^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.