I am using Ganache CLI v6.1.0 (ganache-core: 2.1.0))
(started with default settings by running simply ganache-cli
), web3 (^1.0.0-beta.33)
, and my smart contract is written for solidity ^0.4.0
.
I have some functions working where I can, for instance, click a button on my web UI and have it send a transaction to my deployed smart contract and update the data on-chain. This works without any issue.
Strangely, the simple case of call
ing a constant
function (which simply returns the length of an array) is where I'm having issues. For some reason every time I do this I get an error: Key not found in database
. This error occurs in the promise returned by the call
invocation.
Here is my code:
Solidity function:
function getItemsLength() public constant returns(uint256) {
return items.length;
}
JS Code:
var account;
var numItems = 0;
web3.eth.getAccounts().then(function(result) {
account = result[0];
var contract = new web3.eth.Contract(
simpleStorageABI,
contractAddress,
{
from: account,
gasPrice: '20000000000',
gas: '100000'
}
)
contract.methods.getItemsLength().call(account) // Error occurs here
.then(function(result) {
numItems = result;
})
});
I had this working using testrpc instead of Ganache a few days ago, but then moved to Ganache for websocket support (for event listeners). Somewhere along the way this broke, and it seems like perhaps a bug in Ganache.
Has anyone else run into this? I saw some issues in my searching that seemed similar but they mostly seemed intermittent and related to testing specifically. Any insight or guidance would be appreciated, I've been stuck on this for too long.