web3.js链接以太坊并查询钱包USDT余额

  • 环境:
  • 一、链接以太坊主网:
  • 二、创建一个ABI
    • 那么该如何获取ABI?
  • 三、查询代码
  • 四、输出结果
  • 五、整体代码

环境:

web3.js版本:6.14.15
不会安装以及使用web3.js的小伙伴看:https://blog.csdn.net/qq_45844443/article/details/124330035

一、链接以太坊主网:

  1. 获取以太坊的链接地址(也就是以太坊官网的主网链接)
    获取地址: https://chainlist.org/.
  2. 创建一个js文件并且创建"providers",填上刚才随意取得的主网链接.
let Web3 = require('web3');
var web3 = new Web3(new Web3.providers.HttpProvider("https://rpc.flashbots.net"));

二、创建一个ABI

那么该如何获取ABI?

  1. 有过交易的信息,上面都会显示交易的合约地址,我们找到后直接复制下来
    随便找一个以太坊账户查询的网址,查找该账户的交易信息,并找到合约地址
    给你们推荐一个:https://www.yitaifang.com/accounts/.
    直接右上角查询账户地址,找到里面随意一个USDT的交易并复制下来该合约地址

  2. 通过合约地址查询该ABI
    查询合约地址的AB链接 :https://etherscan.io/
    复制的合约地址通过该页面查询



    获取了相应的ABI后,创建个变量
var abi=...
//太长了,就不全部贴出来了

三、查询代码

var tokenContract = new web3.eth.Contract(abi, '0xdac17f958d2ee523a2206206994597c13d831ec7'); //第二个参数是刚才复制查询的ABI的合约地址
tokenContract.methods.balanceOf('0x5041ed759dd4afc3a72b8192c143f72f4724081a').call({from: '0x5041ed759dd4afc3a72b8192c143f72f4724081a'}, function (error, result) {console.log(error);console.log(result);console.log(web3.utils.fromWei(result, 'mwei')); //转换成mwei是因为wei与USDT的数量转化比为"1:1000000"
});
//new web3.eth.Contract(abi, '刚才复制查询的ABI的合约地址')
//balanceOf('查询的账号地址')
//{form:'查询的账号地址'}

四、输出结果

五、整体代码

