An opinionated web3 starter for building dApps.
This stack covers some basic use cases of any DApp like connecting with wallets, support for different chains, Smart contract interaction, BigNumbers helpers, notifications when a transaction is submitted, etc.
Nextjs
Styled components
etherjs
web3-onboard
SWR
Typechain
⚡ Next.js
🔥 TypeScript
💅 Styled-Components
📏 ESLint already configured
💖 Code Formatted with Prettier
🦊 Husky for Git Hooks
🚫 Lint-staged for running linters on Git staged files
🚓 Commitlint to keep main branch organized
⚙️ Bundler Analyzer
👝 Wallet connectivity already implemented
⛓️ Support for multiple ChainIds
⚙️ Add contracts by network backed by Typescript
📄 Auto generated contract types with Typechain
🪝 Contracts methods using typed Hooks (We also support typed multi-calls 😎)
🔢 Bignumber input
👁️ Tx notifications persisted on local-storage
⏳ React Suspense ready with loading fallback
💡 Absolute Imports using @ prefix
🌈 Include basic UI layout
🌓 Light / Dark UI Theme
🇺🇸 I18n support
a. You can fork this repo using Github templates. Follow the instructions.
b. Or you can duplicate and then initialize it locally.
# Create and use dir
~ mkdir myDapp; cd myDapp
# Clone the repo
## Flag `--node=git` is necessary for private repos
~ npx degit git@github.com:bootnodedev/frontend-starter-kit --mode=git
# install dependencies
~ yarn install
# setup environment variables
## Copy `.env.example` and complete missing variables
~ cp .env.example .env.local
# run the app
~ yarn devYou need to configure RPC providers: Alchemy or infura
In .env.local file put your RPC provider API key as a value of NEXT_PUBLIC_INFURA_TOKEN or NEXT_PUBLIC_ALCHEMY_TOKEN
The best and most secure way to add a new chain is:
- Go to
src/constants/config/types.tsand add the new chain value toconst Chains = {} as constconstant. - Run
yarn tsc, it will break in all the places that need to add support for the new chain.
- Put your contracts ABI files in
src/abisas.jsonfile. - Go to
src/constants/config/contracts.ts. - Provide a key name for your contract in
const contracts = {...}. - Provide a contract address for all the chains you have configured.
- Import your contract ABI file and add it to the contract key created in step 3.
Example for USDC contract:
import ERC_20_abi from '@/src/abis/ERC20.json'
export const contracts = constantContracts({
// Other contracts
USDC: {
address: {
[Chains.mainnet]: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
[Chains.goerli]: '0x78dEca24CBa286C0f8d56370f5406B48cFCE2f86',
},
abi: ERC_20_abi,
},
})After adding a new ABI, run yarn typechain to generate the types for the contract.
More info can be found at TypeChain.
To interact with a subgraph you should follow these steps:
- Go to
src/constants/config/subgraph.tsand a new entry toenum subgraphName. - Go to
src/constants/config/subgraph-endpoints.jsonand complete the object following the structure{ chain: [name: endpoint] }.
{
"5": {
"rentals": "subgraph endpoint"
}
}- Create subgraph queries in the folder
src/queries. - run
yarn subgraph-codegen. This step has to be done every time you add or modify a query. - now you will have all the queries typed and available to be called.
import { SubgraphName, getSubgraphSdkByNetwork } from '@/src/constants/config/subgraph'
const { appChainId } = useWeb3Connection()
const gql = getSubgraphSdkByNetwork(appChainId, SubgraphName.Rentals)
const res = gql.useSubgraphErrors()
console.log({ res: res.data?._meta }) // res is typed 😎There are many web3 utilities this starter has implemented, we are adding examples of them progressively.
You can take a look at /examples page.
This tool shows you the percentage each library is using when the final bundle is generated.
yarn analyze