1

So I am using hardhat-deploy plugin and I have only 2 contracts to deploy.

01 - token
02 - someActionContract

02 - someActionContract is able to mint tokens, so it requires to know the address of a token to mint. So I can find it manually after both deployed, but I want to make it during deployment. So once token is deployed, I could pass it's address to someActionContract args. Is it even possible?

2 Answers 2

1
import { ethers } from "hardhat"

async function main() {
    const [deployer] = await ethers.getSigners()

    const Token = await ethers.getContractFactory("Token")
    const token = await Token.deploy()
    await token.deployed()
    console.log("Token Contract Address : ", token.address)

    const SomeActionContract = await ethers.getContractFactory("SomeActionContract")
    // Deploy some contract and pass token.address if you doing it via Constructor
    const someActionContract = await Token.deploy(token.address)
    await someActionContract.deployed()

    console.log("someActionContract Contract Address : ", someActionContract.address)
}

main().catch((error) => {
    console.error(error)
    process.exitCode = 1
})
npx hardhat run ./scripts/deploy.ts or deploy.js 
4
1

In this second deployment file, you can retrieve your deployed contract and then get the address and abi like so:

const hre = require("hardhat");

module.exports = async function({getNamedAccounts, deployments}) {
    const { deploy, log } = deployments;
    const { deployer } = await getNamedAccounts();

    const token = await hre.deployments.get('Token');
    const address = token.address;
    const abi = token.abi;
    const ARGS = [ address ];

    const someActionContract = await deploy('SomeActionContract', {
        from: deployer,
        args: ARGS,
        log: true,
    });
}
module.exports.tags = ['someActionContract'];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.