From fe0aa911d24611aee86fea8d1a08cb4494af9b18 Mon Sep 17 00:00:00 2001 From: codeesura Date: Wed, 15 Nov 2023 20:49:27 +0300 Subject: [PATCH 1/2] update --- .env.example | 4 +++- README.md | 7 ++++--- hardhat.config.ts | 29 ++++++++++++++++++++++++++ package.json | 9 ++++---- scripts/deploy.ts | 52 ++++++++++++++++++++++++++++++++++++++++------- test/Lock.ts | 4 ++++ 6 files changed, 90 insertions(+), 15 deletions(-) diff --git a/.env.example b/.env.example index f68928e..ecae024 100644 --- a/.env.example +++ b/.env.example @@ -1,3 +1,5 @@ PRIVATE_KEY=0xabc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc1 +ETHERSCAN_API_KEY="IPRSZPE9M4DHH9R1YD69JWU3TWX86GYV9E" # SCROLL_TESTNET_URL=https://prealpha-rpc.scroll.io/l2 - Uncomment this line to use the pre-alpha instead of alpha -SCROLL_TESTNET_URL=https://alpha-rpc.scroll.io/l2 +SCROLL_TESTNET_URL="https://sepolia-rpc.scroll.io" +SCROLL_MAINNET_URL="https://rpc.scroll.io" \ No newline at end of file diff --git a/README.md b/README.md index 549ed64..81abdde 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,8 @@ This project demonstrates how to use hardhat or foundry to deploy a contract in 2. Run `yarn install` to install dependencies. 3. Create a `.env` file following the example `.env.example` in the root directory. Change `PRIVATE_KEY` to your own account private key in the `.env`. 4. Run `yarn compile` to compile the contract. -5. Run `yarn deploy:scrollTestnet` to deploy the contract on the Scroll Alpha Testnet. +5. To deploy the contract on the Scroll Sepolia Testnet, run `yarn deploy:scrollTestnet`. +6. To deploy the contract on the Scroll Mainnet, run `yarn deploy:scrollMainnet` (ensure that your `.env` file contains appropriate credentials and settings for the Scroll Mainnet). 6. Run `yarn test` for hardhat tests. @@ -31,7 +32,7 @@ This project demonstrates how to use hardhat or foundry to deploy a contract in ``` 3. Deploy the contract. ``` - forge create --rpc-url https://alpha-rpc.scroll.io/l2 \ + forge create --rpc-url https://sepolia-rpc.scroll.io \ --value \ --constructor-args \ --private-key \ @@ -43,7 +44,7 @@ This project demonstrates how to use hardhat or foundry to deploy a contract in For example: ``` - forge create --rpc-url https://alpha-rpc.scroll.io/l2 \ + forge create --rpc-url https://sepolia-rpc.scroll.io \ --value 0.00000000002ether \ --constructor-args 1696118400 \ --private-key 0xabc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc1 \ diff --git a/hardhat.config.ts b/hardhat.config.ts index c0d88a4..bbc5f77 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -2,6 +2,7 @@ import * as dotenv from "dotenv"; import { HardhatUserConfig } from "hardhat/config"; import "@nomicfoundation/hardhat-toolbox"; +import "@nomiclabs/hardhat-etherscan"; dotenv.config(); @@ -19,9 +20,37 @@ const config: HardhatUserConfig = { networks: { scrollTestnet: { url: process.env.SCROLL_TESTNET_URL || "", + chainId: 534351, accounts: process.env.PRIVATE_KEY !== undefined ? [process.env.PRIVATE_KEY] : [], }, + scrollMainnet: { + url: process.env.SCROLL_MAINNET_URL || "", + chainId: 534352, + accounts: + process.env.PRIVATE_KEY !== undefined ? [process.env.PRIVATE_KEY] : [], + }, + }, + etherscan: { + apiKey: process.env.ETHERSCAN_API_KEY, + customChains: [ + { + network: "scrollTestnet", + chainId: 534351, + urls: { + apiURL: "https://api-sepolia.scrollscan.com/api", + browserURL: "https://sepolia.scrollscan.com" + } + }, + { + network: "scrollMainnet", + chainId: 534352, + urls: { + apiURL: "https://api.scrollscan.com/api", + browserURL: "https://scrollscan.com" + } + } + ] }, }; diff --git a/package.json b/package.json index 829e6ac..6294568 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,8 @@ "test": "npx hardhat test", "clean": "npx hardhat clean", "deploy:hh": "npx hardhat run --network hardhat scripts/deploy.ts", - "deploy:scrollTestnet": "npx hardhat run --network scrollTestnet scripts/deploy.ts" + "deploy:scrollTestnet": "npx hardhat run --network scrollTestnet scripts/deploy.ts", + "deploy:scrollMainnet": "npx hardhat run --network scrollMainnet scripts/deploy.ts" }, "devDependencies": { "@ethersproject/abi": "^5.4.7", @@ -17,7 +18,7 @@ "@nomicfoundation/hardhat-network-helpers": "^1.0.0", "@nomicfoundation/hardhat-toolbox": "^1.0.1", "@nomiclabs/hardhat-ethers": "^2.0.0", - "@nomiclabs/hardhat-etherscan": "^3.0.0", + "@nomiclabs/hardhat-etherscan": "^3.1.7", "@typechain/ethers-v5": "^10.1.0", "@typechain/hardhat": "^6.1.2", "@types/chai": "^4.2.0", @@ -25,8 +26,8 @@ "@types/node": ">=12.0.0", "chai": "^4.2.0", "dotenv": "^16.0.1", - "ethers": "^5.4.7", - "hardhat": "^2.10.2", + "ethers": "^5.7.2", + "hardhat": "^2.19.0", "hardhat-gas-reporter": "^1.0.8", "solidity-coverage": "^0.7.21", "ts-node": ">=8.0.0", diff --git a/scripts/deploy.ts b/scripts/deploy.ts index ba3e4e7..e91269f 100644 --- a/scripts/deploy.ts +++ b/scripts/deploy.ts @@ -1,25 +1,63 @@ -import { ethers } from "hardhat"; +import { ethers, run } from "hardhat"; +/** + * The main function deploys a Lock contract with a specified unlock time and locked amount, and then + * verifies the contract on Scrollscan. + */ async function main() { + // Calculate the unlock time as one year from now const currentTimestampInSeconds = Math.round(Date.now() / 1000); const ONE_YEAR_IN_SECS = 365 * 24 * 60 * 60; const unlockTime = currentTimestampInSeconds + ONE_YEAR_IN_SECS; - const lockedAmount = ethers.utils.parseEther("0.00000001"); + // Deploy the Lock contract const Lock = await ethers.getContractFactory("Lock"); const lock = await Lock.deploy(unlockTime, { value: lockedAmount }); await lock.deployed(); console.log(`Lock with 0.00000001 ETH and unlock timestamp ${unlockTime} deployed to ${lock.address}`); - // console.log(`Block explorer URL: https://l2scan.scroll.io/address/${lock.address}`); Uncomment here to use the pre-alpha - console.log(`Block explorer URL: https://blockscout.scroll.io/address/${lock.address}`); + + // Verify the contract on Scrollscan + try { + console.log("Starting verification process..."); + await run("verify:verify", { + address: lock.address, + constructorArguments: [unlockTime], + }); + const network = await ethers.provider.getNetwork(); + // Determine the network and construct the Scrollscan URL + const scrollscanUrl = getScrollscanUrl(network.name); + console.log(`Contract verified. Check on Scrollscan: ${scrollscanUrl}/address/${lock.address}`); + } + catch (error) { + console.error("Error during verification:", error); + } + +} + +/** + * The function `getScrollscanUrl` returns the corresponding URL based on the given network name. + * @param {string} networkName - The `networkName` parameter is a string that represents the name of + * the network. It can have two possible values: "scrollMainnet" or "scrollTestnet". + * @returns a URL based on the provided network name. If the network name is "scrollMainnet", it + * returns "https://scrollscan.com". If the network name is "scrollTestnet", it returns + * "https://sepolia.scrollscan.com". For any other network name, it returns "https://scrollscan.com". + */ +function getScrollscanUrl(networkName: string) { + switch (networkName) { + case "scrollMainnet": + return "https://scrollscan.com"; + case "scrollTestnet": + return "https://sepolia.scrollscan.com"; + default: + return "https://scrollscan.com"; + } } -// We recommend this pattern to be able to use async/await everywhere -// and properly handle errors. +// Execute the main function and handle any errors main().catch((error) => { console.error(error); process.exitCode = 1; -}); +}); \ No newline at end of file diff --git a/test/Lock.ts b/test/Lock.ts index 92e0dc7..59da5a4 100644 --- a/test/Lock.ts +++ b/test/Lock.ts @@ -23,6 +23,8 @@ describe("Lock", function () { return { lock, unlockTime, lockedAmount, owner, otherAccount }; } + /* The code you provided is a test suite for the "Deployment" functionality of a smart contract called + "Lock". */ describe("Deployment", function () { it("Should set the right unlockTime", async function () { const { lock, unlockTime } = await loadFixture(deployOneYearLockFixture); @@ -56,6 +58,8 @@ describe("Lock", function () { }); }); + /* The code you provided is a set of tests for the "Withdrawals" functionality of a smart contract + called "Lock". */ describe("Withdrawals", function () { describe("Validations", function () { it("Should revert with the right error if called too soon", async function () { From e5a50ba6128180d55bdc1b8fe5855cfeca20ded4 Mon Sep 17 00:00:00 2001 From: codeesura <120671243+codeesura@users.noreply.github.com> Date: Wed, 15 Nov 2023 22:09:55 +0300 Subject: [PATCH 2/2] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 81abdde..649f439 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ This project demonstrates how to use hardhat or foundry to deploy a contract in ## Prerequisites -- Network setup: https://guide.scroll.io/user-guide/setup +- Network setup: [Guide](https://guide.scroll.io/user-guide/setup) ## Deploy with Hardhat