web3.py 安装以及主币查询 - bsc链

Posted 我要买GTR45

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了web3.py 安装以及主币查询 - bsc链相关的知识,希望对你有一定的参考价值。

安装web3

pip install pip3

我的电脑会提示一个c++ 14.0的报错,按照以下步骤可以解决

error: Microsoft Visual C++ 14.0 or greater is required. Get it with “Microsoft C++ Build Tools“
# 百度云链接:
https://pan.baidu.com/s/1MWcOigDWrohbWfKoWtmHJA 

# 提取码:
6666 

下载解压安装 Microsoft Visual C++ Build Tools 即可解决

BSC链主网设置

rpc link:  https://bsc-dataseed1.binance.org/

连接主网

# 指定主网地址
rpc_link = "https://bsc-dataseed1.binance.org/"
# 创建链接
w3_rpc = Web3(Web3.HTTPProvider(rpc_link))
print("Main Net Connected" if w3_rpc.isConnected() else "Connect Failed")

获取最新区块下当前账户余额

# 获取最新区块账户余额
balance_data = w3_rpc.eth.get_balance(target_address)

 

 余额进制转换

# 余额单位转换
balance = w3_rpc.fromWei(balance_data, "ether")
单位wei值Wei
wei11
Kwei (babbage)1e3 wei1,000
Mwei (lovelace)1e6 wei1,000,000
Gwei (shannon)1e9 wei1,000,000,000
microether (szabo)1e12 wei1,000,000,000,000
milliether (finney)1e15 wei1,000,000,000,000,000
ether1e18 wei1,000,000,000,000,000,000


 完整代码

# -*- encoding: utf-8 -*-"
# @Time    : 2021/12/25 18:34
# @Author  : bibi45
# @Version : 1.0
# @Contact : bibi45gt@gmail.com
# @License : (C)Copyright 2019-2021, bibi45
# That’s weird… It worked yesterday.
from web3 import Web3

# 查询地址
target_address = "查询地址"


class Web3Connection:
    def __init__(self):
        # 指定主网地址
        self.rpc_link = "https://bsc-dataseed1.binance.org/"
        # 创建链接
        self.w3_rpc = Web3(Web3.HTTPProvider(self.rpc_link))
        print("Main Net Connected" if self.w3_rpc.isConnected() else "Connect Failed")

    def check_balance(self, _target_address):
        # 获取最新区块账户余额
        balance_data = self.w3_rpc.eth.get_balance(_target_address)
        # 余额转换
        balance = self.w3_rpc.fromWei(balance_data, "ether")
        print("latest balance: ".format(balance))


if __name__ == '__main__':
    web3_obj = Web3Connection()
    web3_obj.check_balance(target_address)

引用:

error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools" 错误解决方案引用:

【转载】error: Microsoft Visual C++ 14.0 or greater is required. Get it with “Microsoft C++ Build Tools“_糖豆豆今天也要努力鸭的博客-CSDN博客在安装第三方库的时候,conda报了这个错经过一番百度 要安装visual studio C++ build tools但是这个包 它装不上啊啊啊总是提示安装包损坏又经过一番百度,在某篇csdn博文下的评论终于找到了答案。感谢这位大神!百度云链接:https://pan.baidu.com/s/19F4YurwwZ5A9WF5txzMZoQ提取码:ka7q好人一生平安!...https://blog.csdn.net/qq_40349484/article/details/120268224?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522163957277316780261977149%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=163957277316780261977149&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~first_rank_ecpm_v1~rank_v31_ecpm-2-120268224.first_rank_v2_pc_rank_v29&utm_term=+error%3A+Microsoft+Visual+C%2B%2B+14.0+or+greater+is+required.+Get+it+with+%22Microsoft+C%2B%2B+Build+Tools%22%3A+&spm=1018.2226.3001.4187以太坊中的计量单位及相互转换引用:

        作者:thao888
        链接:https://www.jianshu.com/p/a74afe1b171f

以上是关于web3.py 安装以及主币查询 - bsc链的主要内容,如果未能解决你的问题,请参考以下文章

BSC 测试链配置

Web3.py:使用挂起过滤器时出现 ValueError

BSC(币安智能链)私有链部署

bsc全节点搭建(币安智能链)

安装 web3.py 时如何消除错误

BSC/币安链批量转账,批量发送,币安链增加地址合约代码