1

I was using the following method to access the selected account on metamask through web3 v1:

  //metamask method that refresh the active account in the web
    this.web3.currentProvider.publicConfigStore.on('update',async function(event){
      this.setState({
        account: event.selectedAddress.toLowerCase()
      },()=>{
        this.load();
      });
    }.bind(this));

And everything was working fine, it seems that a new update happened and this is no longer available. Any suggestions?

Thanks

2

Use accountsChanged event:

  /**
   * Listening for MetaMask address changes.
   * @param  {Function} callback Resolve when address is changed
   */
   function onAccountsChanged(callback) {
     ethereum.on('accountsChanged', (accounts) => {
       // Time to reload your interface with accounts[0]
       console.log(accounts);

       callback(null, accounts[0]);
     });
   }
| improve this answer | |
1

test this change on account:

this.web3.currentProvider.publicConfigStore.on('update',async function(event){
  this.setState({
    account: this.web3.currentProvider.selectedAddress.toLowerCase()
  },()=>{
    this.load();
  });
}.bind(this));
| improve this answer | |

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.