Moralis.Web3.onAccountsChanged() in React Moralis

Im using react-moralis and noticed a few inconsistencies between it and the Moralis documentation.

This hasn’t been too bad for the most part as I can figure it out. However, I can’t seem to find the functionality for onAccountsChanged() for setting up listeners to either change or link accounts from Metamask.

I may resort to using the window Ethereum object, however will require overriding a lot of the account logic provided by Moralis.

Am I missing something, or is there a better way to go about this?

1 Like

You can check this link for events such as onAccountsChanges() : https://docs.moralis.io/moralis-server/web3/web3-1#events from moralis documentation.

Also, would be nice if you can list down the inconsistencies in our documentation if there are any.

1 Like

onAccountsChanged() doesn’t exist on the web3 object returned by useMoralis() in react-moralis

1 Like

Hey @ccoyotedev

You should import Moralis from useMoralis()

import { useMoralis } from "react-moralis";

function App() {
  const { Moralis } = useMoralis();

  const unsubscribe = Moralis.Web3.onAccountsChanged(function(accounts) {
  console.log(account);
 });
}
3 Likes