From d0228f63b4a268fdf096bcb55ec7d48ba96e3874 Mon Sep 17 00:00:00 2001 From: d1onys1us <13951458+d1onys1us@users.noreply.github.com> Date: Mon, 15 May 2023 19:14:16 -0400 Subject: [PATCH] add hardhat deploy and verify guides --- packages/website/pages/docs/guides.mdx | 3 +- .../pages/docs/guides/deploy-a-contract.mdx | 66 ++++++++++++---- .../pages/docs/guides/verify-a-contract.mdx | 77 +++++++++++++++++-- 3 files changed, 126 insertions(+), 20 deletions(-) diff --git a/packages/website/pages/docs/guides.mdx b/packages/website/pages/docs/guides.mdx index f6b8b94c98f..8ff1cdc7a67 100644 --- a/packages/website/pages/docs/guides.mdx +++ b/packages/website/pages/docs/guides.mdx @@ -1,4 +1,5 @@ -Here are the testnet guides: +# Guides +Follow the testnet guides: - 👛 [Configure your wallet](/docs/guides/configure-your-wallet) - 💦 [Receive tokens](/docs/guides/receive-tokens) - 🌉 [Use the bridge](/docs/guides/use-the-bridge) diff --git a/packages/website/pages/docs/guides/deploy-a-contract.mdx b/packages/website/pages/docs/guides/deploy-a-contract.mdx index 0ea12e80d30..caa3688b18e 100644 --- a/packages/website/pages/docs/guides/deploy-a-contract.mdx +++ b/packages/website/pages/docs/guides/deploy-a-contract.mdx @@ -1,23 +1,21 @@ -import { Callout, Steps } from "nextra-theme-docs"; - - - To be safe, make sure you're using a throwaway wallet. Don't reveal the private key of a wallet with significant value! - +import { Callout, Steps, Tab, Tabs } from "nextra-theme-docs"; ## Overview -This guide will help you deploy a smart contract to Taiko using Foundry. +This guide will help you deploy a smart contract to Taiko using Foundry or Hardhat. ## Prerequisites -- [Foundry](https://book.getfoundry.sh/getting-started/installation) is installed. -- You have some testnet ETH on Taiko (to pay the transaction fee for deploying the contract). +- You have [Foundry](https://book.getfoundry.sh/getting-started/installation) or [Hardhat](https://hardhat.org/hardhat-runner/docs/getting-started#quick-start) installed. +- You have testnet ETH on Taiko (to pay the transaction fee for deploying the contract). - You can [request Sepolia ETH](/docs/guides/receive-tokens) from the faucet and then [use the bridge](/docs/guides/use-the-bridge) to send the testnet ETH to Taiko. -- You have the private key ready to the account with testnet ETH on Taiko. +- You have the private key to the account with testnet ETH on Taiko. ## Steps - + + + ### Create a project with Foundry ```sh forge init hello_foundry && cd hello_foundry @@ -25,10 +23,52 @@ This guide will help you deploy a smart contract to Taiko using Foundry. ### Deploy your contract Deploy the contract located at `src/Counter.sol`. Replace `YOUR_PRIVATE_KEY` below with your private key which has some testnet ETH on Taiko. + + Use a throwaway wallet to be safe. Don't reveal the private key of a wallet with significant value! + + ```sh - forge create --rpc-url https://rpc.a2.taiko.xyz --private-key YOUR_PRIVATE_KEY src/Counter.sol:Counter + forge create --rpc-url https://l2rpc.internal.taiko.xyz --private-key YOUR_PRIVATE_KEY src/Counter.sol:Counter ``` ### View your contract - Paste the address from the output into the [Taiko block explorer](https://explorer.a2.taiko.xyz) and verify that the contract was deployed. - \ No newline at end of file + Paste the address from the output into the [Taiko block explorer](https://l2explorer.internal.taiko.xyz) and verify that the contract was deployed. + + + + + ### Create a project with Hardhat + ```sh + npx hardhat + ``` + + ### Add Taiko to your Hardhat config + ```ts {6-13} filename=hardhat.config.ts + import { HardhatUserConfig } from "hardhat/config"; + import "@nomicfoundation/hardhat-toolbox"; + + const config: HardhatUserConfig = { + solidity: "0.8.18", + networks: { + taiko: { + url: "http://l2rpc.internal.taiko.xyz", + accounts: [ + "0xf214f2b2cd398c806f84e317254e0f0b801d0643303237d97a22a48e01628897", + ], + }, + }, + }; + + export default config; + ``` + + ### Deploy your contract on Taiko + ```sh + npx hardhat run --network taiko scripts/deploy.ts + ``` + + ### View your contract + Paste the address from the output into the [Taiko block explorer](https://l2explorer.internal.taiko.xyz) and verify that the contract was deployed. + + + diff --git a/packages/website/pages/docs/guides/verify-a-contract.mdx b/packages/website/pages/docs/guides/verify-a-contract.mdx index a88e4ddbd9f..6e4f60a2bb7 100644 --- a/packages/website/pages/docs/guides/verify-a-contract.mdx +++ b/packages/website/pages/docs/guides/verify-a-contract.mdx @@ -1,17 +1,82 @@ +import { Callout, Steps, Tab, Tabs } from "nextra-theme-docs"; + ## Overview This guide will help get your contract verified on Taiko! ## Prerequisites -- You have a contract deployed on Taiko. +- You have [Foundry](https://book.getfoundry.sh/getting-started/installation) or [Hardhat](https://hardhat.org/hardhat-runner/docs/getting-started#quick-start) installed. +- You have a contract deployed on Taiko and the source code available. ## Steps -### Foundry -1. Use the older nightly version of Forge with `foundryup --version nightly-94777647f6ea5d34572a1b15c9b57e35b8c77b41` (see why [here](https://github.com/foundry-rs/foundry/issues/4909)). -2. Run `forge verify-contract : --chain-id 167001 --verifier-url https://l2explorer.internal.taiko.xyz/api --verifier blockscout` to verify your contract. + + + + ### Install Forge + You will need an older nightly version of Forge installed (see why [here](https://github.com/foundry-rs/foundry/issues/4909)): + ```sh + foundryup --version nightly-94777647f6ea5d34572a1b15c9b57e35b8c77b41 + ``` + + ### Verify the contract + Replace `CONTRACT_ADDRESS` and `CONTRACT_FILE:CONTRACT_NAME` and run the `verify-contract` command: + ```sh + forge verify-contract CONTRACT_ADDRESS CONTRACT_FILE:CONTRACT_NAME --chain-id 167001 --verifier-url https://l2explorer.internal.taiko.xyz/api --verifier blockscout + ``` + + + + + ### Add Etherscan config to Hardhat config + + Even though the config is called `etherscan`, it is used for all explorers that support the Etherscan API (including Blockscout). The API key is set to a dummy value `42069` because it is not used for Blockscout verification. + + + ```ts {14-28} filename=hardhat.config.ts + import { HardhatUserConfig } from "hardhat/config"; + import "@nomicfoundation/hardhat-toolbox"; + + const config: HardhatUserConfig = { + solidity: "0.8.18", + networks: { + taiko: { + url: "https://l2rpc.internal.taiko.xyz", + accounts: [ + "0xf214f2b2cd398c806f84e317254e0f0b801d0643303237d97a22a48e01628897", + ], + }, + }, + etherscan: { + apiKey: { + taiko: "42069", + }, + customChains: [ + { + network: "taiko", + chainId: 167001, + urls: { + apiURL: "https://l2explorer.internal.taiko.xyz/api", + browserURL: "https://l2explorer.internal.taiko.xyz", + }, + }, + ], + }, + }; + + export default config; + ``` + + ### Run the verify task + Run the verify task, but replace `DEPLOYED_CONTRACT_ADDRESS` and `"Constructor argument 1"` with the address of your deployed contract and the constructor arguments you used when deploying the contract. -### Hardhat + ```sh + npx hardhat verify --network taiko DEPLOYED_CONTRACT_ADDRESS "Constructor argument 1" + ``` -TODO + ### View your verified contract on Blockscout + Check the [Taiko block explorer](https://l2explorer.internal.taiko.xyz) link from the output to see your contract was verified. + + +