let Web3 = require('web3');
var web3 = new Web3(new Web3.providers.HttpProvider("https://rpc.flashbots.net"));var abi = [{"constant": true,"inputs": [],"name": "name","outputs": [{"name": "", "type": "string"}],"payable": false,"stateMutability": "view","type": "function"
}, {"constant": false,"inputs": [{"name": "_upgradedAddress", "type": "address"}],"name": "deprecate","outputs": [],"payable": false,"stateMutability": "nonpayable","type": "function"
}, {"constant": false,"inputs": [{"name": "_spender", "type": "address"}, {"name": "_value", "type": "uint256"}],"name": "approve","outputs": [],"payable": false,"stateMutability": "nonpayable","type": "function"
}, {"constant": true,"inputs": [],"name": "deprecated","outputs": [{"name": "", "type": "bool"}],"payable": false,"stateMutability": "view","type": "function"
}, {"constant": false,"inputs": [{"name": "_evilUser", "type": "address"}],"name": "addBlackList","outputs": [],"payable": false,"stateMutability": "nonpayable","type": "function"
}, {"constant": true,"inputs": [],"name": "totalSupply","outputs": [{"name": "", "type": "uint256"}],"payable": false,"stateMutability": "view","type": "function"
}, {"constant": false,"inputs": [{"name": "_from", "type": "address"}, {"name": "_to", "type": "address"}, {"name": "_value","type": "uint256"}],"name": "transferFrom","outputs": [],"payable": false,"stateMutability": "nonpayable","type": "function"
}, {"constant": true,"inputs": [],"name": "upgradedAddress","outputs": [{"name": "", "type": "address"}],"payable": false,"stateMutability": "view","type": "function"
}, {"constant": true,"inputs": [{"name": "", "type": "address"}],"name": "balances","outputs": [{"name": "", "type": "uint256"}],"payable": false,"stateMutability": "view","type": "function"
}, {"constant": true,"inputs": [],"name": "decimals","outputs": [{"name": "", "type": "uint256"}],"payable": false,"stateMutability": "view","type": "function"
}, {"constant": true,"inputs": [],"name": "maximumFee","outputs": [{"name": "", "type": "uint256"}],"payable": false,"stateMutability": "view","type": "function"
}, {"constant": true,"inputs": [],"name": "_totalSupply","outputs": [{"name": "", "type": "uint256"}],"payable": false,"stateMutability": "view","type": "function"
}, {"constant": false,"inputs": [],"name": "unpause","outputs": [],"payable": false,"stateMutability": "nonpayable","type": "function"
}, {"constant": true,"inputs": [{"name": "_maker", "type": "address"}],"name": "getBlackListStatus","outputs": [{"name": "", "type": "bool"}],"payable": false,"stateMutability": "view","type": "function"
}, {"constant": true,"inputs": [{"name": "", "type": "address"}, {"name": "", "type": "address"}],"name": "allowed","outputs": [{"name": "", "type": "uint256"}],"payable": false,"stateMutability": "view","type": "function"
}, {"constant": true,"inputs": [],"name": "paused","outputs": [{"name": "", "type": "bool"}],"payable": false,"stateMutability": "view","type": "function"
}, {"constant": true,"inputs": [{"name": "who", "type": "address"}],"name": "balanceOf","outputs": [{"name": "", "type": "uint256"}],"payable": false,"stateMutability": "view","type": "function"
}, {"constant": false,"inputs": [],"name": "pause","outputs": [],"payable": false,"stateMutability": "nonpayable","type": "function"
}, {"constant": true,"inputs": [],"name": "getOwner","outputs": [{"name": "", "type": "address"}],"payable": false,"stateMutability": "view","type": "function"
}, {"constant": true,"inputs": [],"name": "owner","outputs": [{"name": "", "type": "address"}],"payable": false,"stateMutability": "view","type": "function"
}, {"constant": true,"inputs": [],"name": "symbol","outputs": [{"name": "", "type": "string"}],"payable": false,"stateMutability": "view","type": "function"
}, {"constant": false,"inputs": [{"name": "_to", "type": "address"}, {"name": "_value", "type": "uint256"}],"name": "transfer","outputs": [],"payable": false,"stateMutability": "nonpayable","type": "function"
}, {"constant": false,"inputs": [{"name": "newBasisPoints", "type": "uint256"}, {"name": "newMaxFee", "type": "uint256"}],"name": "setParams","outputs": [],"payable": false,"stateMutability": "nonpayable","type": "function"
}, {"constant": false,"inputs": [{"name": "amount", "type": "uint256"}],"name": "issue","outputs": [],"payable": false,"stateMutability": "nonpayable","type": "function"
}, {"constant": false,"inputs": [{"name": "amount", "type": "uint256"}],"name": "redeem","outputs": [],"payable": false,"stateMutability": "nonpayable","type": "function"
}, {"constant": true,"inputs": [{"name": "_owner", "type": "address"}, {"name": "_spender", "type": "address"}],"name": "allowance","outputs": [{"name": "remaining", "type": "uint256"}],"payable": false,"stateMutability": "view","type": "function"
}, {"constant": true,"inputs": [],"name": "basisPointsRate","outputs": [{"name": "", "type": "uint256"}],"payable": false,"stateMutability": "view","type": "function"
}, {"constant": true,"inputs": [{"name": "", "type": "address"}],"name": "isBlackListed","outputs": [{"name": "", "type": "bool"}],"payable": false,"stateMutability": "view","type": "function"
}, {"constant": false,"inputs": [{"name": "_clearedUser", "type": "address"}],"name": "removeBlackList","outputs": [],"payable": false,"stateMutability": "nonpayable","type": "function"
}, {"constant": true,"inputs": [],"name": "MAX_UINT","outputs": [{"name": "", "type": "uint256"}],"payable": false,"stateMutability": "view","type": "function"
}, {"constant": false,"inputs": [{"name": "newOwner", "type": "address"}],"name": "transferOwnership","outputs": [],"payable": false,"stateMutability": "nonpayable","type": "function"
}, {"constant": false,"inputs": [{"name": "_blackListedUser", "type": "address"}],"name": "destroyBlackFunds","outputs": [],"payable": false,"stateMutability": "nonpayable","type": "function"
}, {"inputs": [{"name": "_initialSupply", "type": "uint256"}, {"name": "_name", "type": "string"}, {"name": "_symbol","type": "string"}, {"name": "_decimals", "type": "uint256"}],"payable": false,"stateMutability": "nonpayable","type": "constructor"
}, {"anonymous": false,"inputs": [{"indexed": false, "name": "amount", "type": "uint256"}],"name": "Issue","type": "event"
}, {"anonymous": false,"inputs": [{"indexed": false, "name": "amount", "type": "uint256"}],"name": "Redeem","type": "event"
}, {"anonymous": false,"inputs": [{"indexed": false, "name": "newAddress", "type": "address"}],"name": "Deprecate","type": "event"
}, {"anonymous": false,"inputs": [{"indexed": false, "name": "feeBasisPoints", "type": "uint256"}, {"indexed": false,"name": "maxFee","type": "uint256"}],"name": "Params","type": "event"
}, {"anonymous": false,"inputs": [{"indexed": false, "name": "_blackListedUser", "type": "address"}, {"indexed": false,"name": "_balance","type": "uint256"}],"name": "DestroyedBlackFunds","type": "event"
}, {"anonymous": false,"inputs": [{"indexed": false, "name": "_user", "type": "address"}],"name": "AddedBlackList","type": "event"
}, {"anonymous": false,"inputs": [{"indexed": false, "name": "_user", "type": "address"}],"name": "RemovedBlackList","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"
}, {"anonymous": false, "inputs": [], "name": "Pause", "type": "event"}, {"anonymous": false,"inputs": [],"name": "Unpause","type": "event"
}]var tokenContract = new web3.eth.Contract(abi, '0xdac17f958d2ee523a2206206994597c13d831ec7');
tokenContract.methods.balanceOf('0x5041ed759dd4afc3a72b8192c143f72f4724081a').call({from: '0x5041ed759dd4afc3a72b8192c143f72f4724081a'}, function (error, result) {console.log(error);console.log(result);console.log(web3.utils.fromWei(result, 'mwei'));
});

