Skip to content

Commit 5365501

Browse files
authored
Cookbook for viewing block extrinsics (#2476)
1 parent a1f8bed commit 5365501

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

docs/cookbook/blocks.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,20 @@ const header = await api.derive.chain.getHeader();
4242

4343
console.log(`#${header.number}: ${header.author}`);
4444
```
45+
46+
## How do I view block extrinsic information?
47+
48+
The transactions are included in a signed block as part of the extrinsics - some of these will be unsigned and generated by the block author and some of these may be submitted from external sources and be signed. (Some palettes do use unsigned transactions, so signed/unsigned is not an indication of origin). To retrieve the block and display the transaction information, we can do the following -
49+
50+
```js
51+
// no blockHash is specified, so we retrieve the latest
52+
const signedBlock = await this.api.rpc.chain.getBlock();
53+
54+
// the information for each of the contained extrinsics
55+
signedBlock.block.extrinsics.forEach((ex, index) => {
56+
// the extrinsics are decoded by the API
57+
console.log(index, ex.toHuman());
58+
});
59+
```
60+
61+
In the above `.toHuman()` is used to format into a human-readable representation. You can inspect/extract specific fields from the decoded extrinsic as required, for instance `ex.method.section` would return the pallete that executed this transaction.

0 commit comments

Comments
 (0)