Use the HTTPProvider to connect to your node endpoint and get the latest block number.
from web3 import Web3web3 = Web3(Web3.HTTPProvider('FILECOIN_ENDPOINT'))print(web3.eth.block_number)
from web3 import Web3web3 = Web3(Web3.HTTPProvider('https://%s:%s@%s'% ("USERNAME", "PASSWORD", "HOSTNAME")))print(web3.eth.block_number)
where
FILECOIN_ENDPOINT — your node HTTPS endpoint
HOSTNAME — your node HTTPS endpoint hostname
WebSocket
Use AsyncWeb3 with the WebSocketProvider object to connect to your node WSS endpoint and get the latest block number. The web3.py WebSocket provider is asynchronous, so the example runs in an asyncio event loop.
import asynciofrom web3 import AsyncWeb3, WebSocketProviderasync def main(): async with AsyncWeb3(WebSocketProvider('FILECOIN_ENDPOINT')) as web3: print(await web3.eth.block_number)asyncio.run(main())
import asynciofrom web3 import AsyncWeb3, WebSocketProviderasync def main(): async with AsyncWeb3(WebSocketProvider('wss://%s:%s@%s'% ("USERNAME", "PASSWORD", "HOSTNAME"))) as web3: print(await web3.eth.block_number)asyncio.run(main())