0

Here is the script in my deploy.js:

 const main = async () => {
 

  // We get the contract to deploy
  const Transactions = await hre.ethers.getContractFactory("Transactions");
  const transactions = await Transactions.deploy();

  await greeter.deployed();

  console.log("Greeter deployed to:", greeter.address);
}

const runMain = async() => {
  try {
    await main();
    Process.exit(0);
  } catch (error) {
    console.error(error);
    process.exit(1);
  }
}

runMain();

Here is the script in my hardhat.config.js:

// This is a sample Hardhat task. 
// https://eth-ropsten.alchemyapi.io/v2/Bn5tm9fX90ET1hKwb76lKJB0rzU3JBi2

require("@nomiclabs/hardhat-waffle");


module.exports = {
  solidity: '0.8.0',
  networks: {
    ropsten: {
      url: "https://eth-ropsten.alchemyapi.io/v2/Bn5tm9fX90ET1hKwb76lKJB0rzU3JBi2",
      accounts: ["63b598044c3cce8d656............b7c64beb17eb1687aebbefc5cac8a"]
    }
  }
}

This is my solidity contract script:

// SPDX-License-Identifier: MIT

pragma experimental ABIEncoderV2;

pragma solidity >=0.6.0 <0.9.0;

contract Transactions {
    uint256 transactionCount;

    event Transfer(
        address from,
        address reciever,
        uint256 amount,
        string message,
        uint256 timestamp,
        string keyword
    );

    struct TransferStruct {
        address sender;
        address reciever;
        uint256 amount;
        string message;
        uint256 timestamp;
        string keyword;
    }

    TransferStruct[] transactions;

    function addToBlockchain(
        address payable reciever,
        uint256 amount,
        string memory message,
        string memory keyword
    ) public {
        transactionCount += 1;
        transactions.push(
            TransferStruct(
                msg.sender,
                reciever,
                amount,
                message,
                block.timestamp,
                keyword
            )
        );

        emit Transfer(
            msg.sender,
            reciever,
            amount,
            message,
            block.timestamp,
            keyword
        );
    }

    function getAllTransactions()
        public
        view
        returns (TransferStruct[] memory)
    {
        return transactions;
    }

    function getTransactionCount() public view returns (uint256) {
        return transactionCount;
    }
}

And below is the error message I get anytime I try to compile it:

PS C:\Users\Temitope\Desktop\kredar\smart_contract> npx hardhat run scripts/deploy.js --network ropsten
ReferenceError: greeter is not defined
at main (C:\Users\Temitope\Desktop\kredar\smart_contract\scripts\deploy.js:8:3)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at runMain (C:\Users\Temitope\Desktop\kredar\smart_contract\scripts\deploy.js:15:5)

Please kindly let me know what I'm doing wrong and how to solve it.

1 Answer 1

0

Remove these lines in deploy.js and it should be fine

await greeter.deployed();
console.log("Greeter deployed to:", greeter.address
2
  • it's giving another error of... ReferenceError: Process is not defined at runMain (C:\Users\Temitope\Desktop\kredar\smart_contract\scripts\deploy.js:13:5) at processTicksAndRejections (node:internal/process/task_queues:96:5)
    – temitope
    May 2, 2022 at 16:24
  • Hi there, you should remove Process.exit(0); as well. Because you did not import Process and so the compiler does not recognize what is 'Process' and it got you this error
    – longhuynh
    May 3, 2022 at 9:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.