简易 web3.py 连接 bsc示例



from web3 import Web3

'''web1=Web3(Web3.WebsocketProvider("wss://bsc-ws-node.nariox.org:443"))'''
web1=Web3(Web3.HTTPProvider("https://bsc-dataseed4.ninicoin.io/"))
print(f'connected status:{web1.isConnected()}')

其中WebsocketProvider是用webscoket的连接 ,目前只找到一个wss连接节点:wss://bsc-ws-node.nariox.org:443

httpprovider的节点很多:
https://bsc-dataseed1.ninicoin.io/
https://bsc-dataseed2.ninicoin.io/
https://bsc-dataseed3.ninicoin.io/
https://bsc-dataseed4.ninicoin.io/
https://bsc-dataseed1.binance.org/
https://bsc-dataseed2.binance.org/
https://bsc-dataseed3.binance.org/
https://bsc-dataseed4.binance.org/