NomicFoundation / hardhat-ignition

Hardhat Ignition is a declarative deployment system that enables you to deploy your smart contracts without navigating the mechanics of the deployment process.
https://hardhat.org/ignition
MIT License
108 stars 26 forks source link

staticCall not working on hardhat 2.22.5, <Module being constructed - No results available yet> #779

Closed human-77 closed 5 months ago

human-77 commented 5 months ago

What happened?

Everytime that I try to get the answer from the getMessage function with ignition I get the following result rather than the answer:

<ref *1> NamedStaticCallFutureImplementation {
  id: 'Interact#Rocket.getMessage',
  type: 'STATIC_CALL',
  module: IgnitionModuleImplementation {
    id: 'Interact',
    results: <Module being constructed - No results available yet>,
    futures: Set(2) { [NamedContractAtFutureImplementation], [Circular *1] },
    submodules: Set(0) {}
  },
  dependencies: Set(1) {
    NamedContractAtFutureImplementation {
      id: 'Interact#Rocket',
      type: 'NAMED_ARTIFACT_CONTRACT_AT',
      module: [IgnitionModuleImplementation],
      dependencies: Set(0) {},
      contractName: 'Rocket',
      address: '0x5fbdb2315678afecb367f032d93f642f64180aa3'
    }
  },
  functionName: 'getMessage',
  contract: NamedContractAtFutureImplementation {
    id: 'Interact#Rocket',
    type: 'NAMED_ARTIFACT_CONTRACT_AT',
    module: IgnitionModuleImplementation {
      id: 'Interact',
      results: <Module being constructed - No results available yet>,
      futures: [Set],
      submodules: Set(0) {}
    },
    dependencies: Set(0) {},
    contractName: 'Rocket',
    address: '0x5fbdb2315678afecb367f032d93f642f64180aa3'
  },
  args: [],
  nameOrIndex: 0,
  from: undefined
}

Minimal reproduction steps

This is the contract:

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

contract Rocket {
    string public name;
    string public status;
    string public message;

    constructor(string memory _name) {
        name = _name;
        status = "ignition";
    }

    function launch() public {
        status = "lift-off";
    }

    function getMessage() public view returns (string memory) {
        return message;
    }

    function setMessage(string calldata _message) public {
        message = _message;
    }
}

I deployed it using this ignition script:

const { buildModule } = require("@nomicfoundation/hardhat-ignition/modules");

module.exports = buildModule("Apollo", (m) => {
  const apollo = m.contract("Rocket", ["Saturn V"]);

  m.call(apollo, "launch", []);

  return { apollo };
});

With this command:

$ npx hardhat ignition deploy ignition/modules/interact.js --network localhost

I started the local node with the normal command:

$ npx hardhat node

I tried to print the message with this script:

const { buildModule } = require("@nomicfoundation/hardhat-ignition/modules");

module.exports = buildModule("Interact", (m) => {
  const contract = m.contractAt("Rocket", "0x5fbdb2315678afecb367f032d93f642f64180aa3");

  //m.call(contract, "setMessage", ["Hi!"]);
  const output = m.staticCall(contract, "getMessage", []);
  console.log(output);

  return { contract };
});

I executed it with:

$ npx hardhat run .\scripts\interact.js --network localhost
$ npx hardhat run .\ignition\modules\interact.js --network localhost
$ npx hardhat ignition deploy .\scripts\interact.js --network localhost

None of them worked

Search terms

staticCall, Module being constructed

kanej commented 5 months ago

Hey, @human-77. This is expected. Everything passed into buildModule is run before execution. The module is constructed, which is when the console.log(output) is run. The constructed module is then used for running the execution. This separation of the describing of the deployment from its execution allows us to support features like restarting a deployment that was only partially completed.

human-77 commented 5 months ago

But then, How can I get to print the output of the function?

Do I need to import the script from other script, export the result and then print the result? I have tried to that, but got the same result

What I'm trying to do is the same as the scripts that were executed with "hardhat runner", but with ignition, or is that a mistake?

kanej commented 5 months ago

But then, How can I get to print the output of the function?

Do I need to import the script from other script, export the result and then print the result? I have tried to that, but got the same result

What I'm trying to do is the same as the scripts that were executed with "hardhat runner", but with ignition, or is that a mistake?

You can use scripts as before. Ignition is giving you a declarative deployment which means it is less procedural but allows us to understand the complete deployment before running it (so we can do static analysis and validation, visualize it, restart it from a midpoint due to a previous failed run).

But you can combine both approaches as well. Deploy an Ignition module from within a script:

https://hardhat.org/ignition/docs/guides/scripts