only mint tokens when on local hardhat network

This commit is contained in:
Eric Mastro 2023-05-05 16:00:26 +10:00 committed by Ben Bierens
parent 312a3eee55
commit c7b69893a1
1 changed files with 7 additions and 5 deletions

View File

@ -1,16 +1,18 @@
const MINTED_TOKENS = 1_000_000_000 const MINTED_TOKENS = 1_000_000_000
module.exports = async ({ deployments, getNamedAccounts, getUnnamedAccounts }) => { module.exports = async ({ deployments, getNamedAccounts, getUnnamedAccounts, network }) => {
const { deployer } = await getNamedAccounts() const { deployer } = await getNamedAccounts()
const tokenDeployment = await deployments.deploy("TestToken", { from: deployer }) const tokenDeployment = await deployments.deploy("TestToken", { from: deployer })
const token = await hre.ethers.getContractAt("TestToken", tokenDeployment.address) const token = await hre.ethers.getContractAt("TestToken", tokenDeployment.address)
const accounts = [...Object.values(await getNamedAccounts()), ...(await getUnnamedAccounts())] const accounts = [...Object.values(await getNamedAccounts()), ...(await getUnnamedAccounts())]
for (const account of accounts) { if (network.tags.local) {
console.log(`Minting ${MINTED_TOKENS} tokens to address ${account}`) for (const account of accounts) {
console.log(`Minting ${MINTED_TOKENS} tokens to address ${account}`)
const transaction = await token.mint(account, MINTED_TOKENS, { from: deployer }) const transaction = await token.mint(account, MINTED_TOKENS, { from: deployer })
await transaction.wait() await transaction.wait()
}
} }
} }