0

I have updated my truffle version to the latest v5.0.3. By running truffle version, I can get the following version statements.

Truffle v5.0.3 (core: 5.0.3)
Solidity v0.5.0 (solc-js)
Node v10.8.0

However, this update stops me from executing some tutorials that were supposed to work. Especially, the ZOS tutorial at https://docs.zeppelinos.org/docs/upgrading.html, when running commands myContract.x().toString() in Truffle Console. Instead of showing a numerical result, the console kept showing undefined. The same problem happened for the case of running myContract.s().

I am not sure whether the problem comes from a different use of cli command sets across versions. It took me hours to fix it. Therefore, if you encountered similar problems, I wish it can save you time.

  • 1
    The expression myContract.x() should return a promise, which when resolved, yields a BigNumber instance (or on Truffle 5, possibly a BN instance, due to the upgrade of web3 version). I'm not sure why this works for you on Truffle 4, but you should generally resolve the promise before calling toString(). You can do this, for example, with (await myContract.x()).toString(). – goodvibration Feb 6 at 9:51
  • @goodvibration Thanks for the great comment. That's right. The promise can be successfully returned when at Truffle v4, but it failed at Truffle v5 which turned out to return undefined constantly. – Jeff Hu Feb 6 at 10:59
  • @goodvibration I tried out (await myContract.x()).toString(), which returned TypeError: myContract.x is not a function. And (await myContract.x) returned undefined. Interesting haha. – Jeff Hu Feb 6 at 11:05
  • Try myContract.methods.x. Truffle 5.x relies on web3 1.x, which dictates this syntax. – goodvibration Feb 6 at 11:16
1
  1. The expression myContract.x() returns a promise, which when resolved, yields a BigNumber instance. You should generally resolve the promise before calling toString(). You can do this, for example, with (await myContract.x()).toString().
  2. When you upgrade Truffle version from 4.x to 5.x, the underlying Web3 version is subsequently upgraded from 0.x to 1.x. This version of Web3 dictates the syntax myContract.methods.myFunc(), so you should use myContract.methods.x().
0

I downgrade the Truffle version to the stable version of v4. And everything works like usual.

Reinstall Truffle

npm uninstall -g truffle
npm i -g truffle@4

Check Truffle Version

truffle version

which will return

Truffle v4.1.15 (core: 4.1.15)
Solidity v0.4.25 (solc-js)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.