I want to change the connected wallet addres in moralis if user manually changes and connects different address to the web app using a wallet. How can I achieve this?
Hey @testdev9674
Take a look at https://docs.moralis.io/moralis-server/web3/web3#linking
Does this solve your issue?
Hey @Yomoo
Getting this error
this auth is already used
My code
useEffect(() => {
Moralis.Web3.onAccountsChanged(async function (accounts) {
const confirmed = confirm('Link this address to your account?');
if (confirmed) {
await Moralis.Web3.link(accounts[0]);
alert('Address added!');
}
});
}, []);```
if there was an user already associated with that new address, then maybe you’ll have to logout current user and login with new address
linking works when you want to add a new address to current account
Hey @cryptokid can suggest a method which will tell if there is a user associated with the new address?
you can use a cloud function where you can check if current address is already associated with a user, you will need to use master key
I ran into the same issue today and I in my case just logging them out when they change accounts seems to work best.
So I ran into a problem during testing where I started from a fresh browser, ran through the MetaMask onboarding functions (programmatically from my dApp UI), but that created a fresh blank MetaMask address. I’d logged into my usual Moralis account and it absorbed the new address to the top of the array.
Normally great. Except my UI isn’t equipped to handle an array of user addresses, just a scalar. So it started displaying all my portfolio holdings as blank, because it defaults to address[0].
So I’m looking for a Moralis function to update address[0] to the currently connected wallet address and Moralis does not have a function to do that. Put in my vote for you guys to develop one.
I was able to fix my Moralis user record in the server dashboard with my admin credentials. But it shouldn’t be manual. I need to put a button in the User Profile panel to “Update wallet address to current.”
Thanks.