[Contract] web3.eth.getAccounts, web3.eth.getCoinbase 使用場景區別


 

web3.eth.getAccounts() 返回節點控制的賬號列表(Promise returns Array)

web3.eth.getCoinbase() 返回挖礦獎勵所歸集的地址(Promise returns String)

 

根據字面意思很難知道 兩個函數 分別用在哪塊,下面給出具體解釋:

 

web3.eth.accounts[0] 用來獲取 MetaMask 當前所選的賬號,依據 Account List Reflects User Preference

使用時你還需要監聽 MetaMask 上選擇賬號的變化,以便更新你頁面展示的數據,依據 Listening for Selected Account Changes

 

web3.eth.getCoinbase 文檔的意思很明確,和當前選擇的賬號沒必然聯系。

值可能等於 web3.eth.accounts[0] 或者未定義,coinbase 可配置。(What is coinbase)

 

Ref:MetaMask Compatibility Guide # MetaMask as a light client Supported Methods

Ref:Difference between web3.eth.getCoinbase() and web3.eth.getAccounts()[0]

Link:https://www.cnblogs.com/farwish/p/12392389.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM