Skip to content

Latest commit

 

History

History
117 lines (68 loc) · 4.42 KB

README.md

File metadata and controls

117 lines (68 loc) · 4.42 KB

wentokens

This is a wagmi + Foundry + Vite project bootstrapped with create-wagmi

Running Frontend

After running yarn to install dependencies, run yarn dev in your terminal and then 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.

Generating 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.

Install Foundry

First, you will need to install Foundry in order to build your smart contracts. This can be done by running the following command:

curl -L https://foundry.paradigm.xyz | bash

Generate Code

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

yarn 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 where Hooks from the generated file is 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:

Install Foundry

Make sure you have Foundry installed & set up.

See the above instructions.

Set Up Environment

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

Go ahead and open up your .env file, and enter the following env vars:

  • ETHERSCAN_API_KEY: Your Etherscan API Key.
  • FORGE_RPC_URL: The RPC URL of the network to deploy to.
  • FORGE_PRIVATE_KEY: The private key of the wallet you want to deploy from.

Deploy Contract

You can now deploy your contract!

yarn deploy

Developing with Anvil (Mainnet Fork)

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

Install Foundry

Make sure you have Foundry installed & set up.

See the above instructions.

Start Dev Server

Run the command:

yarn 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 (Mainnet Fork) on an RPC URL.

Deploy Contract to Anvil

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

yarn 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 the counter on the Foundry chain.

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 yarn dev:foundry.

Learn more

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