Skip to content
This repository has been archived by the owner on Jun 5, 2024. It is now read-only.

Add Contract Verification Feature and Update Testnet to Sepolia #10

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -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"
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.


Expand All @@ -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 <lock_amount> \
--constructor-args <unlock_time> \
--private-key <your_private_key> \
Expand All @@ -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 \
Expand Down
29 changes: 29 additions & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as dotenv from "dotenv";

import { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";
import "@nomiclabs/hardhat-etherscan";

dotenv.config();

Expand All @@ -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"
}
}
]
},
};

Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -17,16 +18,16 @@
"@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",
"@types/mocha": "^9.1.0",
"@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",
Expand Down
52 changes: 45 additions & 7 deletions scripts/deploy.ts
Original file line number Diff line number Diff line change
@@ -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;
});
});
4 changes: 4 additions & 0 deletions test/Lock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 () {
Expand Down