Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quickstart updates #268

Merged
merged 2 commits into from
Aug 23, 2023
Merged
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
95 changes: 84 additions & 11 deletions docs/build-on-linea/quickstart/deploy-smart-contract/foundry.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
---
title: Foundry
sidebar_position: 3
sidebar_position: 2
---

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

# Foundry

In this tutorial, we'll walk through creating a basic [Foundry](https://book.getfoundry.sh/) project.
Expand All @@ -26,7 +29,7 @@ Before you begin, Ensure you've:

## Create a Foundry project

To create an empty Foundry project, run:
To create a Foundry project, run:

```bash
forge init linea-tutorial
Expand All @@ -38,26 +41,58 @@ And change into the directory:
cd linea-tutorial
```

## Write the smart contract
## Deploy a smart contract

Running `forge init` sets you up with a sample contract, test, and script for `Counter.sol`. To build it, simply run `forge build`.

## Deploy the smart contract
To deploy a smart contract, we highly recommend using an Infura endpoint, as the public endpoint may experience rate limiting.

:::caution

These instructions use API keys and private keys inline. We highly recommend hiding them in `.env` files [by following the instructions below](#using-env-to-store-private-keys).

:::

<Tabs className="my-tabs">
<TabItem value="Infura" label="Infura" default>

To deploy a smart contract, we highly recommend using an Infura endpoint, as the public endpoint may experience rate limiting. You can find out how to [get an API key here](https://support.linea.build/hc/en-us/articles/15752713253147). Then, you can run the following command.
To use Infura, you'll need to [get an API key](https://support.infura.io/hc/en-us/articles/15116941373979-Connecting-to-the-Linea-network)

Using Infura:
On testnet:

```bash
forge create --rpc-url https://linea-goerli.infura.io/v3/YOUR-INFURA-API-KEY src/Counter.sol:Counter --private-key YOUR_PRIVATE_KEY
forge create --rpc-url https://linea-goerli.infura.io/v3/INFURA_API_KEY src/Counter.sol:Counter --private-key PRIVATE_KEY
```

Using the public endpoint:
On mainnet:

```bash
forge create --rpc-url https://linea.infura.io/v3/INFURA_API_KEY src/Counter.sol:Counter --private-key PRIVATE_KEY
```
</TabItem>
<TabItem value="Public Endpoint" label="Public Endpoint">

:::caution

The public endpoints are rate limited and not meant for production systems.

:::

On testnet:

```bash
forge create --rpc-url https://rpc.goerli.linea.build/ src/Counter.sol:Counter --private-key YOUR_PRIVATE_KEY
```

On mainnet:

```bash
forge create --rpc-url https://rpc.linea.build/ src/Counter.sol:Counter --private-key YOUR_PRIVATE_KEY
```

</TabItem>
</Tabs>

Your output should look a little something like this:

```bash
Expand All @@ -66,8 +101,46 @@ Deployed to: 0xED0Ff7E8B655dFFfCA471ea3B6B649ce7C2C1b83
Transaction hash: 0x967e1290b285e67b3d74940ee19925416734c345f58bd1ec64dcea134647d7ee
```

Next, you can optionally [verify your contract on the network](../verify-smart-contract/foundry.md).
### Using `.env` to store private keys

It is dangerous to directly paste your private key into the command line. One workaround is to use `.env` files to store private information such as your wallet's private keys or API keys. In order to do so, create a `.env` file and add it to your `.gitignore` file. Then, fill it with the following information:

```bash
PRIVATE_KEY=YOUR_PRIVATE_KEY
INFURA_API_KEY=YOUR_INFURA_API_KEY
```

Then, run:

```bash
source .env
```

Finally, we can modify the `foundry.toml` file to conveniently store the various rpc endpoints we might be working with. Add this section:

```bash
[rpc_endpoints]
linea-testnet = "https://linea-goerli.infura.io/v3/${INFURA_API_KEY}"
linea-mainnet = "https://linea.infura.io/v3/${INFURA_API_KEY}"
```

Now, in order to deploy, you can simply run:

<Tabs className="my-tabs">
<TabItem value="Mainnet" label="Mainnet" default>

```bash
forge create --rpc-url linea-mainnet src/Counter.sol:Counter --private-key $PRIVATE_KEY
```

</TabItem>
<TabItem value="Testnet" label="Testnet">

```bash
forge create --rpc-url linea-testnet src/Counter.sol:Counter --private-key $PRIVATE_KEY
```

## Deploy to Mainnet
</TabItem>
</Tabs>

_Instructions coming soon!_
Next, you can optionally [verify your contract on the network](../verify-smart-contract/foundry.md).
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ To deploy to Linea, we'll need to add the network to our `hardhat.config.js`. To
</TabItem>
<TabItem value="Public Endpoint" label="Public Endpoint">

The public endpoints are rate limited and not meant for production systems. However, you can use the public endpoints by modifying `hardhat.config.js` as follows:
The public endpoints are rate limited and not meant for production systems.

```javascript
require("@nomicfoundation/hardhat-toolbox");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Truffle
sidebar_position: 2
sidebar_position: 3
---

import Tabs from '@theme/Tabs';
Expand Down
127 changes: 85 additions & 42 deletions docs/build-on-linea/quickstart/verify-smart-contract/foundry.md
Original file line number Diff line number Diff line change
@@ -1,83 +1,126 @@
---
title: Foundry
sidebar_position: 3
sidebar_position: 2
---

To verify your contracts with Foundry, use Blockscout's verification page and Foundry's [`forge flatten`](https://book.getfoundry.sh/reference/forge/forge-flatten) utility.
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

In this example, we'll walk through verifying the `Counter` smart contract we deployed in the [Foundry deployment quickstart](../deploy-smart-contract/foundry.md).
To verify your Foundry contracts, you can use Foundry's [verify-contract](https://book.getfoundry.sh/reference/forge/forge-verify-contract) to verify contracts on Lineascan.

## Access the Blockscout verification page
You'll need to get a Lineascan (Linea instance of Etherscan) API key by creating an account at [https://lineascan.build/myapikey](https://lineascan.build/myapikey).

In the [Linea block explorer](https://goerli.lineascan.build/), search for your deployed contract address. You can find it in the `Deployed to` address in the Foundry deployment output. In our example, the address is `0xED0Ff7E8B655dFFfCA471ea3B6B649ce7C2C1b83`.
## Verify your smart contract

### Verify a contract that has already been deployed

If you want to verify a contract that has already been deployed, you can use the following commands:

<Tabs>
<TabItem value="Mainnet" label="Mainnet" default>

```bash
Deployer: YOUR_ACCOUNT_NUMBER
Deployed to: 0xED0Ff7E8B655dFFfCA471ea3B6B649ce7C2C1b83
Transaction hash: 0x967e1290b285e67b3d74940ee19925416734c345f58bd1ec64dcea134647d7ee
forge verify-contract --etherscan-api-key LINEASCAN_API_KEY --verifier-url https://api.lineascan.build/api CONTRACT_ADDRESS path_to_contract:contract_name --watch
```

Enter the address in the Blockscout search bar, then select the **Code** tab on the page. An unverified contract should look something like this:
</TabItem>
<TabItem value="Testnet" label="Testnet">

![unverified contract](/img/quests/foundry/foundry_verification_1.png)
```bash
forge verify-contract --etherscan-api-key LINEASCAN_API_KEY --verifier-url https://api-testnet.lineascan.build/api CONTRACT_ADDRESS path_to_contract:contract_name --watch
```

To verify the contract, select **Verify & Publish**, which takes you to the Blockscout verification page pre-populated with your contract address. Select **Via flattened source code**, and select **Next**.
</TabItem>
</Tabs>

![flattened source code option](/img/quests/foundry/foundry_verification_2.png)
You should see something a little like this:

## Flatten the contract source code
```bash
Start verifying contract 0x8de6e9b6c774c8b7aba587ed84e5ad0a45837b16 deployed on mainnet

Submitting verification for [src/Counter.sol:Counter] "0x8dE6e9b6c774c8B7AbA587ED84E5AD0A45837b16".
Submitted contract for verification:
Response: OK
GUID: `ynnfyvwcqev9i5xr1urdqt9kdwx4zkurvpu7rgh2ywmyp22dpy`
URL:
https://etherscan.io/address/0x8de6e9b6c774c8b7aba587ed84e5ad0a45837b16
Contract verification status:
Response: `NOTOK`
Details: `Pending in queue`
Contract verification status:
Response: `OK`
Details: `Pass - Verified`
Contract successfully verified
```

To verify the contract, use the `forge flatten` utility to flatten the smart contract and all its imports into one file. Run the `forge flatten` command as follows:
### Verify a contract upon creation

<!--tabs-->
If you want to verify a contract that has already been deployed, you can use the following commands:

# Syntax
<Tabs>
<TabItem value="Mainnet" label="Mainnet" default>

```bash
forge flatten <CONTRACT_FILE_PATH> --output <OUTPUT_FILE_PATH>
forge create --rpc-url https://linea-goerli.infura.io/v3/INFURA_API_KEY src/Counter.sol:Counter --private-key YOUR_PRIVATE_KEY --verify --verifier-url https://api.lineascan.build/api --etherscan-api-key LINEASCAN_API_KEY
```

# Example
</TabItem>
<TabItem value="Testnet" label="Testnet">

```bash
forge flatten src/Counter.sol --output ./flat.sol
forge create --rpc-url https://linea-goerli.infura.io/v3/INFURA_API_KEY src/Counter.sol:Counter --private-key YOUR_PRIVATE_KEY --verify --verifier-url
l https://api-testnet.lineascan.build/api --etherscan-api-key LINEASCAN_API_KEY
```

<!--/tabs-->
</TabItem>
</Tabs>

In the example, open `flat.sol` and copy paste the code inside:
You can check that it was verified correctly by navigating to the [testnet block explorer](https://goerli.lineascan.build/) or the [mainnet block explorer](https://lineascan.build/) and pasting in the deployed contract address.

```javascript
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
## Using `.env` and `foundry.toml` to store etherscan information

contract Counter {
uint256 public number;
If you don't want to paste your keys inline and have multiple etherscan API keys to manage, you can use `.env` and `foundry.toml` to set up custom configurations.

function setNumber(uint256 newNumber) public {
number = newNumber;
}
Assuming you followed the instructions to create a `.env` file [here](../deploy-smart-contract/foundry.md#using-env-to-store-private-keys), add your Lineascan API key to the file:

function increment() public {
number++;
}
}
```bash
LINEASCAN_API_KEY=YOUR_LINEASCAN_API_KEY
```

In our case, the flattened code matches the `Counter.sol` code, but oftentimes your smart contracts may import libraries and other smart contracts, and the file will look different.
Then, run:

## Get your compiler version
```bash
source .env
```

Foundry compiles your code using the compiler version found in `~/.svm`. To get the compiler version, run `ls ~/.svm`. In this example, the compiler version is `0.8.17`.
Finally, modify `foundry.toml` to include the etherscan configurations:

![get compiler version](/img/quests/foundry/foundry_verification_3.png)
```bash
[etherscan]
linea-testnet = { key = "${LINEASCAN_API_KEY}", url = "https://api-testnet.lineascan.build/api" }
linea-mainnet = { key = "${LINEASCAN_API_KEY}", url = "https://api.lineascan.build/api" }
```

Then, to verify your smart contracts, you can simply run:

## Fill out the Blockscout verification page
<Tabs>
<TabItem value="Mainnet" label="Mainnet" default>

Now, you have all the information to fill out the verification page. It should look something like this:
```bash
forge verify-contract --chain linea-mainnet path_to_contract:contract_name --watch
```

</TabItem>
<TabItem value="Testnet" label="Testnet">

```bash
forge verify-contract --chain linea-testnet path_to_contract:contract_name --watch
```
</TabItem>
</Tabs>

![fill out page](/img/quests/foundry/foundry_verification_4.png)
:::info

Click **Verify & Publish** and you'll be directed to the verified contract page:
Learn more about different configurations for verifying your smart contracts [here](https://book.getfoundry.sh/reference/forge/forge-verify-contract) and [here](https://book.getfoundry.sh/forge/deploying).

![verified contract](/img/quests/foundry/foundry_verification_5.png)
:::
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Truffle
sidebar_position: 2
sidebar_position: 3
---

To verify your contracts, you can use Truffle's verification plugin [truffle-plugin-verify](https://github.com/rkalis/truffle-plugin-verify).
Expand Down
6 changes: 6 additions & 0 deletions project-words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ jssdk
kaszubowski
katex
kato
kdwx
keccak
keyfile
keyholders
Expand Down Expand Up @@ -423,6 +424,7 @@ nomicfoundation
nomiclabs
noninteractive
noreply
NOTOK
nousb
npmjs
npmrc
Expand Down Expand Up @@ -709,6 +711,7 @@ upcheck
upgr
upserts
upvotes
urdqt
urlset
USDL
userland
Expand Down Expand Up @@ -750,12 +753,15 @@ xsoar
yacop
yangshun
yangshunz
ynnfyvwcqev
yourcode
yrbjp
Yuhu
ywmyp
zhou
zkevm
ZKEX
zkurvpu
zkvotev
zonic
zoomable
Expand Down