A production-ready SvelteKit template for building Web3 dApps with Reown AppKit, Ethers.js, and Skeleton UI.
.nvmrc for recommended version)nvm use after cloning to automatically use the correct versionThis project uses pnpm as the package manager. pnpm offers significant advantages:
Install pnpm:
# Using npm
npm install -g pnpm
# Using Homebrew (macOS)
brew install pnpm
# Using standalone script
curl -fsSL https://get.pnpm.io/install.sh | sh -
ā ļø Important: While npm may work, we strongly recommend using pnpm for the best experience. The project is configured and tested with pnpm.
Clone this repository
git clone <your-repo-url>
cd template
Use the correct Node.js version
# If using nvm
nvm use
# Or manually install/use Node.js 20.19.0+
nvm install 20.19.0
nvm use 20.19.0
Install dependencies
pnpm install
Set up environment variables
cp env.example .env
Get your project ID from Reown Cloud and add it to .env:
VITE_PROJECT_ID=your_project_id_here
Start the development server
pnpm run dev
Open your browser Navigate to http://localhost:5173
src/
āāā lib/
ā āāā components/
ā ā āāā ContractInteraction.svelte # Contract interaction component
ā ā āāā ETHBalance.svelte # ETH balance display
ā ā āāā LightSwitch.svelte # Theme toggle component
ā ā āāā Navbar.svelte # Navigation with wallet connect
ā ā āāā NetworkStatus.svelte # Network status display
ā ā āāā TransactionButton.svelte # Transaction handling component
ā ā āāā WalletConnect.svelte # Enhanced wallet connect component
ā ā āāā WalletStatus.svelte # Main wallet status component
ā āāā config/
ā ā āāā appkit.ts # Reown AppKit configuration
ā ā āāā contracts.ts # Contract configurations
ā āāā stores/
ā ā āāā walletStore.ts # Wallet state management
ā ā āāā index.ts # Store exports
ā āāā utils/
ā ā āāā web3.ts # Web3 utility functions
ā āāā mint.css # Skeleton UI theme
āāā routes/
ā āāā +layout.svelte # Main layout with navbar
ā āāā +page.svelte # Homepage with wallet demo
āāā app.css # Global styles
āāā app.d.ts # TypeScript definitions
āāā app.html # HTML template
The template includes a complete wallet integration system:
import { account, network, isWalletConnected, walletActions } from '$lib/stores/walletStore';
// Check if wallet is connected
if ($isWalletConnected) {
console.log('Connected to:', $account.address);
console.log('Network:', $network.chainId);
}
// Open wallet modal
walletActions.open();
// Switch network (async)
await walletActions.switchNetwork(8453); // Base mainnet
Use Ethers.js for blockchain interactions:
import { ethers } from 'ethers';
import { walletActions } from '$lib/stores/walletStore';
async function getBalance() {
const provider = walletActions.getProvider();
if (provider) {
const ethersProvider = new ethers.BrowserProvider(provider);
const balance = await ethersProvider.getBalance(address);
return ethers.formatEther(balance);
}
}
The template includes automatic theme switching:
import { modal } from '$lib/config/appkit';
// Switch to dark mode
modal.setThemeMode('dark');
// Switch to light mode
modal.setThemeMode('light');
All scripts should be run with pnpm:
pnpm run dev - Start development serverpnpm run build - Build for productionpnpm run preview - Preview production buildpnpm run check - Run TypeScript checks (ensures zero errors/warnings)pnpm run check:watch - Run TypeScript checks in watch modeThis project includes pre-commit hooks (via Husky) that automatically:
pnpm run check)This ensures code quality and prevents commits with errors or warnings.
Update src/lib/config/appkit.ts:
import { polygon, polygonMumbai } from '@reown/appkit/networks';
// Add to networks array
networks: [base, baseSepolia, polygon, polygonMumbai]
Modify src/lib/mint.css or create new theme files in the src/lib/ directory.
Create new components in src/lib/components/ and import them where needed.
Main wallet connection component with network status, address display, and disconnect functionality.
<WalletStatus />
Shows the current ETH balance for the connected wallet.
<ETHBalance />
Displays current network status and online/offline state.
<NetworkStatus />
Handles transaction sending with loading states and error handling.
<TransactionButton>
Send Transaction
</TransactionButton>
Generic component for interacting with smart contracts.
<ContractInteraction
contractAddress="0x..."
abi={contractABI}
functionName="transfer"
args={[recipient, amount]}
>
Transfer Tokens
</ContractInteraction>
Theme toggle component for switching between light and dark modes.
<LightSwitch />
Replace any npm commands with pnpm:
# Install dependencies
pnpm install
# Add a new dependency
pnpm add <package-name>
# Add a dev dependency
pnpm add -D <package-name>
# Remove a dependency
pnpm remove <package-name>
If you're using nvm, the project includes a .nvmrc file. Simply run:
nvm use
This will automatically switch to the correct Node.js version (20.19.0).
MIT License - feel free to use this template for your projects!