Let's Getting Started with the web3 js

Adding web3.js

How to install & Configure Web3 JS

The web3.js library is a collection of modules that contain functionality for the ethereum ecosystem.

web3-eth is for the ethereum blockchain and smart contracts.
web3-shh is for the whisper protocol, to communicate p2p and broadcast.
web3-bzz is for the swarm protocol, the decentralized file storage.
web3-utils contains useful helper functions for Dapp developers.

This can be done using the following methods:

First you need to get web3.js into your project.

npm: npm install web3
yarn: yarn add web3
pure js: link the dist/web3.min.js

After that you need to create a web3 instance and set a provider.

Most Ethereum-supported browsers like MetaMask have an EIP-1193 compliant provider available at window.ethereum.

For web3.js, check Web3.givenProvider.

If this property is null you should connect to a remote/local node.

// In Node.js use: const Web3 = require('web3');

const web3 = new Web3(Web3.givenProvider || "ws://localhost:8545");

All DONE

That’s it! now you can use the web3 object.

That’s it. I hope you enjoyed the article. If you have questions or queries related to How to install & Configure Web3 JS then feel free to ask in the comment section below, happy to help you.

About the author

Full-stack web developer with great knowledge of SEO & Digital Marketing. 7+ years of experience in Web Development.

Leave a Reply