A TypeScript template for @tableland + NextJS + wagmi + Rainbowkit projects
This repo contains starter code for a NextJS + wagmi + Rainbowkit project with useful Tableland clients included, bootstrapped using create-next-app. It contains a basic example for connecting to a wallet to then allow creating, writing to, and reading a table using the Tableland SDK (@tableland/js-tableland)) as well as Local Tableland (@tableland/local) support during development. Both linting (with eslint) and code formatting (with prettier) are also included, along with Tailwind CSS.
Before you get started, you'll need to create a WalletConnect account and create a project and retrieve the project ID: here
RainbowKit & wagmi require a WalletConnect project ID in order to work properly. These should be set up and configured in a .env file within this project's root and saved to the following variables:
NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID=your_wallet_connect_project_idThere's also a NEXT_PUBLIC_ENABLE_TESTNETS boolean value you can set in order to enable or disable wallet connections to testnet chains. All of the chains that Tableland supports are configured, including the Hardhat chain if you choose to run Local Tableland during development.
First, clone this repo:
git clone https://github.com/tablelandnetwork/next-ts-tableland-templateTo get started, you can run npm run up to start the app. This runs npm install plus the build / start scripts and then serves the application at http://localhost:3000. The starter template includes the following, located in src/components/Tableland.tsx:
- Navbar wallet connection using RainbowKit.
- A form with inputs for creating a table (hardcoded with a
id INTEGER PRIMARY KEY, val TEXTschema) and writing a single value to it. - Reading and rendering your table's data on button click.
The wagmi setup occurs in src/app/providers and src/wagmi.ts. Lastly, there is a useSigner hook in src/hooks/useSigner.ts. It's a required adapter for ethers to work with wagmi (and RainbowKit), which use viem under the hood.
If you'd like to run the project locally, use the following scripts in separate terminal windows:
npm run lt
npm run devThis will do two things: spin up a Local Tableland node and run the app in development mode to reflect live code changes. Local Tableland is an extremely useful tool to develop as it's a lightweight Tableland validator (also spinning up a Hardhat node under the hood) that runs locally on your machine with full Tableland protocol compliance.
There are also a few other scripts you can use:
npm run lint: Lint the codebase witheslint(along with thelint:fixoption).npm run prettier: Prettify the code format withprettier(along with theprettier:fixoption).npm run format: Both lint and format the codebase witheslintandprettier, also fixing any issues it can.npm run clean: Remove the.nextfolder.npm run test: A placeholder for running tests (currently empty).
PRs accepted.
Small note: If editing the README, please conform to the standard-readme specification.
MIT AND Apache-2.0, © 2021-2023 Tableland Network Contributors