Truffle: Access public variables - Error

Created on 27 Nov 2017  路  3Comments  路  Source: trufflesuite/truffle

  • [x] I've asked for help in the Truffle Gitter before filing this issue.

Issue

Hi, I'm running into a weird issue where I couldn't retrieve the value of a public variable in truffle console. It's a public variable used as a counter to track the number of records added. I spent almost a day troubleshooting it and found various issues which couldn't provide a logical justification.

Steps to Reproduce

Access a public variable of a contract in truffle console. Works for the first time but subsequent changes and compilation corrupts the compiled bytecode.

Expected Behavior

Return the public variable value after every compile.

truffle(development)> EcommerceStore.deployed().then(function (i) { i.productIndex.call().then(function (f) { console.log(f) }) })
undefined
truffle(development)> BigNumber { s: 1, e: 0, c: [ 0 ] }

Actual Results

Error when accessing the public variable value. It works for the first time and subsequent deployment breaks.

truffle(development)> EcommerceStore.deployed().then(function (i) { i.productIndex.call().then(function (f) { console.log(f) }) })
undefined
truffle(development)> (node:2353) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 26): Error: Invalid number of arguments to Solidity function

Environment

  • Operating System: Mac OS High Sierra
  • Truffle version: Truffle v4.0.1 (core: 4.0.1)
  • node version: v8.9.1
  • npm version: 5.5.1

Most helpful comment

Deleting the build directory and then deploying the contract fixes this issue. But I believe it's a workaround for this issue but not addressing the actual issue. Can we have a fix for this?

delete the build directory, then run
 truffle migrate --reset

All 3 comments

Deleting the build directory and then deploying the contract fixes this issue. But I believe it's a workaround for this issue but not addressing the actual issue. Can we have a fix for this?

delete the build directory, then run
 truffle migrate --reset

Asked this question on SO and it appears to be a common issue with Truffle, linked to #596. Workaround is to delete /build like @arunmitteam suggested. Works fine in Remix.

@arunmitteam We think this bug has been fixed in 4.1.5. Closing for housekeeping, if anyone sees this again please ping.

Was this page helpful?
0 / 5 - 0 ratings