我如何为 Nethereum 做相当于 web3.eth.getAccounts() 的工作?

问题描述

我在 js 中使用了这个来给我登录Metamask 用户的地址,但我想使用 Nethereum 来做。有人能告诉我 Nethereum 的等价物吗?

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

解决方法

对于 Nethereum 目前我们没有任何直接支持它可以访问 Metamask ,因此在 Netherium 中您只能使用私钥或种子短语访问帐户

像下面这样

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

如果您想通过 Nethereum.Metamask.Blazor 使用 metamask 访问 metamask 帐户实例,请检查以下链接

checkthislink

,

这是不可能的,因为 MetaMask 只能在 Web 前端(JavaScript/TypeScript)中访问,而 .NET 不能在 Web 浏览器中运行。

为了安全地在服务器端获取用户地址,需要让用户使用MetaMask对消息进行签名,然后从消息签名中提取地址。