2

我开始使用 Hardhat 在我的本地系统上部署 Gravity 合约,它第一次部署成功,之后我运行了一个脚本来创建 Gravatars,但是当我运行yarn hardhat node --hostname 0.0.0.0时它失败了。它显示以下错误

*错误:交易在没有原因字符串的情况下被还原。(0x5fbdb2315678afecb367f032d93f642f64180aa3) 在 HardhatNode._mineBlockWithPendingTxs (/home/ahsan/nftiple/marketplace/node_modules/hardhat/src/internal/hardhat-network/provider/node.ts:1582:23) 在 HardhatNode.mineBlock (/home/ahsan/nftiple /marketplace/node_modules/hardhat/src/internal/hardhat-network/provider/node.ts:435:16) 在 EthModule._sendTransactionAndReturnHash (/home/ahsan/nftiple/marketplace/node_modules/hardhat/src/internal/hardhat-network /provider/modules/eth.ts:1494:18) 在 HardhatNetworkProvider._sendWithLogging (/home/ahsan/nftiple/marketplace/node_modules/hardhat/src/internal/hardhat-network/provider/provider.ts:129:22) 在HardhatNetworkProvider.request (/home/ahsan/nftiple/marketplace/node_modules/hardhat/src/internal/hardhat-network/provider/provider.ts:106:18) *

这是我的部署脚本和 Gravity.sol 合约文件的代码

import {HardhatRuntimeEnvironment} from "hardhat/types";
import {DeployFunction} from "hardhat-deploy/types";

const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
  const {deployments, getNamedAccounts} = hre;

  const {deployer} = await getNamedAccounts();

  const deployResult = await deployments.deploy("GravatarRegistry", {
    from: deployer,
    log: true,
  });

  const Registry = await hre.ethers.getContractFactory('GravatarRegistry');
  const registry = await Registry.attach(deployResult.address);
  registry.createGravatar('Virat','https://img1.hscicdn.com/image/upload/f_auto,t_gn_f_345/lsci/db/PICTURES/CMS/316600/316605.png');
  registry.createGravatar('Saurav','https://img1.hscicdn.com/image/upload/f_auto,t_gn_f_345/lsci/db/PICTURES/CMS/319900/319951.png');
  registry.createGravatar('Sachin','https://img1.hscicdn.com/image/upload/f_auto,t_gn_f_345/lsci/db/PICTURES/CMS/316400/316486.png');// FAILS HERE
};

export default func;


pragma solidity ^0.8.0;

contract GravatarRegistry {
    event NewGravatar(uint id, address owner, string displayName, string imageUrl);
    event UpdatedGravatar(uint id, address owner, string displayName, string imageUrl);

    struct Gravatar {
        address owner;
        string displayName;
        string imageUrl;
    }

    Gravatar[] public gravatars;

    mapping(uint => address) public gravatarToOwner;
    mapping(address => uint) public ownerToGravatar;

    function createGravatar(string memory _displayName, string memory _imageUrl) public {
        require(ownerToGravatar[msg.sender] == 0);
        gravatars.push(Gravatar(msg.sender, _displayName, _imageUrl));
        uint id = gravatars.length - 1;
        gravatarToOwner[id] = msg.sender;
        ownerToGravatar[msg.sender] = id;

        emit NewGravatar(id, msg.sender, _displayName, _imageUrl);
    }

    function getGravatar(address owner) public view returns (string memory, string memory) {
        uint id = ownerToGravatar[owner];
        return (gravatars[id].displayName, gravatars[id].imageUrl);
    }

    function updateGravatarName(string memory _displayName) public {
        require(ownerToGravatar[msg.sender] != 0);
        require(msg.sender == gravatars[ownerToGravatar[msg.sender]].owner);

        uint id = ownerToGravatar[msg.sender];

        gravatars[id].displayName = _displayName;
        emit UpdatedGravatar(id, msg.sender, _displayName, gravatars[id].imageUrl);
    }

    function updateGravatarImage(string memory _imageUrl) public {
        require(ownerToGravatar[msg.sender] != 0);
        require(msg.sender == gravatars[ownerToGravatar[msg.sender]].owner);

        uint id = ownerToGravatar[msg.sender];

        gravatars[id].imageUrl = _imageUrl;
        emit UpdatedGravatar(id, msg.sender, gravatars[id].displayName, _imageUrl);
    }

    // the gravatar at position 0 of gravatars[]
    // is fake
    // it's a mythical gravatar
    // that doesn't really exist
    // dani will invoke this function once when this contract is deployed
    // but then no more
    function setMythicalGravatar() public {
        require(msg.sender == 0x8d3e809Fbd258083a5Ba004a527159Da535c8abA);
        gravatars.push(Gravatar(address(0), " ", " "));
    }
}

我正在使用 hardhat-deploy 并且我知道 hardhat-deploy 试图避免重新部署相同的合同。有什么办法可以将我的安全帽重置为空白/干净状态,这样我就可以摆脱这个错误。我尝试多次删除 node_modules 目录但无济于事

4

0 回答 0