|
| 1 | +import * as dotenv from "dotenv"; |
| 2 | +dotenv.config(); |
| 3 | +import { HardhatRuntimeEnvironment } from "hardhat/types"; |
| 4 | +import { DeployFunction } from "hardhat-deploy/types"; |
| 5 | +import { Contract, getAddress } from "ethers"; |
| 6 | + |
| 7 | +/** |
| 8 | + * Deploys a contract named "OracleReader" using the deployer account and |
| 9 | + * constructor arguments set to the deployer address |
| 10 | + * |
| 11 | + * @param hre HardhatRuntimeEnvironment object. |
| 12 | + */ |
| 13 | +const deployOracleReader: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { |
| 14 | + /* |
| 15 | + On localhost, the deployer account is the one that comes with Hardhat, which is already funded. |
| 16 | +
|
| 17 | + When deploying to live networks (e.g `yarn deploy --network goerli`), the deployer account |
| 18 | + should have sufficient balance to pay for the gas fees for contract creation. |
| 19 | +
|
| 20 | + You can generate a random account with `yarn generate` which will fill DEPLOYER_PRIVATE_KEY |
| 21 | + with a random private key in the .env file (then used on hardhat.config.ts) |
| 22 | + You can run the `yarn account` command to check your balance in every network. |
| 23 | + */ |
| 24 | + const { deployer } = await hre.getNamedAccounts(); |
| 25 | + const { deploy } = hre.deployments; |
| 26 | + |
| 27 | + // Read oracle and self-kisser addresses from .env file. |
| 28 | + const oracle = getAddress(process.env.CHRONICLE_ORACLE || ""); |
| 29 | + const selfKisser = getAddress(process.env.SELF_KISSER || ""); |
| 30 | + |
| 31 | + await deploy("OracleReader", { |
| 32 | + from: deployer, |
| 33 | + // Contract constructor arguments |
| 34 | + args: [oracle, selfKisser], |
| 35 | + log: true, |
| 36 | + // autoMine: can be passed to the deploy function to make the deployment process faster on local networks by |
| 37 | + // automatically mining the contract deployment transaction. There is no effect on live networks. |
| 38 | + autoMine: true, |
| 39 | + }); |
| 40 | + |
| 41 | + // Get the deployed contract to interact with it after deploying. |
| 42 | + const oracleReader = await hre.ethers.getContract<Contract>("OracleReader", deployer); |
| 43 | + console.log("👋 The current oracle's value is:", await oracleReader.read()); |
| 44 | +}; |
| 45 | + |
| 46 | +export default deployOracleReader; |
| 47 | + |
| 48 | +// Tags are useful if you have multiple deploy files and only want to run one of them. |
| 49 | +// e.g. yarn deploy --tags OracleReader |
| 50 | +deployOracleReader.tags = ["OracleReader"]; |
0 commit comments