Rootstock Wagmi Starter Kit
The Rootstock Wagmi starter kit provides a foundation for building decentralized applications (dApps) on the Rootstock blockchain. It leverages the security of Bitcoin and the flexibility of Ethereum.
The kit uses Wagmi, a React Hooks library, to simplify smart contracts and blockchain network interactions and and Shadcn libraries.
This starter kit is designed to help developers jump-start their dApp development journey on Rootstock.
Prerequisites
- Node.js and Git: Ensure to have Node.js and Git installed on your system.
- See the Prerequisites section for how to download Node.js using NVM.
- Yarn: Install Yarn, a package manager for Node.js projects. You can do this by running the following command in your terminal:
npm install -g yarn - Basic Knowledge:
Learn how to write, test, secure, deploy and verify smart contracts on the Rootstock blockchain network. Enroll for the Rootstock Blockchain Developer Course.
Setup
1. Clone the Repository
First, you’ll need to clone the Rootstock Wagmi Starter Kit repository. Open your terminal and run the following commands:
git clone https://github.com/rsksmart/rsk-wagmi-starter-kit
cd rsk-wagmi-starter-kit
2. Get Project ID
Every dApp that relies on WalletConnect now needs to obtain a projectId from WalletConnect Cloud. This is free and only takes few minutes.
To get the key:
- Go to Walletconnect and sign up.
- Create a new project by clicking on Create Project.
- Add a Name and Link to your project, select a product (AppKit or WalletKit), select WalletKit.
- Now you will see the project ID, copy it.
3. Environment Setup
To set up your environment, follow these steps:
- Create a
.envfile and add environment variables.VITE_WC_PROJECT_ID=Your projectid from cloud Walletconnect
4. Install Dependencies
Before running the project, make sure to have the necessary dependencies installed. We recommend using the yarn package manager due to potential conflicts with npm packages. Run the following command to install dependencies:
yarn
5. Run the Project
Now that you’ve cloned the repository and installed dependencies, it’s time to run the project. Execute the following command:
yarn dev
This will start the Rootstock Wagmi Starter dApp locally, allowing you to develop and test your smart contracts. You can access the Vite server at http://localhost:5173.
Result
After successfully running your project using the command above, do the following:
- Click the “Connect Wallet” button to log in. Once connected, you can:
- Switch Networks: Easily switch between Mainnet and Testnet.
- View and Copy Your Address: Access your wallet address.
- Check Your tRBTC Balance: See your tRBTC balance.
- Disconnect: Log out from the project.
Test Project
To test the Wagmi project, follow these simple steps:
- Connect Your Wallet: Click the “Connect Wallet” button.
- Navigate to the Wagmi Section: Scroll down and find the card labeled “Contract Interaction with Wagmi Starter Kit.” Click on it.
- Explore the Tabs: In the Wagmi section, you’ll see three tabs: ERC-20, ERC-721, and ERC-1155. Click on any of these tabs to explore further.
Understanding the Codebase
Folder Structure
Public
Src
.env
.env.example
The src folder is organized to streamline the development process and make it easy to locate specific code or assets. Here's a detailed breakdown:
.src Folder Structure
- Assets: Contains the ABIs (Application Binary Interfaces) for ERC20, ERC721, and ERC1155.
- Components:
- AccountAbstraction: Contains code related to account abstraction.
- Home: Holds components specific to the homepage.
- Icons: Contains various icon components.
- Tokens: Includes components for different token types.
- UI: General UI components used across the application.
- Footers.tsx: Footer component.
- Navbar.tsx: Navbar component.
- Config:
- provider.tsx: Configuration for providers.
- rainbowkitConfig.ts: Configuration for RainbowKit.
- wagmiProviderConfig.ts: Configuration for WAGMI providers.
- Lib: Contains various utility folders for easy organization:
- Constants: Application constants.
- Functions: General functions used across the app.
- Types: Type definitions.
- Utils: Utility functions.
- Pages:
- index.ts: Main entry point.
- Etherspot.tsx: Page component for Etherspot.
- Home.tsx: Homepage component.
- Wagmi.tsx: Wagmi-related page component.