web3 / web3.js

Collection of comprehensive TypeScript libraries for Interaction with the Ethereum JSON RPC API and utility functions.
https://web3js.org/
Other
19.18k stars 4.91k forks source link

Disable caching of eth_call requests #1463

Closed melnikaite closed 5 years ago

melnikaite commented 6 years ago

I have following code

        contractInstance.methods.read().call().then(items => {
          this.items = items // sometimes cached
        })

Sometimes I'm getting cached items. When it happens I don't see eth_call in Ganache log.

Workaround

        contractInstance.methods.read().call({
          gas: gas // random gas
        }).then(items => {
          this.items = items // always correct
        })

Ganache 1.0.2 Web3 1.0.0-beta.31 Node v9.2.1 OS X 10.13.3

gburtini commented 6 years ago

I believe a call is implemented as a local simulation. If it is cached, as long as the cache expires per block, that should be sufficient. I assume you're saying the cache does not expire per block in at least some circumstances.

Can you post the ABI for your read method?

melnikaite commented 6 years ago

Sure

    {
      "constant": true,
      "inputs": [],
      "name": "read",
      "outputs": [
        {
          "name": "_items",
          "type": "bytes32[]"
        }
      ],
      "payable": false,
      "stateMutability": "view",
      "type": "function"
    }
showmeyourcode commented 6 years ago

Was facing the same issue even after restarting GANACHE and redeploying the smart contract several times using truffle. Sending random gas trick mention by @melnikaite worked for me.

web3 : 1.0.0-beta.34 Ganache : 1.1.0 OS : Mac OS X El Capitan (10.11) react : 16.3.2 Metamask : 4.5.5

nivida commented 5 years ago

This is an issue of ganache and you should open it there.