New contract method execution option: generating the transaction dictionary
See original GitHub issue- Version: 4
What was wrong?
There is no convenient way to prepare a contract transaction for offline signing.
Specifically, the prepared transaction should work smoothly with w3.eth.account.signTransaction()
.
How can it be fixed?
New contract method preparation API
Add a new way to prepare a contract function transaction. It would look something like:
# new API
transaction_dict = myContract.functions.myMethod().asdict()
# existing APIs
signed = w3.eth.account.signTransaction(transaction_dict, private_key)
w3.eth.sendRawTransaction(signed.rawTransaction)
asdict
should accept a dictionary that defines transaction fields, just like call/transact/etc, and return an AttributeDict
.
Fields included
Besides the natural fields, like to
and data
, this must also generate other fields like:
- nonce
- chainId
- gas
- gasPrice
If they are not supplied as arguments to asdict()
, then they should be inferred before returning. signTransaction
will not attempt to infer these values, so they must be explicitly added.
API Naming
asdict()
is okay, but isn’t necessarily the obvious winner.
Some alternatives:
myContract.functions.myMethod().todict()
myContract.functions.myMethod().tofields()
myContract.functions.myMethod().prepare()
myContract.functions.myMethod().generate()
Crossover issue
Depending on whether #419 is already implemented, and how it’s implemented, this might require a bit of extra work to expose asdict
in both ways.
TODOs
- choose naming
- implement new API
- document in
docs/
- reference this method in signTransaction docs
docs/web3.eth.account.rst
~- [ ] Support for #419 - if implementation available~
Issue Analytics
- State:
- Created 6 years ago
- Comments:24 (10 by maintainers)
Top GitHub Comments
@monokh i just remitted payment. the gitcoinco bot didn’t comment because of issues resultant from the migration of this repo from @pipermerriam 's github handle to the @ethereum handle. nevertheless, payment has been remitted and https://gitcoin.co/funding/details?url=https://github.com/pipermerriam/web3.py/issues/430 is updated!
congrats! 🎉
Hi, I’m willing to work on this 🙂. I’ve done offline TX signing with web3.js but it had been a bit of a pain due to needed other libraries for TX signing. I have python experience so interested in how I can shape this 😃 Expect a merge request coming your way soon