Skip to content

Commit 1bdf23c

Browse files
update dapps template
1 parent b490749 commit 1bdf23c

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

.CONTRIBUTING/tutorials/templates/dapps-template.md

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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

2929
Set up the development environment:
3030

@@ -33,11 +33,12 @@ Set up the development environment:
3333
npx create-react-app my-polkadot-dapp --template typescript
3434
cd my-polkadot-dapp
3535

36-
# Install Polkadot dependencies
36+
# Install required dependencies
3737
npm install @polkadot/api@VERSION @polkadot/extension-dapp@VERSION @polkadot/util@VERSION
3838
```
3939

4040
### Project Structure
41+
4142
```
4243
my-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

5657
Create a connection to the Polkadot network:
5758

58-
```typescript
59-
// src/hooks/usePolkadotApi.ts
59+
```typescript title="usePolkadotApi.ts"
6060
import { ApiPromise, WsProvider } from '@polkadot/api';
6161
import { useEffect, useState } from 'react';
6262

@@ -80,12 +80,11 @@ export const usePolkadotApi = () => {
8080
};
8181
```
8282

83-
## Step 3: Wallet Integration
83+
## Wallet Integration
8484

8585
Implement wallet connection functionality:
8686

87-
```typescript
88-
// src/components/WalletConnect.tsx
87+
```typescript title="src/components/WalletConnect.tsx"
8988
import { web3Accounts, web3Enable, web3FromAddress } from '@polkadot/extension-dapp';
9089
import { InjectedAccountWithMeta } from '@polkadot/extension-inject/types';
9190
import { 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

129128
Create components for interacting with the blockchain:
130129

131-
```typescript
132-
// src/components/ChainInteraction.tsx
130+
```typescript title="src/components/ChainInteraction.tsx"
133131
import { ApiPromise } from '@polkadot/api';
134132
import { InjectedAccountWithMeta } from '@polkadot/extension-inject/types';
135133
import { 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

199197
Bring everything together:
200198

201-
```typescript
202-
// src/App.tsx
199+
```typescript title="src/App.tsx"
203200
import React, { useState } from 'react';
204201
import { usePolkadotApi } from './hooks/usePolkadotApi';
205202
import { WalletConnect } from './components/WalletConnect';
@@ -231,7 +228,7 @@ function App() {
231228
export default App;
232229
```
233230

234-
## Step 6: Testing Your dApp
231+
## Testing Your dApp
235232

236233
Test the application:
237234

@@ -243,6 +240,7 @@ npm start
243240
```
244241

245242
### Testing Checklist
243+
246244
1. **Wallet Connection**: Verify extension detection and account selection
247245
2. **API Connection**: Check network connection status
248246
3. **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

259257
Enhance your dApp with additional features:
260258

261259
### Real-time Updates
262-
```typescript
260+
261+
```typescript title="realtime-updates.ts"
263262
// Subscribe to balance changes
264263
const 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
272272
try {
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
286287
const networks = {
287288
polkadot: 'wss://rpc.polkadot.io',
@@ -295,7 +296,7 @@ const networks = {
295296

296297
Deploy your dApp:
297298

298-
```bash
299+
```bash
299300
# Build for production
300301
npm run build
301302

0 commit comments

Comments
 (0)