sample-script.js 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. // We require the Hardhat Runtime Environment explicitly here. This is optional
  2. // but useful for running the script in a standalone fashion through `node <script>`.
  3. //
  4. // When running the script with `npx hardhat run <script>` you'll find the Hardhat
  5. // Runtime Environment's members available in the global scope.
  6. const hre = require("hardhat");
  7. async function main() {
  8. // Hardhat always runs the compile task when running scripts with its command
  9. // line interface.
  10. //
  11. // If this script is run directly using `node` you may want to call compile
  12. // manually to make sure everything is compiled
  13. // await hre.run('compile');
  14. // We get the contract to deploy
  15. const Greeter = await hre.ethers.getContractFactory("Greeter");
  16. const greeter = await Greeter.deploy("Hello, Hardhat!");
  17. await greeter.deployed();
  18. console.log("Greeter deployed to:", greeter.address);
  19. }
  20. // We recommend this pattern to be able to use async/await everywhere
  21. // and properly handle errors.
  22. main()
  23. .then(() => process.exit(0))
  24. .catch((error) => {
  25. console.error(error);
  26. process.exit(1);
  27. });