Skip to content

Commit

Permalink
Fix after review.
Browse files Browse the repository at this point in the history
  • Loading branch information
andreibancioiu committed Apr 4, 2024
1 parent 4b2bb71 commit a11f509
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions docs/sdk-and-tools/sdk-js/sdk-js-cookbook-v13.md
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,9 @@ Now, let's find and parse the event we are interested in:
```
import { TransactionEventsParser, findEventsByFirstTopic } from "@multiversx/sdk-core";
const abiJsonMultisig = await promises.readFile("../contracts/multisig-full.abi.json", { encoding: "utf8" });
const abiMultisig = AbiRegistry.create(JSON.parse(abiJsonMultisig));
const eventsParser = new TransactionEventsParser({
abi: abiMultisig
});
Expand Down Expand Up @@ -852,7 +855,20 @@ console.log(sum);

## Explicit decoding / encoding of values

When needed, you can use the [`BinaryCodec`](https://multiversx.github.io/mx-sdk-js-core/v13/classes/BinaryCodec.html) to [decode and encode values](/developers/data/serialization-overview/) manually.
When needed, you can use the [`BinaryCodec`](https://multiversx.github.io/mx-sdk-js-core/v13/classes/BinaryCodec.html) to [decode and encode values](/developers/data/serialization-overview/) manually,
leveraging contract ABIs:

```
const abiJsonExample = await promises.readFile("../contracts/example.abi.json", { encoding: "utf8" });
const abiExample = AbiRegistry.create(JSON.parse(abiJsonExample));
const abiJsonMultisig = await promises.readFile("../contracts/multisig-full.abi.json", { encoding: "utf8" });
const abiMultisig = AbiRegistry.create(JSON.parse(abiJsonMultisig));
```

:::note
The ABI files used within this cookbook are available [here](https://github.com/multiversx/mx-sdk-js-examples).
:::

### Decoding a custom type

Expand All @@ -861,7 +877,7 @@ Example of decoding a custom type (a structure) called `DepositEvent` from binar
```
import { BinaryCodec } from "@multiversx/sdk-core";
const depositCustomType = abi.getCustomType("DepositEvent");
const depositCustomType = abiExample.getCustomType("DepositEvent");
const codec = new BinaryCodec();
let data = Buffer.from("00000000000003db000000", "hex");
let decoded = codec.decodeTopLevel(data, depositCustomType);
Expand All @@ -873,7 +889,7 @@ console.log(JSON.stringify(decodedValue, null, 4));
Example of decoding a custom type (a structure) called `Reward` from binary data:

```
const rewardStructType = abi.getStruct("Reward");
const rewardStructType = abiExample.getStruct("Reward");
data = Buffer.from("010000000445474c440000000201f400000000000003e80000000000000000", "hex");
[decoded] = codec.decodeNested(data, rewardStructType);
Expand Down

0 comments on commit a11f509

Please sign in to comment.