DEV Community

kaustav karmakar
kaustav karmakar

Posted on

Web3.js with javascript

The Support of my programm is done from Web3.js documentations
Course Overview

  1. Web3.js ** web3.js is a collection of libraries that allow you to interact with a local or remote ethereum node using HTTP, IPC or WebSocket.** 2.** Modules**
  2. Uses we can transfer ether in the wallet
  3. We can fetch the account balance 3.Web3.js in chrome console 4.We generate ABI and ByteCode using Web3.js in our smart contract 5.Compilation of Web3.js 6.Deployement of Smart Contract *Web3.js Prerequisites *
  4. Blockchain
  5. Basic understanding of Blockchain
  6. Ethereum
  7. Basic understanding of Ethereum
  8. Solidity
  9. Basic idea about Solidity
  10. JavaScript
  11. Basic understanding of JavaScript Software Requirement
  12. Node js
  13. Ganache
  14. Vs Code

What is Web3.js?

  • Suppose we have a application and we want to connect our application with blockchain(Smart Contract),then we can use Web3.js in our applications to connect to the blockchain(Smart Contract).
  • It acts as a interface between your peer world(application) and blockchain (Smart Contract).
  • Web3.js is nothing but the interactions between our application and Smart Contract in Blockchain Web3.js
  • Installation of Web3.js
  • Import of Web3.js
  • To connect with Ganache
  • To get the balance of an account
  • to convert wei into ether
  • to transfer ether from one account to another account
    Steps to proceed

  • node --v

  • npm init -y

  • npm install --save web3

let Web3 = require('web3');
//to check web3 is import or not 
console.log(" Web3", Web3);
//Now we will create a object named web3
let web3=new Web3(new Web3.providers.HttpProvider("Please give ganache url");
Enter fullscreen mode Exit fullscreen mode

Image description
Now we can control the Ganache

  • Now we will check how we can fetch the balance of Ganache of our account
web3.eth.getBalance("id of account").then(console.log);
//you will get the balance of the account 
//you need to have a little understanding of javascript
//then can also acts as a Promise
//if we want to get the balance 
web3.eth.getBalance("id of account").then(function(result){
console.log(web3.utils.fromWei(reults,"ether"));});
});
Enter fullscreen mode Exit fullscreen mode

How can we transfer ether from one account to another account?

web3.eth.sendTransactions({from:" id of account where money need to be transfer",to:"id of account where money need to be sent",value:web3.utils.toWei("Amount to be transfer","ether")});
Enter fullscreen mode Exit fullscreen mode

Main Source all the resources is click here
Thank You for Reading

Top comments (0)