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

Suggestion: make truffle-contract more strict when interacting with its methods #1455

Open
PaulRBerg opened this Issue Nov 23, 2018 · 6 comments

Comments

Projects
None yet
3 participants
@PaulRBerg
Copy link

PaulRBerg commented Nov 23, 2018

Scenario

Let's say we have a contract instance myContractInstance and methods myPureMethod and myStateMethod.

Using truffle 5.0.0.beta.2, I can do the following in my test files:

await myContractInstance.myPureMethod(...params);
await myContractInstance.contract.methods.myPureMethod(...params).call();

And also:

await myContractInstance.myStateMethod(...params);
await myContractInstance.contract.methods.myStateMethod(...params).send();

What is the recommended way to interact with the contract? According to the docs, the latter seems to be the newest api of web3 1.0.0. If that's so, why can we still do the former? Backwards compatibility?

It's confusing because there are many examples on StackExchange and on many other websites showing a ton of different ways to achieve the same thing. More often than not, standardisation is a good thing.

Related Issues

Environment

  • Operating System: macOS 10.14
  • Ethereum client: ganache 1.2.2
  • Truffle version: 5.0.0.beta.2
  • node version: 10.12.0
  • npm version: 6.4.1
@PaulRBerg

This comment has been minimized.

Copy link
Author

PaulRBerg commented Nov 23, 2018

Update

After doing more investigation, I now understand that truffle-contract was developed in the first place to have a promise-based version of the old callback-based Contract class found in the 0.20.6 version of the web3 library.

As web3 ^1.0.0 implemented Promises and PromiEvents, wouldn't it make sense to nuke out truffle-contract? At least for me, the process of upgrading to truffle ^5.0.0 has been highly problematic specifically because of this inconsistency.

Practically speaking, I posit that there would be much less confusion if Truffle injects web3.eth.Contract instances when running js tests.

@adrianmcli

This comment has been minimized.

Copy link
Member

adrianmcli commented Dec 8, 2018

This makes a lot of sense, I'll try to bring this up with the team.

@stale

This comment has been minimized.

Copy link

stale bot commented Feb 6, 2019

Thank you for raising this issue! It has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. If you would like to keep this issue open, please respond with information about the current state of this problem.

@stale stale bot added the stale label Feb 6, 2019

@gnidan

This comment has been minimized.

Copy link
Member

gnidan commented Feb 13, 2019

not stale

@stale

This comment has been minimized.

Copy link

stale bot commented Feb 13, 2019

Thanks for your response! This issue is no longer considered stale and someone from the Truffle team will try to respond as soon as they can.

@stale stale bot removed the stale label Feb 13, 2019

@gnidan gnidan added the Docs label Feb 13, 2019

@gnidan

This comment has been minimized.

Copy link
Member

gnidan commented Feb 13, 2019

(I'm calling this a documentation issue only. The docs should be more clear on .myMethod vs. .methods.myMethod)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment