I am in need of the current connected walletâs address for use within a smart contract read function.
I am trying to call a smart contract read function with:
function ViewUserDeposits() {
const { runContractFunction, data, error, isLoading, isFetching } =
useApiContract({
address: contrAddress,
functionName: "getUserDepositHistory",
chain: "mumbai",
abi: Abi,
params: {
_user: account,
_numBack: 1,
},
});
useEffect(() => {
const interval = setInterval(() => {
runContractFunction();
}, 4000);
return () => clearInterval(interval);
}, []);
return; //setting this to "return account;" will show the wallet address correctly wherever ViewUserDeposits() is rendered
}
My problem is within the params option in ViewUserDeposits(), I require sending the users wallet address for â_userâ.
params: {
_user: account,
_numBack: 1,
},
I can render the address by using âaccountâ from
const { authenticate, isAuthenticated, account, chainId, logout } =
useMoralis();
By calling {account} in html i get a 0x address to display. The âaccountâ does contain the address i need but when i use it in the parameters of the function it doesnât return anything. It does however work if i manually hardcode the 0x address instead of using a variable like account. I have tried sending account into the parameters of the ViewUserDeposits (ViewUserDeposits(account)) function and using it from there but i get the same results.
Have tried making changes to the âaccountâ such as JSON.stringify(), toLowerCase(), and Removing quotes (with .replace(/[â"]+/g, ââ) ). These all some to do the trick when displaying the address on the page but there is no change when used in the function.
Have also tried using
const { Moralis } = useMoralis();
Moralis.User.current().get("ethAddress");
Although whenever I try this approach I cannot get the address to display and the page doesnât render.