Using Hardhat Deployment Scripts
const { ethers } = require('hardhat');
const hre = require('hardhat');
require('dotenv').config() // Store environment-specific variable from '.env' to process.env
function waitforme(milisec) {
return new Promise(resolve => {
setTimeout(() => { resolve('') }, milisec);
})
}
module.exports = async ({ getNamedAccounts, deployments, getChainId }) => {
const { deploy } = deployments;
const { deployer } = await getNamedAccounts();
const artifact = await deployments.getArtifact('NFTContract');
const chainId = await getChainId();
const networkName = hre.network.name;
const result = await deploy('NFTContract', {
from: deployer,
contract: {
abi:artifact.abi,
bytecode:artifact.bytecode,
deployedBytecode:artifact.deployedBytecode
},
// args: [<constructorArguments>],
log: true,
skipIfAlreadyDeployed: true
});
if (result.newlyDeployed) {
// It takes time for etherscan to index newly deployed contracts
await waitforme(20000);
await hre.run('verify:verify', {
address: augustus.address,
// constructorArguments: [<constructorArguments>],
});
}
};
module.exports.tags = ['NFTContract'];
require("@nomiclabs/hardhat-waffle");
const PROVIDER_URL = "URL";
// Please don't commit your private keys
// Usually you use a .env file to keep the private key
// which is still not secure but better
const MAINNET_PRIVATE_KEY = "YOUR PRIVATE KEY";
module.exports = {
solidity: "0.7.3",
networks: {
mainnet: {
url: PROVIDER_URL,
accounts: [`${MAINNET_PRIVATE_KEY}`]
}
}
};
Running the deployments: yarn compile && yarn hardhat --network mainnet deploy