首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ReferenceError:未定义greeter

ReferenceError:未定义greeter
EN

Ethereum用户
提问于 2022-05-02 14:24:13
回答 1查看 119关注 0票数 0

下面是我的deploy.js中的脚本:

代码语言:javascript
复制
 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();

下面是我的hardhat.config.js中的脚本:

代码语言:javascript
复制
// 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"]
    }
  }
}

这是我的稳固合同剧本:

代码语言:javascript
复制
// 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;
    }
}

下面是每当我试图编译它时都会收到的错误消息:

代码语言:javascript
复制
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)

请让我知道我做错了什么,以及如何解决。

EN

回答 1

Ethereum用户

回答已采纳

发布于 2022-05-02 15:35:33

删除deploy.js中的这些行,应该会很好

代码语言:javascript
复制
await greeter.deployed();
console.log("Greeter deployed to:", greeter.address
票数 0
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/127361

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档