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

`contract.deploymentTransaction()` is always null when using ignition modules #769

Closed ahmohamed closed 5 months ago

ahmohamed commented 5 months ago

Thanks for making this nice deployment package. I am trying to migrate code from hardhat-deploy to using ignition modules. I'm using ethers V6 and want to fetch the deploymentTransaction of the contract, but it's always null. What am I missing here?

describe("Counter", () => {
    let counter: Counter;

    beforeEach(async () => {
        const signers: SignerWithAddress[] = await ethers.getSigners();

        // @ts-ignore: https://github.com/NomicFoundation/hardhat-ignition/issues/156
        counter = (await ignition.deploy(CounterModule, {
            parameters: { Counter: { initCount: initCount } },
            defaultSender: signers[0].address
        })).contract;

        const currCount = await counter.getCount();
        expect(currCount).to.eq(initCount);
        expect(await counter.getAddress()).to.properAddress;
        await counter.waitForDeployment()
        expect(counter.deploymentTransaction()).to.not.be.null
    });
// ....
kanej commented 5 months ago

Hey, @ahmohamed the deploymentTransaction is not populated, that value is only set if the contract instance was deployed through an Ethers contract factory: https://docs.ethers.org/v6/api/contract/#BaseContract-deploymentTransaction

As a note, you shouldn't need the await count.waitForDeployment(), once ignition.deploy returns all the contracts should be deployed (or an error will be thrown).

ahmohamed commented 5 months ago

Thanks @kanej. I didn’t realise that. The code that I'm migrating to ignition did use contract factory, so that explains why it was present.

So now with ignition, is there an alternate way to get the deployed tx? For example, to wait for x confirmations or to query the gas used?

RE note: I suspected it's not needed, but wanted to cover all bases ;)

kanej commented 5 months ago

There is not a way to get access easily programmatically.

The deployment transaction is recorded into the logging journal ./ignition/deployments/<deploymentid>/journal.jsonl, but it is not easily accessible.