This was made for a workshop in the King of Devs 2.0 Hackathon.
A video version of going through the setup and the code step by step can be found here:
A simple app that allows you to login with your browser wallet and interact with a simple Storage.sol contract.
At the time of building this npm was broken with the wagmi cli so I used pnpm. Now I've submitted a PR that solved that so feel free to use npm
$ mkdir contracts
$ cd contracts
$ pnpm init
$ pnpm add --save-dev hardhat
$ pnpm hardhat
> Select typescript
> Install dependencies
Replace default Lock Contract with Storage contract
$ pnpm hardhat compile
Editar el script de deploy
Iniciar el nodo de hardhat en otra consola
$ pnpm hardhat node
Nos va a tirar unas llaves privadas. Guardamos una de estas y la importamos en Metamask para poder usar desde la app frontend.
Hacer el deployment en red local:
$ pnpm hardhat compile
$ pnpm hardhat run scripts/deploy.ts --network localhost
Copiar el address del contrato (Usando plugins como hardhat deploy se puede automatizar este paso)
$ mkdir frontend
$ cd frontend
$ pnpm init
$ pnpm add --save-dev create-t3-app
$ pnpm create-t3-app
> select "." as project folder
> Select Tailwind, to make the demo pretty
> Select overwrite directory
$ pnpm add --save-dev @wagmi/cli
$ pnpm add wagmi ethers@^5
$ pnpx wagmi init
Add hardhat and react plugins
Run the generate command
$ pnpm wagmi generate
This generates a file with an abi for the contract and hooks using the abi. You migth want to add this file to your .gitignore and ignore it on your linter.
In src/pages/app.tsx
add chain config, client and wrap the app in a Wagmi Client as the guide here shows
Go to src/pages/index.tsx
and delete the page content.
Add the code to connect to the wallet
- Clone this and name it as you want
- cd into contracts
- run
pnpm install
- run
pnpm hardhat compile
- run
pnpm hardhat node
and leave it running - run
pnpm hardhat run scripts/deploy.ts --network localhost
- run
- cd into frontend
- run
pnpm install
- run
pnpm wagmi generate
- run
pnpm dev
- run