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

truffle console doesn't work in v5 #1601

Closed
PaulRBerg opened this Issue Dec 30, 2018 · 10 comments

Comments

Projects
None yet
3 participants
@PaulRBerg
Copy link

PaulRBerg commented Dec 30, 2018

Issue

From the docs:

MyContract.at("0xabcd...").getValue.call();

However, there's no way to make this syntax work with truffle ^5.0.

Steps to Reproduce

$ git clone git@github.com:PaulRBerg/truffle-console-bug.git
$ cd truffle-console-bug
$ npm install
$ ganache-cli
$ truffle console --network development
$ compile
$ migrate

Now, either of the following comands will return an error:

  • Note.at("your-contract-address").getNumber.call()
  • await Note.at("your-contract-address").getNumber.call()

Expected Behavior

Return the number set on deployment, that is 64.

Actual Results

Error returned:

TypeError: Cannot read property 'call' of undefined
at evalmachine.:1:8

Environment

  • Operating System: macos
  • Ethereum client: 10.14.2
  • Truffle version (truffle version): 5.0.0
  • node version (node --version): 10.12.0
  • npm version (npm --version): 6.5.0
@PaulRBerg

This comment has been minimized.

Copy link
Author

PaulRBerg commented Dec 30, 2018

Switching to using just the new web3 1.0 Contract object works seamlessly:

let abi = require("./build/contracts/Note.json").abi;
let contract = new web3.eth.Contract(abi, "your-contract-address");
contract.methods.getNumber().call();

Just like with #1455, TruffleContract seems to be causing more trouble than good. I mean this in a constructive way, I'm very grateful for your work, but I do feel that there needs to be more standardisation in the blockchain space.

@gnidan

This comment has been minimized.

Copy link
Member

gnidan commented Dec 30, 2018

.at() is now async, so you have to do (await Note.at(...)).getValue.call()

Thanks for opening this. Will fix the docs (probably in the new year)

@eggplantzzz

This comment has been minimized.

Copy link
Contributor

eggplantzzz commented Jan 4, 2019

@gnidan Actually it seems like you can still do let number = MyContract.myValue.call() and the value of number will be a BN.

@eggplantzzz

This comment has been minimized.

Copy link
Contributor

eggplantzzz commented Jan 4, 2019

Oh my apologies, the call method will return the BN. Not at! I misread, gnidan is correct.

@eggplantzzz

This comment has been minimized.

Copy link
Contributor

eggplantzzz commented Jan 17, 2019

Is this issue still relevant? If not I will be considering closing this soon.

@eggplantzzz

This comment has been minimized.

Copy link
Contributor

eggplantzzz commented Jan 17, 2019

@PaulRBerg
Note: (haha get it? :P ) I tried to duplicate your error locally and couldn't. My steps were as follows:

truffle(develop)> let note = await Note.at("0x5040F5c3f1f01C23ad172F3293B466d4aD8E0263")
undefined
truffle(develop)> let num = await note.getNumber.call()
undefined
truffle(develop)> num
<BN: 40>
@PaulRBerg

This comment has been minimized.

Copy link
Author

PaulRBerg commented Jan 18, 2019

It is still relevant. I followed the exact steps I posted 19 days ago and I get the same error. Here's what I get when I do truffle version:

Truffle v5.0.1 (core: 5.0.1)
Solidity - 0.4.25 (solc-js)
Node v10.12.0

Maybe you're using a globally installed truffle v4?

@eggplantzzz

This comment has been minimized.

Copy link
Contributor

eggplantzzz commented Jan 21, 2019

@PaulRBerg I would not expect the syntax you are using to work. You need to execute those slightly differently. You need to "await" and receive the instance before calling getNumber.
You could do (await Note.at("your-contract-address")).getNumber.call() for example. As @gnidan said, the at method is async and in your example the getNumber method is attempting to be called before it receives the instance back.

@eggplantzzz

This comment has been minimized.

Copy link
Contributor

eggplantzzz commented Jan 30, 2019

@PaulRBerg Did you get your issue resolved?

@PaulRBerg

This comment has been minimized.

Copy link
Author

PaulRBerg commented Jan 30, 2019

Apologies, it's all good now. I don't know why I had the impression that I was awaiting Note.at. It would be good to annotate this behaviour with a warning in the docs because the old functionality was not using await.

Thanks for your help!

@PaulRBerg PaulRBerg closed this Jan 30, 2019

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