簡體   English   中英

web3.eth.getAccounts(); 當前不工作

[英]web3.eth.getAccounts(); current not working

我在來自 Ganache 的 Metamask 上設置了五個帳戶。

我選擇了一個有 1000 個測試以太幣的。

但...

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

accounts始終是長度為 1 的數組。

這是為什么?

此外,數組中的帳戶是第一個帳戶,而不是當前選擇的帳戶。

有什么我想念的嗎?這是如何工作的? 謝謝。

Metamask 讓您只連接一個帳戶,因此您的帳戶數組的長度始終為 1。 請參閱此主題: https://github.com/MetaMask/metamask-extension/issues/5607

您需要在 Metamask 中更改帳戶后重新加載頁面,以便考慮或處理第三個答案中建議的更改帳戶事件: https://ethereum.stackexchange.com/a/63823

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM