I have deployed a token like so using hardhat
const { getNamedAccounts, deployments, network } = hre
const { deploy, log, get } = deployments
const { deployer } = await getNamedAccounts()
log("----------------------------------------------------")
log("Deploying GovernanceToken and waiting for confirmations...")
const governanceTokenContractFactory = await ethers.getContractFactory(GOVERNANCE_TOKEN_NAME);
console.log(`Deploying ${GOVERNANCE_TOKEN_NAME}...`);
const deployedProxy = await upgrades.deployProxy(governanceTokenContractFactory, [], {
initializer: "initialize",
kind: "uups",
});
await deployedProxy.deployed();
console.log(`${GOVERNANCE_TOKEN_NAME} proxy deployed to: ${deployedProxy.address}`);
const governanceToken = await governanceTokenContractFactory.attach(
deployedProxy.address
);
In a seperate script I'm trying to deploy the governor which requires the governance token. Normally I would be able to get the deployed token like so:
const governanceToken = await get(GOVERNANCE_TOKEN_NAME)
//const governanceToken = await ethers.getContract(GOVERNANCE_TOKEN_NAME)
I'm getting an error when I try to do so:
Error: No Contract deployed with name GovernanceToken
My guess is that this is related to me using @openzeppelin/hardhat-upgrades
to deploy and that its not registering it the same way it would during normal deployment:
import { upgrades } from "hardhat"
How can I get a previously deployed proxy contract in a seperate deployment file using hardhat-upgrades?
So after deploying I needed to save the artifact.
const { getNamedAccounts, deployments, network } = hre
const { deploy, log, get } = deployments
const { deployer } = await getNamedAccounts()
log("----------------------------------------------------")
log("Deploying GovernanceToken and waiting for confirmations...")
const governanceTokenContractFactory = await ethers.getContractFactory(GOVERNANCE_TOKEN_NAME);
console.log(`Deploying ${GOVERNANCE_TOKEN_NAME}...`);
const deployedProxy = await upgrades.deployProxy(governanceTokenContractFactory, [], {
initializer: "initialize",
kind: "uups",
});
await deployedProxy.deployed();
console.log(`${GOVERNANCE_TOKEN_NAME} proxy deployed to: ${deployedProxy.address}`);
const governanceToken = await governanceTokenContractFactory.attach(
deployedProxy.address
);
const artifact = await deployments.getExtendedArtifact(GOVERNANCE_TOKEN_NAME);
const proxyDeployments = {
address: deployedProxy.address,
...artifact
}
await save(GOVERNANCE_TOKEN_NAME, proxyDeployments);