Note: We need Pythonversion >=3.5.3 and install web3.py using pip3 install web3.
Python and other library versions are the cause of the common installation problems. Therefore, if you face any problem, try setting up a virtual environment and troubleshoot web3.py installation.
Connecting to Ethereum Blockchain
A network of Ethereum nodes is called Ethereum blockchain. To interact with Etherum blockchain, these nodes expose APIs which are available using web3.py library.
In addition, we will need a running Ethereum node, therefore, we will use QuikNode’s free version. Just sign up here and get the node URL.
We will use web3.py to get the latest Ethereum block number. For this, we will use the code snippet given below.
In this snippet, we are importing web3.py library and adding our Ethereum node URL and getting the latest Ethereum block number using w3.eth.blockNumber API.
Now, we will save this code snippet in index.py file and then run it using python index.py command. After running this command we will see the latest Ethereum block number as shown below.
That’s it you have connected through Ethereum network using Python. In addition, you can learn more web3.py APIs to build complex applications on Ethereum.
Ready? Try QuikNode free for 7 days --> Sign Up Now
Auston Bunsen
Auston is a software engineer and the cofounder of QuikNode. He's passionate about the power of Web3 and curious to see what people build on top of QuikNode.