Search code examples
ethereumsmartcontractsweb3js

Does using call(..) perform network activity?


When using web3's [contract].[method].call(..), does web3 perform network activity to fetch the contract's latest state? Or is it always up-to-date with new blocks so no fetching is needed? Does it depend on the provider? if so, what's the policy with MetaMask?


Solution

  • That code invokes the eth_call JSON-RPC method on the node you're using as your provider. If the node is located on the same computer, then there's no external network activity. (The call is likely made over a websocket or HTTP, so it's sort of a network call, but nothing is leaving the computer.)

    If you're using an external node, e.g. Infura (the default provider MetaMask connects to), then there is external network activity to send the request to that node and receive the response.