• web3-引言之读取账户地址


    说明

    主要归纳下常见的web3学习网站以及如何通过web3读取账户地址。

    内容

    常见学习网站

    1 官网
    https://ethereum.org/en/

    2 以太实时区块网站
    https://etherscan.io/

    3 加密僵尸(以游戏的形式学习solidity的用法)
    https://cryptozombies.io/

    4 加密黑客(主要学习加密学知识的)
    https://cryptohack.org/challenges/

    5 基础入门web3教学
    http://www.codebaoku.com/web3/

    使用web3获取某地址的以太余额

    const Web3 = require("web3");
    const rpcURL = "https://kovan.infura.io/v3/xxxxxxxxxx"
    const web3 = new Web3(rpcURL)
    
    //检查账户余额
    const address = "0x7f101fe45e6649a6fb8f3f8b43ed03d353f2b90c";
    web3.eth.getBalance(address, (err, wei) => {
        debugger
        //余额单位从wei转换为ether
        balance = web3.utils.fromWei(wei, 'ether')
        console.log(balance)
    })
    
    //获取智能合约的javascript对象
    const abi = [{"constant":true,"inputs":[],"name":"mintingFinished","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_value","type":"uint256"}],"name":"approve","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[],"name":"unpause","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_amount","type":"uint256"}],"name":"mint","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"paused","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"balance","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[],"name":"finishMinting","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":false,"inputs":[],"name":"pause","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transfer","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_amount","type":"uint256"},{"name":"_releaseTime","type":"uint256"}],"name":"mintTimelocked","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"},{"name":"_spender","type":"address"}],"name":"allowance","outputs":[{"name":"remaining","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"type":"function"},{"anonymous":false,"inputs":[{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Mint","type":"event"},{"anonymous":false,"inputs":[],"name":"MintFinished","type":"event"},{"anonymous":false,"inputs":[],"name":"Pause","type":"event"},{"anonymous":false,"inputs":[],"name":"Unpause","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"},{"indexed":true,"name":"spender","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Transfer","type":"event"}]
    const address1 = "0xd26114cd6EE289AccF82350c8d8487fedB8A0C07"
    const contract = new web3.eth.Contract(abi, address1)
    console.log(contract)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
  • 相关阅读:
    Git Flow——项目开发中经典分支管理策略
    【软考软件评测师】第十五章 黑盒测试基础
    Tomcat的安装与使用,maven与Servlet的使用
    CSS层叠样式表
    c#基础0-类型、起步
    flutter 适配屏幕宽高工具
    【吴恩达机器学习笔记】八、应用机器学习的建议
    年薪50W的软件测试面试题,到底长啥样?
    【Spring Cloud】新闻头条微服务项目:实时创建ES索引并引入MongoDB实现搜索历史记录及关键词联想
    js 对象循环遍历
  • 原文地址:https://blog.csdn.net/wangbiao9292/article/details/125511185