Back

blockchain - 使用metamask 以及对应的api

发布时间: 2022-01-06 08:48:00

参考:https://docs.metamask.io/guide/getting-started.html

metamask 作为firefox 或者chrome插件安装之后,会给window对象增加一个属性: ethereum  例如:

1. 判断metamask 是否安装

if (typeof window.ethereum !== 'undefined') {
  console.log('MetaMask is installed!');
}

对于以及安装过的的话,就打印,否则就返回undefined

2. 让当前用户进行登录

window.ethereum.request({ method: "eth_requestAccounts" })

Back