How do I do the equivalent of web3.eth.getAccounts() for Nethereum?

1k Views Asked by At

I have this working in js to give me the address of the logged-in Metamask user, but I would like to do it using Nethereum. Could someone tell me the equivalent to this with Nethereum?

var accounts = await web3.eth.getAccounts();
console.log(accounts)
2

There are 2 best solutions below

0
On

for Nethereum right now we dont have any direct support that it can access Metamask , so in netherium you can only access account using private key or seed phrase

Like this below

 var account = new Account(privateKey);
 var publicAddressOfTheAboveAccount = account.Address;

Check the below link if you want to use metamask using Nethereum.Metamask.Blazor to access metamask account instance

checkthislink

3
On

This is impossible, because MetaMask is accessible only in the web frontend (JavaScript/TypeScript) and .NET does not run within a web browser.

To get the user address on the server side securely, you need to ask user to sign a message with MetaMask and then extract the address from the message signature.