diff --git a/docs/sdk-and-tools/devcontainers.md b/docs/sdk-and-tools/devcontainers.md index 91c006bb4..24591c684 100644 --- a/docs/sdk-and-tools/devcontainers.md +++ b/docs/sdk-and-tools/devcontainers.md @@ -29,6 +29,8 @@ mxpy --version sc-meta --version ``` +[comment]: # (mx-context-auto) + ## Using the Docker images without VSCode If you'd like to use the development Docker image(s) without VSCode's devcontainers feature, this is entirely possible. For example, let's try the following (in any terminal): diff --git a/docs/sdk-and-tools/proxy.md b/docs/sdk-and-tools/proxy.md index 969cd8c33..4284a87e0 100644 --- a/docs/sdk-and-tools/proxy.md +++ b/docs/sdk-and-tools/proxy.md @@ -78,7 +78,7 @@ The Proxy holds its configuration within the `config` folder: [comment]: # (mx-context-auto) -## **Snaphotless observers support** +## **Snapshotless observers support** Instead of nodes that perform regular trie operations, such as snapshots and so on, one could use snapshotless nodes, which are, as the name suggests, nodes that have a different configuration which allows them to "bypass" certain costly trie operations, with the downside of losing access to anything but real-time. diff --git a/docs/sdk-and-tools/sdk-js/sdk-js-cookbook.md b/docs/sdk-and-tools/sdk-js/sdk-js-cookbook.md index 2078a28ad..5c2447ce5 100644 --- a/docs/sdk-and-tools/sdk-js/sdk-js-cookbook.md +++ b/docs/sdk-and-tools/sdk-js/sdk-js-cookbook.md @@ -11,7 +11,7 @@ This page will guide you through the process of handling common tasks using **sd This cookbook makes use of `sdk-js 12`. In order to migrate from `sdk-js 11.x` to `sdk-js 12`, please follow [the migration guide](/sdk-and-tools/sdk-js/sdk-js-migration-guides). ::: - + [comment]: # (mx-context-auto) @@ -223,7 +223,7 @@ For a different awaiting strategy, also see [extending sdk-js](https://docs.mult - + [comment]: # (mx-context-auto) @@ -305,7 +305,7 @@ const tx4 = factory.createMultiESDTNFTTransfer({ - + [comment]: # (mx-context-auto) @@ -415,8 +415,7 @@ console.log("Return code:", returnCode); - - + [comment]: # (mx-context-auto) ## ABI @@ -450,7 +449,7 @@ existingContract = new SmartContract({ address: existingContractAddress, abi: ab - + [comment]: # (mx-context-auto) @@ -566,7 +565,7 @@ let firstValueAsStruct = firstValue; - + [comment]: # (mx-context-auto) @@ -789,7 +788,76 @@ For customizing the default parser, also see [extending sdk-js](/sdk-and-tools/s - + + +[comment]: # (mx-context-auto) + +## Contract events + +[comment]: # (mx-context-auto) + +### Decode transaction events + +Example of decoding a transaction event having the identifier `deposit`: + +``` +const abiContent = await promises.readFile("../contracts/example.abi.json", { encoding: "utf8" }); +const abiObj = JSON.parse(abiContent); +const abiRegistry = AbiRegistry.create(abiObj); +const resultsParser = new ResultsParser(); + +const eventIdentifier = "deposit"; +const eventDefinition = abiRegistry.getEvent(eventIdentifier); +const transaction = await networkProvider.getTransaction("532087e5021c9ab8be8a4db5ad843cfe0610761f6334d9693b3765992fd05f67"); +const event = transaction.contractResults.items[0].logs.findFirstOrNoneEvent(eventIdentifier); +const outcome = resultsParser.parseEvent(event, eventDefinition); +console.log(JSON.stringify(outcome, null, 4)); +``` + + + + + +[comment]: # (mx-context-auto) + +## Explicit decoding / encoding of values + +[comment]: # (mx-context-auto) + +### Decoding a custom type + +Example of decoding a custom type (a structure) called `DepositEvent` from binary data: + +``` +import { AbiRegistry, BinaryCodec } from "@multiversx/sdk-core"; +import { promises } from "fs"; + +const abiJson = await promises.readFile("../contracts/example.abi.json", { encoding: "utf8" }); +const abiObj = JSON.parse(abiJson); +const abiRegistry = AbiRegistry.create(abiObj); +const depositCustomType = abiRegistry.getCustomType("DepositEvent"); +const codec = new BinaryCodec(); +let data = Buffer.from("00000000000003db000000", "hex"); +let decoded = codec.decodeTopLevel(data, depositCustomType); +let decodedValue = decoded.valueOf(); + +console.log(JSON.stringify(decodedValue, null, 4)); +``` + +Example of decoding a custom type (a structure) called `Reward` from binary data: + +``` +const rewardStructType = abiRegistry.getStruct("Reward"); +data = Buffer.from("010000000445474c440000000201f400000000000003e80000000000000000", "hex"); + +[decoded] = codec.decodeNested(data, rewardStructType); +decodedValue = decoded.valueOf(); +console.log(JSON.stringify(decodedValue, null, 4)); +``` + + + + [comment]: # (mx-context-auto) diff --git a/docs/sdk-and-tools/sdk-py/sdk-py-cookbook.md b/docs/sdk-and-tools/sdk-py/sdk-py-cookbook.md index 9360074ce..08f7a805b 100644 --- a/docs/sdk-and-tools/sdk-py/sdk-py-cookbook.md +++ b/docs/sdk-and-tools/sdk-py/sdk-py-cookbook.md @@ -3,7 +3,8 @@ id: sdk-py-cookbook title: Cookbook --- -[comment]: # "mx-abstract" +[comment]: # (mx-abstract) + [comment]: # (mx-context-auto) ## Overview