Itâs shorthand for
if (!Moralis.Web3.isWeb3Enabled) { Moralis.Web3.enableWeb3(); }
and so on.
So:
import { useMoralis } from "react-moralis";
import { useState, useEffect } from "react";
export const Balance = () => {
const [balanceETH, setBalanceETH] = useState();
const { enableWeb3, Moralis } = useMoralis();
useEffect(() => {
function fetchBalance() {
enableWeb3().then(setBalanceETH(Moralis.User.getERC20()));
}
fetchBalance();
}, [Moralis.User, enableWeb3]);
return <>Balance: {balanceETH} ETH</>;
};
Which would be beautifulâŚexcept:
TypeError: Moralis.User.getERC20 is not a function
I have indeed read the react-moralis docs both on npm and on GitHub. The documentation is new so itâs written for experts in the project, which I obviously ainât. There are things missing like const { Moralis } = useMoralis()
. And there are things âoverstatedâ like "getERC20()
is a function of User" (that one I heard around here, also not in the docs). Thereâs no listing of simple practical functions like âhow do I get my end userâs ETH balance?â Expert writerâs canât comprehend the totality of disorientation noobs like me really experience. So I hope Iâm contributing at least that much perspective. Stairways to heaven are lovely, but they need to touch Earth somewhereâŚ
Per your suggestion Iâm rummaging through the actual code now to see whatâs REALLY in the tin.
Day 3 of âuse Moralis, itâs plug-and-playâ and I havenât got a reliable âfetch my ETH balanceâ function working yet in React. But to be fair most my struggle is with React.