0

Here is my code in which error is coming please help me out.

initContract: function () {
    $.getJSON('Election.json', function (data) {
      // Get the necessary contract artifact file and instantiate it with truffle-contract
      var ElectionArtifact = data;
      App.contracts.Election = TruffleContract(ElectionArtifact);

      // Set the provider for our contract
      App.contracts.Election.setProvider(App.web3Provider);

      // Listen for events in the contract
      App.listenForEvents();

      web3.currentProvider.publicConfigStore.on('update', function (result) {
        if (result.selectedAddress != App.yourAddress) {
          location.reload();
        }

      });

      return App.showResult();
    });
    return App.bindEvents();
  },

error in console is:

Uncaught TypeError: Cannot read property 'on' of undefined
4
  • The only place where on is used is here web3.currentProvider.publicConfigStore.on(.. the error means web3.currentProvider.publicConfigStore is undefined, or it was never initialized properly.
    – Ismael
    Jun 15 at 3:28
  • @Ismael then what should I do to rectify this error. Jun 22 at 6:54
  • From the MetaMask documentation about removal of ethereum.publicConfigStore you have to update the code to replace it with a new api, probably ethereum.on('accountsChanged', handleAccountsChanged);.
    – Ismael
    Jun 22 at 22:48
  • Perhaps this should help ethereum.stackexchange.com/questions/42768/…
    – Ismael
    Jun 23 at 16:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.