@@ -24,7 +24,7 @@ Before starting, ensure you have:
2424- Test tokens on [ relevant network]
2525- Code editor of your choice
2626
27- ## Step 1: Project Setup
27+ ## Project Setup
2828
2929Set up the development environment:
3030
@@ -33,11 +33,12 @@ Set up the development environment:
3333npx create-react-app my-polkadot-dapp --template typescript
3434cd my-polkadot-dapp
3535
36- # Install Polkadot dependencies
36+ # Install required dependencies
3737npm install @polkadot/api@VERSION @polkadot/extension-dapp@VERSION @polkadot/util@VERSION
3838```
3939
4040### Project Structure
41+
4142```
4243my-polkadot-dapp/
4344├── src/
@@ -51,12 +52,11 @@ my-polkadot-dapp/
5152└── README.md
5253```
5354
54- ## Step 2: API Connection Setup
55+ ## API Connection Setup
5556
5657Create a connection to the Polkadot network:
5758
58- ``` typescript
59- // src/hooks/usePolkadotApi.ts
59+ ``` typescript title="usePolkadotApi.ts"
6060import { ApiPromise , WsProvider } from ' @polkadot/api' ;
6161import { useEffect , useState } from ' react' ;
6262
@@ -80,12 +80,11 @@ export const usePolkadotApi = () => {
8080};
8181```
8282
83- ## Step 3: Wallet Integration
83+ ## Wallet Integration
8484
8585Implement wallet connection functionality:
8686
87- ``` typescript
88- // src/components/WalletConnect.tsx
87+ ``` typescript title="src/components/WalletConnect.tsx"
8988import { web3Accounts , web3Enable , web3FromAddress } from ' @polkadot/extension-dapp' ;
9089import { InjectedAccountWithMeta } from ' @polkadot/extension-inject/types' ;
9190import { useState , useEffect } from ' react' ;
@@ -124,12 +123,11 @@ export const WalletConnect = () => {
124123};
125124```
126125
127- ## Step 4: Chain Interaction Component
126+ ## Chain Interaction Component
128127
129128Create components for interacting with the blockchain:
130129
131- ``` typescript
132- // src/components/ChainInteraction.tsx
130+ ``` typescript title="src/components/ChainInteraction.tsx"
133131import { ApiPromise } from ' @polkadot/api' ;
134132import { InjectedAccountWithMeta } from ' @polkadot/extension-inject/types' ;
135133import { web3FromAddress } from ' @polkadot/extension-dapp' ;
@@ -194,12 +192,11 @@ export const ChainInteraction = ({ api, account }: Props) => {
194192};
195193```
196194
197- ## Step 5: Main App Component
195+ ## Main App Component
198196
199197Bring everything together:
200198
201- ``` typescript
202- // src/App.tsx
199+ ``` typescript title="src/App.tsx"
203200import React , { useState } from ' react' ;
204201import { usePolkadotApi } from ' ./hooks/usePolkadotApi' ;
205202import { WalletConnect } from ' ./components/WalletConnect' ;
@@ -231,7 +228,7 @@ function App() {
231228export default App ;
232229```
233230
234- ## Step 6: Testing Your dApp
231+ ## Testing Your dApp
235232
236233Test the application:
237234
@@ -243,6 +240,7 @@ npm start
243240```
244241
245242### Testing Checklist
243+
2462441 . ** Wallet Connection** : Verify extension detection and account selection
2472452 . ** API Connection** : Check network connection status
2482463 . ** Balance Queries** : Test balance retrieval functionality
@@ -254,20 +252,22 @@ npm start
254252!!!tip "Screenshot Dimensions"
255253 Use 1512px width for desktop screenshots, 400x600px for browser extensions.
256254
257- ## Step 7: Advanced Features [ Optional]
255+ ## Advanced Features [ Optional]
258256
259257Enhance your dApp with additional features:
260258
261259### Real-time Updates
262- ``` typescript
260+
261+ ``` typescript title="realtime-updates.ts"
263262// Subscribe to balance changes
264263const unsubscribe = await api .query .system .account (address , (account ) => {
265264 setBalance (account .data .free .toHuman ());
266265});
267266```
268267
269268### Error Handling
270- ``` typescript
269+
270+ ``` typescript title="error-handling.ts"
271271// Robust error handling
272272try {
273273 // API calls
@@ -281,7 +281,8 @@ try {
281281```
282282
283283### Multiple Network Support
284- ``` typescript
284+
285+ ``` typescript title="network-config.ts"
285286// Support for multiple networks
286287const networks = {
287288 polkadot: ' wss://rpc.polkadot.io' ,
@@ -295,7 +296,7 @@ const networks = {
295296
296297Deploy your dApp:
297298
298- ``` bash
299+ ``` bash
299300# Build for production
300301npm run build
301302
0 commit comments