用戶帳戶在以太坊的各種環境中使用,包括作為識別符號和用于簽署交易,
首先需要判斷用戶瀏覽器有沒有安裝Metamask插件
if (typeof window.ethereum.isMetaMask === 'undefined') {
alert('看起來您需要一個 Dapp 瀏覽器才能開始使用,')
alert('請安裝 MetaMask!')
}
如果用戶沒有安裝,提示他安裝,否則無法繼續使用,
下一步 我們 請求狐貍錢包,訪問賬戶,獲取當前地址
ethereum.request({ method: 'eth_requestAccounts' }).catch(function (reason) {
alert('哦!NO, 好像發生了點意外,別著急, 我們很快修復它');
}).then(function (accounts) {
console.log('account',accounts);
拿到地址之后,賦值給我們的頁面
const account = accounts[0]
//alert('登錄成功');
console.log("success");
$("#login-address").html("賬戶地址"+account);
作者接區塊鏈開發,智能合約開發,聯系 QQ80164590
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/293412.html
標籤:區塊鏈
