How Check Wallet number on fly!

Hi, i do project
When user connect wallet I can get wallet number through var wallet = user.get(‘ethAddress’);
And Moralis will remember this!
But if user will switch account on metamask user.get(‘ethAddress’); will return old address …
but i wish make double check that they pay from same address with was on login time!
Other way mined NFT will go for address wrong address.
or how i can send payment request and switch metamask automatically to address what was stored at login time in user.get(‘ethAddress’);

Thanks in advance and thatks for Moralis - Great project!

You can check current address that is selected in MetaMask with web3, for example after you use Moralis.enableWeb3().
There could be cases when the user wants to do the transaction with a different address and not the one that was used at authentication.

Yep i was thinking same, probably i do something wrong

Every time when i load page i use

before payment
do again
var wallet = user.get(‘ethAddress’);
and i get “wallet” what was used on login time (connecting wallet to page), not current what is open on metamask.
Then i ask for payment from my smart contract …

const options3 = {
chain: ChainName,
contractAddress: SmartContract,
functionName: “mint”,
abi: ABI,
msgValue: Moralis.Units.ETH(PriceToPay),
params: {_to: wallet, _count: NftToMint},
awaitReceipt: false

const mint = await Moralis.executeFunction(options3);

You have to access the address from MetaMask with a different syntax

For example:

 const accounts = web3.eth.getAccounts()
  const account = await accounts[0]

I get workable with
const accounts = await ethereum.request({ method: ‘eth_accounts’ });
is this correct?

It is an equivalent syntax

1 Like

Thanks for help!
But i have one more question. but i think better open new topic!