0

const contractABI = require('./build/contracts/DonationContract.json'); const { Transaction } = require('ethereumjs-tx');

const MAX_TIME_FRAME = 60; // Adjust the maximum time frame as needed const provider =new Web3.providers.HttpProvider('https://sepolia.infura.io/v3/+ infura key');//'https://mainnet.infura.io/v3/YOUR_INFURA_PROJECT_ID' const web3 = new Web3(provider); require('dotenv').config();

try {

const networkId = await web3.eth.net.getId();
const contractAddress = "0x";
const contract = new web3.eth.Contract(contractABI.abi, contractAddress);

const transactionObject =  contract.methods.createDonation(
  formData.street_address,
  formData.pickup_date,
  formData.pickup_time,
  formData.availability_date,
  formData.pickup_hours,
  formData.item_type,
  formData.other_item,
  formData.item_description,
  formData.quantity,
  formData.requires_refrigeration,
  formData.best_consumed_date,
  formData.partial_donation
); 
const privateKey = process.env.PRIVATE_KEY;
const fromAddress = 'etheruem address';


const tx = new Transaction({
  nonce: await web3.eth.getTransactionCount(fromAddress),
  to: contractAddress,
  data: transactionObject.encodeABI(),
  gasPrice: web3.utils.toHex(await web3.eth.getGasPrice()),
  gasLimit: web3.utils.toHex(500000),
  value: web3.utils.toHex(0),
});

const tx = new Transaction(Tx, {'chain':'sepolia', 'chainId':'11155111'});

tx.sign(Buffer.from(privateKey, 'hex'));

const serializedTx = tx.serialize();

const receipt = await web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex'))
{
  if (!err) {
    console.log(result);
  };
}
Tinawaa1
  • 7
  • 2
  • Error: Chain with name sepolia not supported at Common._getChainParams (/home/cougarnet.uh.edu/fmnartey/AI-FEED/donation-module/node_modules/ethereumjs-common/dist/index.js:58:15) at Common.setChain (/home/cougarnet.uh.edu/fmnartey/AI-FEED/donation-module/node_modules/ethereumjs-common/dist/index.js:68:40) at new Common (/home/cougarnet.uh.edu/fmnartey/AI-FEED/donation-module/node_modules/ethereumjs-common/dist/index.js:27:34) at new Transaction (/home/cougarnet.uh.edu/fmnartey/AI-FEED/donation-module/node_modules/ethereumjs-tx/dist/transaction.js:65:28) – Tinawaa1 Jun 06 '23 at 22:19

0 Answers0