I'm trying to incorporate storage in a smart contract where participants of the contract will have their address stored in a address[]
look up table participationAddressLUT
.
The contract initializes with 2 addresses in the look up table via the function bootstrapParticipation()
. The participationSize()
getter gives us the size of the look up table.
However when trying to retrieve the size of the lookup table using web3 v0.20.2
TokenSale.at(this.state.contractAddress).then((instance) => {
instance.participationSize.call().then((r) => {
console.log('participationSize: ', r)
})
})
we get the cryptic error
Uncaught (in promise) Error: Error: VM Exception while executing eth_call: invalid opcode
What is wrong with the current contract code that prevented this from working?
Contract code:
pragma solidity ^0.4.15;
import "./libs/zeppelin/crowdsale/CappedCrowdsale.sol";
import "./libs/zeppelin/crowdsale/FinalizableCrowdsale.sol";
contract TokenSale is CappedCrowdsale, FinalizableCrowdsale {
mapping (address => uint256) public participationWeis;
address[] public participationAddressLUT;
function TokenSale(uint256 _startTime, uint256 _endTime, uint256 _rate, uint256 _goal, uint256 _cap, address _wallet, address _tokenContractAddress)
CappedCrowdsale(_cap)
FinalizableCrowdsale()
Crowdsale(_startTime, _endTime, _rate, _wallet)
{
bootstrapParticipation();
}
function bootstrapParticipation() internal {
address participant = 0xcede48d8ac162d1b08ed9419010de3c99f2cfdd6;
uint256 weiAmount = 1000000;
participationWeis[participant] = participationWeis[participant].add(weiAmount);
participationAddressLUT.push(participant);
participant = 0x854bd635fd4e8684a326664e0698c8fefae6dd97;
weiAmount = 5000000;
participationWeis[participant] = participationWeis[participant].add(weiAmount);
participationAddressLUT.push(participant);
}
function participationSize() public returns (uint256) {
return participationAddressLUT.length;
}
}
Full Traceback
errors.js:35 Uncaught (in promise) Error: Error: VM Exception while executing eth_call: invalid opcode
at C:\Users\y\AppData\Roaming\npm\node_modules\truffle\build\chain.bundled.js:48863:17
at C:\Users\y\AppData\Roaming\npm\node_modules\truffle\build\chain.bundled.js:60103:5
at C:\Users\y\AppData\Roaming\npm\node_modules\truffle\build\chain.bundled.js:12319:9
at C:\Users\y\AppData\Roaming\npm\node_modules\truffle\build\chain.bundled.js:8879:16
at replenish (C:\Users\y\AppData\Roaming\npm\node_modules\truffle\build\chain.bundled.js:9399:25)
at iterateeCallback (C:\Users\y\AppData\Roaming\npm\node_modules\truffle\build\chain.bundled.js:9389:17)
at C:\Users\y\AppData\Roaming\npm\node_modules\truffle\build\chain.bundled.js:9364:16
at C:\Users\y\AppData\Roaming\npm\node_modules\truffle\build\chain.bundled.js:12316:13
at C:\Users\y\AppData\Roaming\npm\node_modules\truffle\build\chain.bundled.js:60099:9
at C:\Users\y\AppData\Roaming\npm\node_modules\truffle\build\chain.bundled.js:54779:7
at C:\Users\y\AppData\Roaming\npm\node_modules\truffle\build\chain.bundled.js:48863:17
at C:\Users\y\AppData\Roaming\npm\node_modules\truffle\build\chain.bundled.js:60103:5
at C:\Users\y\AppData\Roaming\npm\node_modules\truffle\build\chain.bundled.js:12319:9
at C:\Users\y\AppData\Roaming\npm\node_modules\truffle\build\chain.bundled.js:8879:16
at replenish (C:\Users\y\AppData\Roaming\npm\node_modules\truffle\build\chain.bundled.js:9399:25)
at iterateeCallback (C:\Users\y\AppData\Roaming\npm\node_modules\truffle\build\chain.bundled.js:9389:17)
at C:\Users\y\AppData\Roaming\npm\node_modules\truffle\build\chain.bundled.js:9364:16
at C:\Users\y\AppData\Roaming\npm\node_modules\truffle\build\chain.bundled.js:12316:13
at C:\Users\y\AppData\Roaming\npm\node_modules\truffle\build\chain.bundled.js:60099:9
at C:\Users\y\AppData\Roaming\npm\node_modules\truffle\build\chain.bundled.js:54779:7
at Object.InvalidResponse (http://localhost:3000/static/js/bundle.js:94294:17)
at http://localhost:3000/static/js/bundle.js:90537:37
at XMLHttpRequest.request.onreadystatechange (http://localhost:3000/static/js/bundle.js:59860:8)