wighawag / hardhat-deploy

hardhat deployment plugin
MIT License
1.19k stars 292 forks source link

export-all is not saving different network deployment in the same file #455

Open morandalex opened 1 year ago

morandalex commented 1 year ago

Describe the bug I am trying to export several network deployments into a single file. but every time I deploy , I see that the precedent newtork deploynent is overwritten by the new one.

I am using the following deploy script:

const func: DeployFunction = async (hre: HardhatRuntimeEnvironmentExtended) => {
    const {getNamedAccounts, deployments, ethers, getChainId} = hre as HardhatRuntimeEnvironmentExtended;

    const provider = ethers.provider;
    const {deploy} = deployments;

    const chainId = await getChainId();
    console.log("DEPLOYMENT ON : ", chainId)

    let FakeErc20Contract: FakeErc20;
    let FakeErc20ContractDeploy: any;

    let Contract: Contract;
    let ContractDeploy: any;
    const [deployer, admin, user1, user2, user3, user4]: SignerWithAddress[] = await ethers.getSigners();

    ///////////////////////////////
    // STEP 0 : DEPLOY ERC20 CONTRACT IF LOCAL OTHERWISE GET CORRECT ERC20 ADDRESS
    ///////////////////////////////
    if (chainId == '1337') {
        console.log('we are using the following addresses: ', {
            deployer: deployer.address,
            admin: admin.address,
            user1: user1.address,
            user2: user2.address,
        })
        try {
            FakeErc20ContractDeploy = await deploy('FakeErc20', {
                from: deployer.address,
                args: [],
                log: true,
            });

            console.log('FAKE ERC20 ADDRESS : ', FakeErc20ContractDeploy.address)
        } catch (e) {
            console.log(e.reason)
        }
    }

    ///////////////////////////////
    // STEP 1 : DEPLOY MAIN CONTRACT WITH INHERITED CONTRACTS
    ///////////////////////////////
    let argsArray = []
    let usdc,eurc = ''

    switch (chainId) {
        case '1337' :
            usdc = FakeErc20ContractDeploy.address
            argsArray = [[usdc],100,100000]
            break;
        case '5' :
            usdc = circleErc20Contracts[chainId].usdc
            eurc = circleErc20Contracts[chainId].eurc
            argsArray = [[usdc,eurc],100,100000]
            break;
        case '137' :
            usdc = circleErc20Contracts[chainId].usdc
            argsArray = [[usdc],100,100000]
            break;
        case '80001' :
            usdc = circleErc20Contracts[chainId].usdc
            argsArray = [[usdc],100,100000]
            break;
    }
    try {
        ContractDeploy = await deploy('Contract', {
            from: deployer.address,
            args: argsArray,
            gasPrice: ethers.utils.parseUnits("100", "gwei"),
            log: true,
        });
        console.log("DEPLOYED CONTRACT ADDRESS : ",ContractDeploy.address)
    } catch (e) {
        console.log(e)
    }

}

To Reproduce yarn hardhat deploy --export-all ./src/contracts_data.json

Expected behavior I should se in the file the list of different network deployments

{
"80001: ....
"137": ....
"1": ...
ecc..
}

versions

Additional context anything else why not remaining goerli and mubai together

wighawag commented 1 year ago

you need to specify a network

instead of

yarn hardhat deploy --export-all ./src/contracts_data.json

you have to execute:

yarn hardhat --network <my-network> deploy --export-all ./src/contracts_data.json

And I suggest you export after all is deployed so

yarn hardhat --network <my-network> deploy
yarn hardhat --network <my-second-network> deploy
...
yarn hardhat export --export-all ./src/contracts_data.json
ghost commented 1 year ago

@wighawag thanks!