Build a Frontend
Build a simple frontend for your deployed contract with Vite and Wagmi
Choose between using testnet or a local node.
Frontend setup
Choose between using React or Vue for your frontend.
- Create a Vite React project.
npm create vite@latest token-frontend -- --template react-ts --no-interactive - Move into the project folder and install the required packages.
cd token-frontendnpm install npm install wagmi viem@2.x @tanstack/react-query - Create file in the
srcfolder calledwagmi.tsand copy/paste the config below.import { createConfig, http } from 'wagmi'; import { injected } from 'wagmi/connectors'; import { defineChain } from 'viem'; import { anvil } from 'viem/chains'; const zksyncOSTestnet = defineChain({ id: 8022833, name: 'ZKsync OS Developer Preview', nativeCurrency: { name: 'Ether', symbol: 'ETH', decimals: 18 }, rpcUrls: { default: { http: ['https://zksync-os-testnet-alpha.zksync.dev'] } }, blockExplorers: { default: { name: 'ZKsync OS Developer Preview Explorer', url: 'https://zksync-os-testnet-alpha.staging-scan-v2.zksync.dev', }, }, }); export const activeChain = import.meta.env.VITE_CHAIN === 'local' ? anvil : zksyncOSTestnet; export const config = import.meta.env.VITE_CHAIN === 'local' ? createConfig({ chains: [anvil], connectors: [injected()], transports: { [anvil.id]: http(), }, }) : createConfig({ chains: [zksyncOSTestnet], connectors: [injected()], transports: { [zksyncOSTestnet.id]: http(), }, }); - Next, configure the
wagmiand query client providers insrc/main.tsx.import React from 'react'; import ReactDOM from 'react-dom/client'; import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; import { WagmiProvider } from 'wagmi'; import App from './App'; import { config } from './wagmi'; import './index.css'; const queryClient = new QueryClient(); ReactDOM.createRoot(document.getElementById('root')!).render( <React.StrictMode> <WagmiProvider config={config}> <QueryClientProvider client={queryClient}> <App /> </QueryClientProvider> </WagmiProvider> </React.StrictMode> ); - Replace
src/App.tsxwith the code below.
- Create a
.envfile in the root of thetoken-frontendfolder and add your deployed contract address asVITE_CONTRACT_ADDRESS.VITE_CONTRACT_ADDRESS=0x...
- Finally you can start the development server.
npm run dev
Testing the frontend
Now you can test the frontend by opening http://localhost:5173/ in your browser, connecting your wallet,
checking the token metadata,
and submitting a token transfer.
Takeaways
- ZKsync chains after the Atlas upgrade are fully EVM-equivalent, meaning you can write smart contracts in Solidity or Vyper as in Ethereum and test apps with standard EVM tooling.
- You can use ZKsync's latest testnet, the ZKsync OS Developer Preview, to test your apps as you develop them.
- As you continue building with ZKsync, make sure to join our GitHub Discussions Community to ask questions, get help and help other devs building on ZKsync, or share your project.