Skip to content

Commit

Permalink
add hardhat deploy and verify guides
Browse files Browse the repository at this point in the history
  • Loading branch information
dionysuzx committed May 15, 2023
1 parent f241953 commit d0228f6
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 20 deletions.
3 changes: 2 additions & 1 deletion packages/website/pages/docs/guides.mdx
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
66 changes: 53 additions & 13 deletions packages/website/pages/docs/guides/deploy-a-contract.mdx
Original file line number Diff line number Diff line change
@@ -1,34 +1,74 @@
import { Callout, Steps } from "nextra-theme-docs";

<Callout type="warning" emoji="⚠️">
To be safe, make sure you're using a throwaway wallet. Don't reveal the private key of a wallet with significant value!
</Callout>
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

<Steps>
<Tabs items={["Foundry", "Hardhat"]} defaultIndex="0">
<Tab>
<Steps>
### Create a project with Foundry
```sh
forge init hello_foundry && cd hello_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.
<Callout type="warning">
Use a throwaway wallet to be safe. Don't reveal the private key of a wallet with significant value!
</Callout>

```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.
</Steps>
Paste the address from the output into the [Taiko block explorer](https://l2explorer.internal.taiko.xyz) and verify that the contract was deployed.
</Steps>
</Tab>
<Tab>
<Steps>
### 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.
</Steps>
</Tab>
</Tabs>
77 changes: 71 additions & 6 deletions packages/website/pages/docs/guides/verify-a-contract.mdx
Original file line number Diff line number Diff line change
@@ -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 <contract-address> <contract-file>:<contract-name> --chain-id 167001 --verifier-url https://l2explorer.internal.taiko.xyz/api --verifier blockscout` to verify your contract.
<Tabs items={["Foundry", "Hardhat"]} defaultIndex="0">
<Tab>
<Steps>
### 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
```
</Steps>
</Tab>
<Tab>
<Steps>
### Add Etherscan config to Hardhat config
<Callout type="info">
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.
</Callout>

```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.
</Steps>
</Tab>
</Tabs>

0 comments on commit d0228f6

Please sign in to comment.