Development Documents
Get User Account Function
4 min
this documentation provides a detailed explanation of the getaccount function, which handles user account retrieval, login authentication, and interaction with the ethereum provider it includes asynchronous operations to ensure smooth and non blocking user experience function getaccount description the getaccount function checks if a user is logged in if not, it initiates the login process once the user is logged in, it retrieves the user's ethereum account the function also handles loading indicators and emits events upon successful account retrieval code async function getuserinfo() { try { // create a new user instance let user = new user(); // check if the user is logged in const islogin status = await user islogin(); console log(islogin status, 'islogin status'); if (!islogin status) { console log("login failed, please try again later"); return; } // if user is already logged in, interact with ethereum provider to get account let account = await user getaccount(); console log("getweb3 account", account); let userid = await user getuserid(); console log("getweb3 userid", userid); let result = await user balance() if (result && result balances && result balances length) { let temp = result balances\[0] let balance = temp / 1000000000000000000n console log("getweb3 balance ",balance) } } catch (error) { console log(error, "getuserinfo error"); if (error && typeof error == 'string') { console log(error); } else { console log(error message); } } } detailed explanation user object initialization creates a new instance of the user object check login status asynchronously checks if the user is logged in logs the login status handle not logged in status shows a loading toast if the user is not logged in user info process logs the account, userid, balance and any error error handling logs the error this setup ensures that the user account status is checked and handled as soon as the component is ready, providing a seamless experience for the user