async function get(){ // 实例化web3 window.web3 = new Web3(e_web3j.js 切换小狐狸钱包地址">
赞
踩
- if (typeof window.ethereum !== 'undefined') {
- console.log('MetaMask is installed!');
- }
- // 引入
- //<script src="./node_modules/web3/dist/web3.min.js"></script>
- async function get(){
- // 实例化web3
- window.web3 = new Web3(ethereum);
- var web3 = window.web3;
- // 请求用户授权 解决web3js无法直接唤起Meta Mask获取用户身份
- const enable = await ethereum.enable();
- console.log(enable,11)
- // 授权获取账户
- var accounts = await web3.eth.getAccounts();
- // web3.eth.getAccounts().then((e)=>{console.log(e)})
- // 取第一个账户
- var myAccount = accounts[0];
- console.log(myAccount, 1);
- // 返回指定地址账户的余额
- var balance = await web3.eth.getBalance(myAccount);
- console.log(balance, 2)
- }

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。