web3 code example

Here is a simple example of Web3 code using JavaScript, which connects to the Ethereum blockchain using the Web3.js library. This example allows you to interact with a smart contract, retrieve the balance of an Ethereum address, and send a transaction. First, make sure you have Web3.js installed: npm install web3 Then, you can use the following code: const Web3 = require('web3'); // Initialize Web3 instance (using Infura or a local node) const web3 = new Web3('https://mainnet.infura.io/v3/YOUR_INFURA_PROJECT_ID'); // Example Ethereum address const address = '0x742d35Cc6634C0532925a3b844Bc454e4438f44e'; // Get balance of an Ethereum address async function getBalance() { const balance = await web3.eth.getBalance(address); console.log(`Balance of ${address}: ${web3.utils.fromWei(balance, 'ether')} ETH`); } // Send a transaction async function sendTransaction() { const senderAddress = 'YOUR_SENDER_ADDRESS'; const privateKey = 'YO...