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

@SyedMuhamadYasir SyedMuhamadYasir 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
Copy link
Collaborator

carver commented Sep 4, 2019

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

@SyedMuhamadYasir
Copy link
Contributor Author

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
Copy link
Collaborator

kclowes 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
Copy link
Contributor Author

SyedMuhamadYasir 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
Copy link
Collaborator

kclowes commented Sep 4, 2019

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

@SyedMuhamadYasir
Copy link
Contributor Author

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

done !

please take a look :)

Copy link
Collaborator

@kclowes kclowes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 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
Copy link
Contributor Author

all recommended changes applied, kindly check

Copy link
Collaborator

@kclowes kclowes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me @SyedMuhamadYasir! Thank you!

@SyedMuhamadYasir
Copy link
Contributor Author

Looks good to me @SyedMuhamadYasir! Thank you!

Great 😄

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

@kclowes
Copy link
Collaborator

kclowes 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
Copy link
Collaborator

kclowes commented Sep 5, 2019

Thank you @SyedMuhamadYasir!

@kclowes kclowes merged commit 917d2fb into ethereum:master Sep 5, 2019
@SyedMuhamadYasir
Copy link
Contributor Author

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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants