• Stars
    star
    181
  • Rank 212,110 (Top 5 %)
  • Language
    Solidity
  • Created almost 2 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A boilerplate for getting started with optimism
Optimism

This is a Optimism + wagmi + Foundry + Rainbowkit + Vite project originally bootstrapped with create-wagmi built with ❤️ for hackers.

Who is this for?

This starter is a great choice for any of the following groups:

Getting Started

Install Node

See here. Note that you need Node at a later version than 14.18.0, or 16 and above. These instructions were verified with Node 18.

Install Foundry

You will need to install Foundry to build your smart contracts.

  1. Run the following command:

    curl -L https://foundry.paradigm.xyz | bash
  2. Source your environment as requested by Foundry.

  3. Run foundryup.

Start the application

starter-app-screenshot

  1. Clone/fork the optimism-starter repo

    git clone https://github.com/ethereum-optimism/optimism-starter.git
  2. Install the necessary node packages:

    cd optimism-starter
    npm install
  3. Start the frontend with npm run dev

    npm run dev

    If you get errors during this step, you might need to update your Foundry to the latest version.

  4. Open localhost:5173 in your browser.

    Once the webpage has loaded, changes made to files inside the src/ directory (e.g. src/App.tsx) will automatically update the webpage.

See below for general usage instructions or FAQ for answers to general questions such as:

Generate ABIs & React Hooks

This project comes with @wagmi/cli built-in, which means you can generate wagmi-compatible (type safe) ABIs & React Hooks straight from the command line.

To generate ABIs & Hooks, follow the steps below.

Generate code

To generate ABIs & React Hooks from your Foundry project (in ./contracts), you can run:

npm run wagmi

This will use the wagmi config (wagmi.config.ts) to generate a src/generated.ts file which will include your ABIs & Hooks that you can start using in your project.

Here is an example of Hooks from the generated file being used.

Deploying Contracts

To deploy your contracts to a network, you can use Foundry's Forge – a command-line tool to tests, build, and deploy your smart contracts.

You can read a more in-depth guide on using Forge to deploy a smart contract here, but we have included a simple script in the package.json to get you started.

Below are the steps to deploying a smart contract to Ethereum Mainnet using Forge:

Set up environment

Get an Etherscan key

  1. Register for Etherscan on Optimism. This account is different from your normal Etherscan account.

  2. Go to the API keys page and click Add to create a new API key.

Specify .env

You will first need to set up your .env to tell Forge where to deploy your contract.

  1. Copy .env.example to .env.

    cp .env.example .env
  2. Edit your .env to specify the environment variables.

    • ETHERSCAN_API_KEY: Your Etherscan API Key.

    • FORGE_RPC_URL: The RPC URL of the network to which you deploy. If you use Alchemy, your URL will look like this: https://opt-goerli.g.alchemy.com/v2/<Alchemy API Key>

    • FORGE_PRIVATE_KEY: The private key of the wallet you want to deploy from.

Deploy contract

You can now deploy your contract!

npm run deploy

Developing with Anvil (Optimism Mainnet Fork)

Let's combine the above sections and use Anvil alongside our development environment to use our contracts (./contracts) against an Optimism fork.

Start dev server

Run the command:

npm run dev:foundry

This will:

  • Start a vite dev server,
  • Start the @wagmi/cli in watch mode to listen to changes in our contracts, and instantly generate code,
  • Start an Anvil instance (Goerli Optimism Fork) on an RPC URL.

Deploy our contract to Anvil

Now that we have an Anvil instance up and running, let's deploy our smart contract to the Anvil network:

npm run deploy:anvil

Start developing

Now that your contract has been deployed to Anvil, you can start playing around with your contract straight from the web interface!

Head to localhost:5173 in your browser, connect your wallet, and try increment a counter on the Foundry chain. Use the generated code in src/generated.ts to do it and follow the Attestooooor component as an example

Tip: If you import an Anvil private key into your browser wallet (MetaMask, Coinbase Wallet, etc) – you will have 10,000 ETH to play with 😎. The private key is found in the terminal under "Private Keys" when you start up an Anvil instance with npm run dev:foundry.

Alternatives

Looking to use burner wallets? Prefer hardhat? Prefer NEXT.js? Check out these amazing alternatives:

  • create wagmi cli - A flexible cli with many templates (this starterkit was started from vite-react-cli-foundry)
  • scaffold-eth - The new 2nd version of a popular NEXT.js based starter including hardhat, burner wallets, great documentation, and an active telegram for support
  • Awesome wagmi - Has other alternative examples
  • Create Eth App - Uses a wagmi alternative called useDapp that is used at OP Labs

Learn more

To learn more about Optimism, Vite, Foundry, Rainbow kit or wagmi, check out the following resources:

More Repositories

1

optimism

Optimism is Ethereum, scaled.
Go
5,605
star
2

optimism-tutorial

Build your first app on Optimism!
Solidity
735
star
3

cannon

On chain interactive fault prover for Ethereum
Solidity
582
star
4

community-hub

Optimism Governance Docs
MDX
321
star
5

ecosystem-contributions

Find ways to contribute to the Optimism Collective
TypeScript
303
star
6

ethereum-optimism.github.io

Unified token list for OP Mainnet, Base, and other OP Chains
TypeScript
264
star
7

contracts

[Optimism] Smart Contracts
Solidity
258
star
8

optimistic-specs

Optimistic: Bedrock, is a protocol that strives to be an extremely simple optimistic rollup that maintains 1:1 compatibility with Ethereum
Go
168
star
9

OPerating-manual

OPerating Manual of the Optimism Collective. https://optimism.io/vision
142
star
10

op-geth

Go
129
star
11

optimism-project-ideas

Ways to contribute to the Optimism Collective
113
star
12

kona

A suite of `no_std` components for the OP Stack state transition function.
Rust
103
star
13

op-analytics

Onchain Data, Utilities, References, and other Analytics on Optimism
Jupyter Notebook
100
star
14

asterisc

RISC-V interactive fraud-proof tech
Go
96
star
15

ecosystem

Optimism is Ethereum, scaled.
TypeScript
77
star
16

docs

Optimism Developer Docs
MDX
76
star
17

smock

[Optimism] Solidity mock contracts in JavaScript
TypeScript
73
star
18

superchain-registry

An index of chains which serves as the source of truth for who’s in the Superchain Ecosystem
Go
70
star
19

developers

This repository is to serve as a place where builders on every level of the OP Stack can come to collaborate.
68
star
20

brand-kit

Brand assets for Optimism
67
star
21

optimism-integration

[Optimism] Service Integration & Rapid Development
Shell
48
star
22

go-ethereum

[Optimism] Go implementation of the Optimistic Ethereum protocol
Go
39
star
23

solidity

[Optimism] (Slightly) modified Solidity compiler
C++
37
star
24

superchain-ops

Solidity
36
star
25

axos

Portable no-std Derivation Pipeline engineered in pure Rust
Rust
27
star
26

superchain-relayer

Interface to relay messages from L2 to L1 for chains in the Superchain like Base, Zora, and OP Mainnet
TypeScript
26
star
27

Truffle-ERC20-Example

A simple ERC20 token project in Truffle to get started with the OVM
JavaScript
23
star
28

minigeth

Stripped-down oracle-augmented version of geth for use in fault proofs.
Go
23
star
29

lib-keccak

Keccak-f[1600] permutation in the EVM
Solidity
22
star
30

verifier

[Optimism] Layer 2 Verifier
JavaScript
21
star
31

supersim

Local Multi-L2 Development Environment
Go
20
star
32

merch

official optimism merch instructions
19
star
33

reference-optimistic-geth

Go
17
star
34

optimism-mud-starter

A MUD based starterkit by optimism
TypeScript
17
star
35

optimism-ts-services

[Optimism] Client-Side Services
TypeScript
15
star
36

tests

Standard Tests for OP Stack Component Implementations.
Rust
14
star
37

Waffle-ERC20-Example

A simple ERC20 token project in Waffle to get started with the OVM
Solidity
14
star
38

batch-submitter

[Optimism] Batches go zoom
TypeScript
11
star
39

plugins

[Optimism] Plugins!
TypeScript
11
star
40

data-transport-layer

[Optimism] Shuttling data from L1 all day.
TypeScript
11
star
41

infra

Optimism is Ethereum, scaled.
Go
11
star
42

regenesis

[Optimism] State Dumps & Regenesis Automation
JavaScript
10
star
43

optimistic-pm

Modeled after https://github.com/ethereum/eth2.0-pm
9
star
44

.github

[Optimism] Default GitHub configuration files
9
star
45

integration-tests

[Optimism] Service Integration Tests
TypeScript
8
star
46

tx-overload

Go
7
star
47

chug-splash

Chuggin' and splashin', splashin' and chuggin'. Chugslash!
TypeScript
7
star
48

stack-docs

OP Stack documentation
Vue
4
star
49

workshops

Workshops that we teach
Solidity
3
star
50

docker

[Optimism] Dockerfiles and Entrypoints
Shell
2
star
51

design-docs

2
star
52

changelog

HTML
2
star
53

optimism-faq-bot

Optimism FAQ bot for Discord. A fork of Rari-Capital's FAQ bot :0
Python
2
star
54

l2-geth-state-dumper

A small utility for generating an L2 genesis state
Go
2
star
55

service-base

[Optimism] A simple framework for stateful JS services
TypeScript
2
star
56

ovm-subgraphs

TypeScript
1
star
57

keygeneration

[Optimism] Airgapped Key Generation
Shell
1
star
58

scripts

[Optimism] Various misc. scripts
JavaScript
1
star
59

bailiff

Go
1
star