| Value |
Top-encoding bytes |
Nested encoding bytes |
DayOfWeek::Monday
|
/* nothing */
|
/* discriminant */ 0,
|
DayOfWeek::Tuesday
|
/* discriminant */ 1,
|
EnumWithEverything::Default
|
/* nothing */
|
/* discriminant */ 0,
|
EnumWithEverything::Today(
DayOfWeek::Monday
)
|
/* discriminant */ 1,
/* DayOfWeek discriminant */ 0
|
EnumWithEverything::Today(
DayOfWeek::Friday
)
|
/* discriminant */ 1,
/* DayOfWeek discriminant */ 4
|
EnumWithEverything::Write(
Vec::new(),
0,
)
|
/* discriminant */ 2,
/* vec length */ 0, 0, 0, 0,
/* u16 */ 0, 0,
|
EnumWithEverything::Write(
[1, 2, 3].to_vec(),
4
)
|
/* discriminant */ 2,
/* vec length */ 0, 0, 0, 3,
/* vec contents */ 1, 2, 3,
/* an extra 16 */ 0, 4,
|
EnumWithEverything::Struct (
int: 0x42,
seq: vec![0x1, 0x2, 0x3, 0x4, 0x5],
another_byte: 0x6,
uint_32: 0x12345,
uint_64: 0x123456789,
);
|
/* discriminant */ 3,
/* int */ 0, 0x42,
/* seq length */ 0, 0, 0, 5,
/* seq contents */ 1, 2, 3, 4, 5,
/* another_byte */ 6,
/* uint_32 */ 0x00, 0x01, 0x23, 0x45,
/* uint_64 */ 0x00, 0x00, 0x00, 0x01,
0x23, 0x45, 0x67, 0x89,
|
);
---
### Decode contract events
Decode the events a smart contract emits into named, typed fields, using an ABI
and `TransactionEventsParser`. A raw event is a bag of base64 topics and data
bytes; the parser uses the ABI's event definition to turn those bytes into a
usable object.
This recipe decodes a **real** `pongEvent` from the ping-pong contract, captured
verbatim from devnet transaction `922dbae7...`. The decoded `user` field must
equal the real sender of that transaction, which is how the recipe verifies
itself.
## Prerequisites
- Node.js >= 20.19.0.
- For the default (offline) decode: nothing, the raw event is baked in.
- For the `live` mode: devnet network access.
## Install
```bash
mkdir decode-contract-events
cd decode-contract-events
# Create the project files shown on this page.
npm install
npm run build
```