47

请问 Web.js 钱包怎么获得 Dapp 的授权? | 登链社区 | 技术问答

 3 years ago
source link: https://learnblockchain.cn/question/2399
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

50 请问 Web.js 钱包怎么获得 Dapp 的授权?

程序前端是 Vue 打包的 Dapp,通过浏览器打开 Dapp ,这个时候链接钱包会弹出授权,或者我看 Imtoken 是用 Dapp 直接获得授权,请问应该如何实现 钱包和Dapp 的直接链接?

最佳答案 5天前

使用 ethereum.enable() 请求授权:

try {
        await window.ethereum.enable();
      } catch (error) {
        console.error("User denied account access");
      }

构造出 new Web3(window.ethereum) 对象后,就可以用web3 相关的 API 与钱包交互。

Tiny熊 - 布道者
擅长:智能合约,以太坊 | 采纳率 39% | 回答于 5天前

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK