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.
Access a public variable of a contract in truffle console. Works for the first time but subsequent changes and compilation corrupts the compiled bytecode.
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 ] }
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
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.
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?