Skip to content

Commit 0298775

Browse files
committed
Refactor Chopsticks documentation to streamline code examples and improve readability. Replace lengthy code snippets with references to external files for configuration, connection, and RPC examples. Update output examples for consistency across sections.
1 parent 3ee67cb commit 0298775

File tree

11 files changed

+119
-109
lines changed

11 files changed

+119
-109
lines changed

.reference/tools/chopsticks.md

Lines changed: 10 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -126,23 +126,7 @@ The Chopsticks source repository includes a collection of [YAML](https://yaml.or
126126
An example of a configuration file for Polkadot is as follows:
127127

128128
```yaml title="polkadot.yml"
129-
endpoint:
130-
- wss://rpc.ibp.network/polkadot
131-
- wss://polkadot-rpc.dwellir.com
132-
mock-signature-host: true
133-
block: ${env.POLKADOT_BLOCK_NUMBER}
134-
db: ./db.sqlite
135-
runtime-log-level: 5
136-
137-
import-storage:
138-
System:
139-
Account:
140-
- - - 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY
141-
- providers: 1
142-
data:
143-
free: '10000000000000000000'
144-
ParasDisputes:
145-
$removePrefix: ['disputes'] # those can makes block building super slow
129+
--8<-- 'code/reference/tools/chopsticks/polkadot.yml'
146130
```
147131

148132
The configuration file allows you to modify the storage of the forked network by rewriting the pallet, state component and value that you want to change. For example, Polkadot's file rewrites Alice's `system.Account` storage so that the free balance is set to `10000000000000000000`.
@@ -180,10 +164,7 @@ npx @acala-network/chopsticks \
180164

181165
If the fork is successful, you will see output indicating the RPC is listening:
182166

183-
<div class="termynal" data-termynal>
184-
<span data-ty="input">npx @acala-network/chopsticks --endpoint wss://polkadot-rpc.dwellir.com --block 100</span>
185-
<span data-ty="output">[19:12:21.023] INFO: Polkadot RPC listening on port 8000</span>
186-
</div>
167+
---8<-- 'code/reference/tools/chopsticks/polkadot-output.html'
187168

188169
You can now access the running Chopsticks fork using the default address: `ws://localhost:8000`.
189170

@@ -213,18 +194,7 @@ You can interact with the forked chain using various libraries such as [Polkadot
213194
For programmatic interaction, you can use the [Polkadot.js](/reference/tools/polkadot-js-api/){target=\_blank} library:
214195

215196
```typescript title="connect-to-fork.ts"
216-
import { ApiPromise, WsProvider } from '@polkadot/api';
217-
218-
async function connectToFork() {
219-
const wsProvider = new WsProvider('ws://localhost:8000');
220-
const api = await ApiPromise.create({ provider: wsProvider });
221-
await api.isReady;
222-
223-
// Now you can use 'api' to interact with your fork
224-
console.log(`Connected to chain: ${await api.rpc.system.chain()}`);
225-
}
226-
227-
connectToFork();
197+
--8<-- 'code/reference/tools/chopsticks/connect-to-fork.ts'
228198
```
229199

230200
### Replay Blocks
@@ -266,14 +236,7 @@ npx @acala-network/chopsticks xcm \
266236

267237
After running it, you should see output indicating connections between the chains:
268238

269-
<div class="termynal" data-termynal>
270-
<span data-ty="input">npx @acala-network/chopsticks xcm --r polkadot --p moonbeam --p astar</span>
271-
<span data-ty="output">[13:46:12.631] INFO: Moonbeam RPC listening on port 8000</span>
272-
<span data-ty="output">[13:46:23.669] INFO: Astar RPC listening on port 8001</span>
273-
<span data-ty="output">[13:46:53.320] INFO: Polkadot RPC listening on port 8002</span>
274-
<span data-ty="output">[13:46:54.038] INFO (xcm): Connected relaychain 'Polkadot' with parachain 'Moonbeam'</span>
275-
<span data-ty="output">[13:46:55.028] INFO (xcm): Connected relaychain 'Polkadot' with parachain 'Astar'</span>
276-
</div>
239+
---8<-- 'code/reference/tools/chopsticks/xcm-output.html'
277240

278241
Now you can interact with your forked chains using the ports specified in the output and test XCM messages between them.
279242

@@ -299,16 +262,7 @@ Chopstick's internal WebSocket server has special endpoints that allow the manip
299262
**Example:**
300263

301264
```typescript title="dev-newblock-example.ts"
302-
import { ApiPromise, WsProvider } from '@polkadot/api';
303-
304-
async function main() {
305-
const wsProvider = new WsProvider('ws://localhost:8000');
306-
const api = await ApiPromise.create({ provider: wsProvider });
307-
await api.isReady;
308-
await api.rpc('dev_newBlock', { count: 1 });
309-
}
310-
311-
main();
265+
--8<-- 'code/reference/tools/chopsticks/dev-new-block-example.ts'
312266
```
313267

314268
=== "dev_setBlockBuildMode"
@@ -325,16 +279,7 @@ Chopstick's internal WebSocket server has special endpoints that allow the manip
325279
**Example:**
326280

327281
```typescript title="dev-setBlockBuildMode-example.ts"
328-
import { ApiPromise, WsProvider } from '@polkadot/api';
329-
330-
async function main() {
331-
const wsProvider = new WsProvider('ws://localhost:8000');
332-
const api = await ApiPromise.create({ provider: wsProvider });
333-
await api.isReady;
334-
await api.rpc('dev_setBlockBuildMode', 'Instant');
335-
}
336-
337-
main();
282+
--8<-- 'code/reference/tools/chopsticks/dev-setBlockBuildMode-example.ts'
338283
```
339284

340285
=== "dev_setHead"
@@ -348,16 +293,7 @@ Chopstick's internal WebSocket server has special endpoints that allow the manip
348293
**Example:**
349294

350295
```typescript title="dev-setHead-example.ts"
351-
import { ApiPromise, WsProvider } from '@polkadot/api';
352-
353-
async function main() {
354-
const wsProvider = new WsProvider('ws://localhost:8000');
355-
const api = await ApiPromise.create({ provider: wsProvider });
356-
await api.isReady;
357-
await api.rpc('dev_setHead', 500);
358-
}
359-
360-
main();
296+
--8<-- 'code/reference/tools/chopsticks/dev-setHead-example.ts'
361297
```
362298

363299
=== "dev_setRuntimeLogLevel"
@@ -371,16 +307,7 @@ Chopstick's internal WebSocket server has special endpoints that allow the manip
371307
**Example:**
372308

373309
```typescript title="dev-setRuntimeLogLevel-example.ts"
374-
import { ApiPromise, WsProvider } from '@polkadot/api';
375-
376-
async function main() {
377-
const wsProvider = new WsProvider('ws://localhost:8000');
378-
const api = await ApiPromise.create({ provider: wsProvider });
379-
await api.isReady;
380-
await api.rpc('dev_setRuntimeLogLevel', 1);
381-
}
382-
383-
main();
310+
--8<-- 'code/reference/tools/chopsticks/dev-setRuntimeLogLevel-example.ts'
384311
```
385312
=== "dev_setStorage"
386313

@@ -394,24 +321,7 @@ Chopstick's internal WebSocket server has special endpoints that allow the manip
394321
**Example:**
395322

396323
```typescript title="dev-setStorage-example.ts"
397-
import { ApiPromise, WsProvider } from '@polkadot/api';
398-
import { Keyring } from '@polkadot/keyring';
399-
400-
async function main() {
401-
const wsProvider = new WsProvider('ws://localhost:8000');
402-
const api = await ApiPromise.create({ provider: wsProvider });
403-
await api.isReady;
404-
const keyring = new Keyring({ type: 'ed25519' });
405-
const bob = keyring.addFromUri('//Bob');
406-
const storage = {
407-
System: {
408-
Account: [[[bob.address], { data: { free: 100000 }, nonce: 1 }]],
409-
},
410-
};
411-
await api.rpc('dev_setStorage', storage);
412-
}
413-
414-
main();
324+
--8<-- 'code/reference/tools/chopsticks/dev-setStorage-example.ts'
415325
```
416326

417327
=== "dev_timeTravel"
@@ -425,16 +335,7 @@ Chopstick's internal WebSocket server has special endpoints that allow the manip
425335
**Example:**
426336

427337
```typescript title="dev-timeTravel-example.ts"
428-
import { ApiPromise, WsProvider } from '@polkadot/api';
429-
430-
async function main() {
431-
const wsProvider = new WsProvider('ws://localhost:8000');
432-
const api = await ApiPromise.create({ provider: wsProvider });
433-
await api.isReady;
434-
await api.rpc('dev_timeTravel', '2030-08-15T00:00:00');
435-
}
436-
437-
main();
338+
--8<-- 'code/reference/tools/chopsticks/dev-timeTravel-example.ts'
438339
```
439340

440341
## Where to Go Next
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { ApiPromise, WsProvider } from '@polkadot/api';
2+
3+
async function connectToFork() {
4+
const wsProvider = new WsProvider('ws://localhost:8000');
5+
const api = await ApiPromise.create({ provider: wsProvider });
6+
await api.isReady;
7+
8+
// Now you can use 'api' to interact with your fork
9+
console.log(`Connected to chain: ${await api.rpc.system.chain()}`);
10+
}
11+
12+
connectToFork();
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { ApiPromise, WsProvider } from '@polkadot/api';
2+
3+
async function main() {
4+
const wsProvider = new WsProvider('ws://localhost:8000');
5+
const api = await ApiPromise.create({ provider: wsProvider });
6+
await api.isReady;
7+
await api.rpc('dev_newBlock', { count: 1 });
8+
}
9+
10+
main();
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { ApiPromise, WsProvider } from '@polkadot/api';
2+
3+
async function main() {
4+
const wsProvider = new WsProvider('ws://localhost:8000');
5+
const api = await ApiPromise.create({ provider: wsProvider });
6+
await api.isReady;
7+
await api.rpc('dev_setBlockBuildMode', 'Instant');
8+
}
9+
10+
main();
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { ApiPromise, WsProvider } from '@polkadot/api';
2+
3+
async function main() {
4+
const wsProvider = new WsProvider('ws://localhost:8000');
5+
const api = await ApiPromise.create({ provider: wsProvider });
6+
await api.isReady;
7+
await api.rpc('dev_setHead', 500);
8+
}
9+
10+
main();
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { ApiPromise, WsProvider } from '@polkadot/api';
2+
3+
async function main() {
4+
const wsProvider = new WsProvider('ws://localhost:8000');
5+
const api = await ApiPromise.create({ provider: wsProvider });
6+
await api.isReady;
7+
await api.rpc('dev_setRuntimeLogLevel', 1);
8+
}
9+
10+
main();
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { ApiPromise, WsProvider } from '@polkadot/api';
2+
import { Keyring } from '@polkadot/keyring';
3+
4+
async function main() {
5+
const wsProvider = new WsProvider('ws://localhost:8000');
6+
const api = await ApiPromise.create({ provider: wsProvider });
7+
await api.isReady;
8+
const keyring = new Keyring({ type: 'ed25519' });
9+
const bob = keyring.addFromUri('//Bob');
10+
const storage = {
11+
System: {
12+
Account: [[[bob.address], { data: { free: 100000 }, nonce: 1 }]],
13+
},
14+
};
15+
await api.rpc('dev_setStorage', storage);
16+
}
17+
18+
main();
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { ApiPromise, WsProvider } from '@polkadot/api';
2+
3+
async function main() {
4+
const wsProvider = new WsProvider('ws://localhost:8000');
5+
const api = await ApiPromise.create({ provider: wsProvider });
6+
await api.isReady;
7+
await api.rpc('dev_timeTravel', '2030-08-15T00:00:00');
8+
}
9+
10+
main();
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<div class="termynal" data-termynal>
2+
<span data-ty="input">npx @acala-network/chopsticks --endpoint wss://polkadot-rpc.dwellir.com --block 100</span>
3+
<span data-ty="output">[19:12:21.023] INFO: Polkadot RPC listening on port 8000</span>
4+
</div>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
endpoint:
2+
- wss://rpc.ibp.network/polkadot
3+
- wss://polkadot-rpc.dwellir.com
4+
mock-signature-host: true
5+
block: ${env.POLKADOT_BLOCK_NUMBER}
6+
db: ./db.sqlite
7+
runtime-log-level: 5
8+
9+
import-storage:
10+
System:
11+
Account:
12+
- - - 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY
13+
- providers: 1
14+
data:
15+
free: '10000000000000000000'
16+
ParasDisputes:
17+
$removePrefix: ['disputes'] # those can makes block building super slow

0 commit comments

Comments
 (0)