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.
Attempt 1 - using the default getter did not work.
// public variable name
uint public productIndex;
// using the default getter method did not work
EcommerceStore.deployed().then(function (i) { i.productIndex.call().then(function (f) { console.log(f) }) })
Attempt 2 - I wrote a new function in my original smart contract to return the value of the variable - did not work.
// public variable name
uint public productIndex;
EcommerceStore.deployed().then(function (i) { i.getProdCount().then(function (f) { console.log(f) }) });
Attempt 3 - I renamed the variable and tried to return the value from the new function - did not work.
// public variable name
uint public productIndex1;
// not working without parameter
EcommerceStore.deployed().then(function (i) { i.getProdCount().then(function (f) { console.log(f) }) });
Attempt 4 - Renamed the variable and tried to return it from a function with dummy input parameter and it worked.
// public variable name
uint public productIndex1;
// working with parameter
EcommerceStore.deployed().then(function (i) { i.getProdCount(0).then(function (f) { console.log(f) }) });
I couldn't understand what's going on. I can do a screen share or put together a video for someone to review. Again not sure if it's truffle issue or testrpc issue. How can I go get this fixed? Who can help me understand this issue? The same contract works on remix and I'm able to get the public variable method.
build/
directory and redeploy the contracts (truffle migrate --reset
). Sometimes contract artifacts get corrupted and truffle acts in strange ways.