Web3.py: Support for fallback and constructor functions

Created on 23 Jan 2018  路  16Comments  路  Source: ethereum/web3.py

Continuation of https://github.com/ethereum/web3.py/issues/353

What was wrong?

We should support the following API on contract instances for interacting with the fallback function.

  • contract.fallback.estimateGas()
  • contract.fallback.call()
  • contract.fallback.transact()
  • contract.fallback.buildTransaction()

As well as the following for interacting with the constructor.

  • contract.constructor(*args, **kwargs).estimateGas()
  • contract.constructor(*args, **kwargs).transact()
  • contract.constructor(*args, **kwargs).buildTransaction()

How can it be fixed?

Hopefully we can leverage the existing web3.contract.ContractMethod abstraction.

Good For Bounty

Most helpful comment

I will give it a try :)

All 16 comments

__This issue now has a funding of 0.4 ETH (402.8 USD) attached to it.__

  • If you would like to work on this issue you can claim it here.
  • If you've completed this issue and want to claim the bounty you can do so here
  • Questions? Get help on the Gitcoin Slack
  • $16127.14 more Funded OSS Work Available at: https://gitcoin.co/explorer

@carver @dylanjw thoughts on this?

  • Should contract.deploy() be deprecated?
  • Should contract.constructor(...).transact() be named something like contract.constructor(...).deploy()?

Should contract.deploy() be deprecated?

Sounds good to me. A new API for the local signing of the deploy transaction is needed anyway, and I like that constructor consistent with the ABI type name.

Should contract.constructor(...).transact() be named something like contract.constructor(...).deploy()

I think we should be consistent with the other options here (call, buildTransaction, etc)

__The funding of 0.4 ETH (420.48 USD) attached has been claimed by @zheli.__

@zheli, please leave a comment to let the funder and the other parties involved your implementation plan. If you don't leave a comment, the funder may expire your claim at their discretion.

I will give it a try :)

@zheli if you have any work towards this, I encourage you to go ahead and open a pull request with it. We can mark it as a work-in-progress.

@pipermerriam have some question regarding calling fallback function using constructor form. As it is mentioned in the specification:

contract.constructor(args, *kwargs).estimateGas()
contract.constructor(args, *kwargs).transact()
contract.constructor(args, *kwargs).buildTransaction()

So user should be able to use them on fallback function like this?
contract.estimateGas().fallback(args, kwargs)?

I am wondering what should we do if there is a actual function called fallback in user's contract

Also I want to clarify by deprecating contract.constructor().deploy, you mean people should be able to call contract.constructor().transact() without the suffix function name to deploy contract?

So user should be able to use them on fallback function like this?
contract.estimateGas().fallback(args, kwargs)?

I think it's okay if you only want to support the newest contract function API, and not the flipped one. So this would be the only one supported:

    contract.fallback.estimateGas()
    contract.fallback.call()
    contract.fallback.transact()
    contract.fallback.buildTransaction()

In this ordering, there is no way to collide with the contract's defined function names. You would call a user-defined fallback function with: contract.functions.fallback(...).transact(...).

Also I want to clarify by deprecating contract.constructor().deploy, you mean people should be able to call contract.constructor().transact() without the suffix function name to deploy contract?

It's contract.deploy() that would be deprecated. Right, it would be replaced with contract.constructor().transact().

Hello.
Please, can you tell me, when I can get contract.constructor() in this pakage?
I try to use this with v 4.0.0b9, but face with error: AttributeError: type object 'Contract' has no attribute 'constructor'
As I understend, this functionality not implement in last build. :(

@savao within a couple weeks of #595 being merged.

Thank you very much!

Hi @zheli @carver how is this one going? CC @owocki

@vs77bb it will be merged soon.

Merged, and approved for bounty payout. Thanks @zheli !

__Work for 0.4 ETH (376.6 USD) has been submitted by__:

Submitters, please leave a comment to let the funder (and the other parties involved) that you've submitted you work. If you don't leave a comment, the funder may expire your submission at their discretion.

Was this page helpful?
0 / 5 - 0 ratings