const Web3 = require("web3");
// Loading the contract ABI
// (the results of a previous compilation step)
const fs = require("fs");
const { abi } = JSON.parse(fs.readFileSync("Demo.json"));
// Configuring the connection to an Ethereum node
const network = process.env.ETHEREUM_NETWORK;
new Web3.providers.HttpProvider(
`https://${network}.infura.io/v3/${process.env.INFURA_PROJECT_ID}`
// Creating a signing account from a private key
const signer = web3.eth.accounts.privateKeyToAccount(
process.env.SIGNER_PRIVATE_KEY
web3.eth.accounts.wallet.add(signer);
// Creating a Contract instance
const contract = new web3.eth.Contract(
// Replace this with the address of your deployed contract
process.env.DEMO_CONTRACT
// Issuing a transaction that calls the `echo` method
const tx = contract.methods.echo("Hello, world!");
gas: await tx.estimateGas(),
.once("transactionHash", (txhash) => {
console.log(`Mining transaction ...`);
console.log(`https://${network}.etherscan.io/tx/${txhash}`);
// The transaction is now on chain!
console.log(`Mined in block ${receipt.blockNumber}`);
require("dotenv").config();