question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 6 years ago
  • Comments:24 (10 by maintainers)

github_iconTop GitHub Comments

3reactions
owockicommented, Dec 5, 2017

@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! 🎉

3reactions
monokhcommented, Nov 17, 2017

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

web3.eth.Contract — web3.js 1.0.0 documentation
Creates a transaction object for that method, which then can be called, send, estimated, or ABI encoded.
Read more >
Contract - Ethers.js
Returns an UnsignedTransaction which represents the transaction that would need to be signed and submitted to the network to execute METHOD_NAME with args...
Read more >
Smart contract details - Algorand Developer Portal
Smart contracts can generate asset and payment transactions allowing them to function as Escrow accounts on the Algorand blockchain. Smart contracts can ...
Read more >
Options Contract: What It Is, How It Works, Types of Contracts
Key Takeaways. An options contract is an agreement between two parties to facilitate a potential transaction involving an asset at a preset price...
Read more >
An Introduction to Ethereum and Smart Contracts - Auth0
In this way, a verifiable link of transactions is created; each new transaction, with a new owner, pointing to the previous transaction, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found