Posted By : Harshit
There is a system called EVM (Ethereum Virtual Machine) which holds the state of the Ethereum network. If any participant request computation then other participants will verify and validate the request and if the request validates then it causes the state change in EVM and will propagate through the entire network. This request is called the transaction. Ether is the cryptocurrency of the market for computation, which will be provided to the participants as market incentives for verifying and executing it.
npm init -y
npm install web3
npm install nodemon --save
const web3 = require('web3');
const express = require('express');
const Tx = require('ethereumjs-tx');
const app = express();
web3js = new web3(new web3.providers.HttpProvider("https://rinkeby.infura.io/YOUR_API_KEY"));
app.get('/getBalance',function(req,res){
//contract abi is the array that you can get from the ethereum wallet or etherscan
var contractABI =YOUR_CONTRACT_ABI;
var contractAddress ="YOUR_CONTRACT_ADDRESS";
web3js.eth.getBalance("YOUR ACCOUNT ADDRESS", function(err, result) {
if (err) {
console.log(err)
res.status(400).send({success:false,Erroe:err})
} else {
let balance = web3js.utils.fromWei(result, "ether")
res.status(200).send({success:true,Balance:balance})
}
})
})
This blog will help you create an API to interact with Ethereum Blockchain.
September 8, 2024 at 02:30 am
Your comment is awaiting moderation.