web3.js链接以太坊并查询钱包u余额相关推荐

  1. 向别人网页注入js_区块链研究实验室 | Web3 .js基于以太坊的Javascript API

    web3.js是一个库集合,你可以使用HTTP或IPC连接本地或远程以太它节点进行交互. web3的JavaScript库能够与以太坊区块链交互. 它可以检索用户帐户,发送交易,与智能合约交互等. V ...

  2. 使用 Web3.js 连接以太坊节点并查询区块链数据

    Web3.js 是一个用于连接以太坊网络的 JavaScript 库.在本文中,我们将介绍如何使用 Web3.js 来连接以太坊节点,并且查询以太坊区块链上的数据. 1. 安装 Web3.js 首先, ...

  3. 在vue中使用web3.js开发以太坊dapp

    前端如何使用以太坊智能合约方法 这里讲的是前端与MetaMask之间的交互 文中涉及到的官方文档 web3.js 1.0中文手册 MetaMask官方文档 web3.js文件 链接:https://p ...

  4. 如何用web3.js在以太坊区块链上保存数据?

    2019独角兽企业重金招聘Python工程师标准>>> 虽然有北大博士讲,95%的区块链项目都没有前途,但我们知道区块链还是有它的优势,比如数据的不可篡改性对于版权保护有相当大的意义 ...

  5. android web3j 代币查询_wallet-eth 以太坊代币钱包 助记词 私钥 keystore 转账

    wallet-eth-android wallet-eth 以太坊代币钱包 助记词 私钥 keystore 转账(bip39.bip32.bip44.web3j) 生成钱包地址 // 生成钱包地址 W ...

  6. 前端Vue项目调用页面web3.js:连接metaMask钱包,(查询钱包ETH余额,查询代币余额,ETH转账,代币转账,代币授权,查询授权数量,计算价格)等功能

    这里分享下相关文档 1.web3.js中文文档 https://learnblockchain.cn/docs/web3.js/getting-started.html 2.metamask官方文档: ...

  7. 使用ethers.js开发以太坊Web钱包 - 将私钥保存在客户端

    为什么需要 Keystore 文件 通过这篇文章理解开发HD 钱包涉及的 BIP32.BIP44.BIP39,私钥其实就代表了一个账号,最简单的保管账号的方式就是直接把私钥保存起来,如果私钥文件被人盗 ...

  8. 【Web3】Web3连接到以太坊网络(测试网、主网)

    目录 什么是Web3 Web3项目连接以太坊网络 1.下载Web3 2.实例化Web3对象 3.infura 获取连接以太坊网络节点 4.添加网络节点 什么是Web3 web3.js开发文档:web3 ...

  9. coldwallet java eth_wallet-eth 以太坊代币钱包 助记词 私钥 keystore 转账

    wallet-eth-android wallet-eth 以太坊代币钱包 助记词 私钥 keystore 转账(bip39.bip32.bip44.web3j) 生成钱包地址 // 生成钱包地址 W ...

最新文章

  1. LVS技术浅析-proc参数
  2. Robert算子的运用
  3. Vs2010无法打开文件“Kernel32.lib”、无法打开“libcpmt.lib”msvcprt.lib
  4. Asp.net中的HttpModule和HttpHandler的简单用法
  5. Workflow WF Reference Links for 2009-02-13
  6. 【Pytorch神经网络理论篇】 08 Softmax函数(处理分类问题)
  7. asp.net 异步群发邮件时遭遇到的问题 ddddddddd
  8. PyTorch | 通过torch.normal()创建概率分布的张量 | torch.normal()如何使用?torch.normal()使用方法 | torch.normal()例子
  9. redis高级用法:geo位置相关信息
  10. Stanford机器学习---第二讲. 多变量线性回归 Linear Regression with multiple variable
  11. 【Spark Summit EU 2016】使用参数服务器在Spark上扩展因式分解机
  12. python3 模板库 好用_关于3个Python模板库的比较
  13. EasyUI——基本布局
  14. 手工内存管理规则的总结
  15. cocos creator 优量汇广告接入
  16. 现代互联网的网络拓扑
  17. matlab 蒙特卡罗计算pi值
  18. Google全系列产品不再信任赛门铁克某款根证书-转载
  19. 生鲜供应链行业分析和产品解决方案
  20. wordpress后台管理(七)说说管理:所有说说、发表说说

热门文章

  1. python 股票量化盘后分析系统V0.42
  2. C语言 函数返回多个值方法
  3. 三星电脑Notebook 5(NP500R3M-K08)更换SSD
  4. Relation (mathematics)
  5. 宝安日报:联诚发跨界创新“追光”十九载!
  6. 企业信息安全与人员管理标准
  7. 跨平台开发方案的三个时代
  8. Git分支合并时显示输入合并备注
  9. php有意思的小项目,推荐6个Github上超有意思的前端项目!
  10. C# 集合-并发处理