当前位置:网站首页>Web3js method to obtain account information and balance
Web3js method to obtain account information and balance
2022-07-02 20:23:00 【JackieDYH】
web3js file
web3 Browser check
if (typeof window.ethereum !== 'undefined') {
console.log('MetaMask is installed!');
}
- 1.
- 2.
- 3.
Get account information
// introduce
//<script src="./node_modules/web3/dist/web3.min.js"></script>
async function get(){
// Instantiation web3
window.web3 = new Web3(ethereum);
var web3 = window.web3;
// Request user authorization solve web3js Cannot be aroused directly Meta Mask Get user identity
const enable = await ethereum.enable();
console.log(enable,11)
// Authorize access to accounts
var accounts = await web3.eth.getAccounts();
// web3.eth.getAccounts().then((e)=>{console.log(e)})
// Take the first account
var myAccount = accounts[0];
console.log(myAccount, 1);
// Returns the balance of the account at the specified address
var balance = await web3.eth.getBalance(myAccount);
console.log(balance, 2)
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
边栏推荐
- CRM Customer Relationship Management System
- 在消费互联网时代,诞生了为数不多的头部平台的话
- 通信人的经典语录,第一条就扎心了……
- AcWing 1135. Happy New Year (shortest path + search)
- Driverless learning (III): Kalman filter
- 测试人员如何做不漏测?这7点就够了
- Development skills of rxjs observable custom operator
- 笔记本安装TIA博途V17后出现蓝屏的解决办法
- Google Earth engine (GEE) - Landsat 9 image full band image download (Beijing as an example)
- What are the preferential account opening policies of securities companies now? Is it actually safe to open an account online?
猜你喜欢
KT148A语音芯片ic的软件参考代码C语言,一线串口
【QT】QPushButton创建
面试经验总结,为你的offer保驾护航,满满的知识点
CRM Customer Relationship Management System
KT148A语音芯片ic的用户端自己更换语音的方法,上位机
Self-Improvement! Daliangshan boys all award Zhibo! Thank you for your paper
Wu Enda's machine learning mind mapping insists on clocking in for 23 days - building a knowledge context, reviewing, summarizing and replying
外包干了三年,废了...
sql-labs
测试人员如何做不漏测?这7点就够了
随机推荐
Exemple complet d'enregistrement du modèle pytoch + enregistrement du modèle pytoch seuls les paramètres d'entraînement sont - ils enregistrés? Oui (+ Solution)
for(auto a : b)和for(auto &a : b)用法
现在券商的优惠开户政策什么?实际上网上开户安全么?
[Chongqing Guangdong education] reference materials for labor education of college students in Nanjing University
Want to ask, is there any discount for opening an account now? Is it safe to open an account online?
Postman接口测试实战,这5个问题你一定要知道
Istio deployment: quickly start microservices,
【QT】QPushButton创建
笔记本安装TIA博途V17后出现蓝屏的解决办法
励志!大凉山小伙全奖直博!论文致谢看哭网友
How to realize the function of detecting browser type in Web System
Design and implementation of ks004 based on SSH address book system
Automatically generate VGg image annotation file
勵志!大凉山小夥全獎直博!論文致謝看哭網友
Implementation of online shopping mall system based on SSM
【Hot100】23. 合并K个升序链表
JASMINER X4 1U deep disassembly reveals the secret behind high efficiency and power saving
台湾SSS鑫创SSS1700替代Cmedia CM6533 24bit 96KHZ USB音频编解码芯片
【Hot100】23. Merge K ascending linked lists
面试经验总结,为你的offer保驾护航,满满的知识点