A Web3 library is a tool that allows developers to interact with blockchains. These libraries provide an easy-to-use interface for developers to build decentralized applications (DApps) and interact and retrieve data from a blockchain.
The most popular Web3 libraries are web3.js, ethers.js, and web3.py. These libraries are widely used in the Web3 community and provide similar functionality.
Install a Web3 library
Learn how to install Web3 libraries and connect to a blockchain for developing DApps.
JavaScript libraries
To install a Web3 JavaScript library, you need node.js installed on your machine:
- Install node.js
Then you can install the library using npm:
npm install web3
npm install ethers
Python libraries
To install and use a Python library, you first need to install Python in your system:
Then you can install the library using pip:
pip install web3
Get started
To get started with Web3 libraries, you will need to have a basic understanding of the EVM and smart contracts. It is also recommended to have a local development environment set up. Once you have set up your development environment, you can start interacting with different blockchains using the Web3 library of your choice.
Create a node instance
web3.js
To get started with web3.js, you will need to create a provider instance. This can be done by instantiating the Web3
class and passing in the URL of an Ethereum node deployed with Chainstack. For example:
const Web3 = require("web3");
const node_url = "CHAINSTACK_NODE_URL";
const web3 = new Web3(node_url);
ethers.js
To get started with ethers.js, you must create a provider instance. This can be done by instantiating the ethers.providers.JsonRpcProvider
class and passing in the URL of an Ethereum node deployed with Chainstack. For example:
const ethers = require('ethers');
const node_url = "CHAINSTACK_NODE_URL";
const provider = new ethers.providers.JsonRpcProvider(node_url);
web3.py
To start with web3.py, you will need to create a provider instance. This can be done by instantiating the Web3
class and passing in the URL of an Ethereum node deployed with Chainstack. For example:
from web3 import Web3
node_url = "CHAINSTACK_NODE_URL"
web3 = Web3(Web3.HTTPProvider(node_url))
Once you have created a provider instance, you can use the functions provided by the library to interact with a blockchain.