redpacket_v1_local_deploy.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 deployi
  15. const RedPacket = await hre.ethers.getContractFactory("HappyRedPacket");
  16. const redPacket = await RedPacket.deploy();
  17. await redPacket.deployed();
  18. redPacket.on("CreationSuccess", (received_amount, _id, _name, _message, msg_sender, block_timestamp, _token_addr, number, ifrandom, duration) => {
  19. console.log("CreationSuccess ->", received_amount, _id, _name, _message, msg_sender, block_timestamp, _token_addr, number, ifrandom, duration);
  20. console.log("CreationSuccess id ->", _id);
  21. });
  22. const ret = await redPacket.create_red_packet
  23. ("0x5FbDB2315678afecb367f032d93F642f64180aa3"
  24. , 1
  25. , false
  26. , 10000
  27. ,"0x36549bd2558d9f37204f55be93cc38db93f377217b306febb9899c0013735755"
  28. , "good luck"
  29. , "good luck"
  30. , 0
  31. , "0x0000000000000000000000000000000000000000"
  32. , 1
  33. , { gasLimit: 310000, value: 1 })
  34. console.log("RedPacket deployed to:", redPacket.address);
  35. }
  36. // We recommend this pattern to be able to use async/await everywhere
  37. // and properly handle errors.
  38. main()
  39. .then(() => process.exit(0))
  40. .catch((error) => {
  41. console.error(error);
  42. process.exit(1);
  43. });