Skip to content

Commit

Permalink
Merge pull request #746 from multiversx/development
Browse files Browse the repository at this point in the history
Development into main
  • Loading branch information
andreibancioiu authored Nov 15, 2023
2 parents 506bb9e + 53a7f03 commit 06a2330
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 10 deletions.
2 changes: 2 additions & 0 deletions docs/sdk-and-tools/devcontainers.md
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion docs/sdk-and-tools/proxy.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
84 changes: 76 additions & 8 deletions docs/sdk-and-tools/sdk-js/sdk-js-cookbook.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
:::

<!-- BEGIN_INCLUDE_FILE { "url": "https://raw.githubusercontent.com/multiversx/mx-sdk-js-examples/v0.5.1/cookbook/generated/basic.md" } -->
<!-- BEGIN_INCLUDE_FILE { "url": "https://raw.githubusercontent.com/multiversx/mx-sdk-js-examples/v0.6.0/cookbook/generated/basic.md" } -->

[comment]: # (mx-context-auto)

Expand Down Expand Up @@ -223,7 +223,7 @@ For a different awaiting strategy, also see [extending sdk-js](https://docs.mult

<!-- END_INCLUDE_FILE -->

<!-- BEGIN_INCLUDE_FILE { "url": "https://raw.githubusercontent.com/multiversx/mx-sdk-js-examples/v0.5.1/cookbook/generated/transfers.md" } -->
<!-- BEGIN_INCLUDE_FILE { "url": "https://raw.githubusercontent.com/multiversx/mx-sdk-js-examples/v0.6.0/cookbook/generated/transfers.md" } -->

[comment]: # (mx-context-auto)

Expand Down Expand Up @@ -305,7 +305,7 @@ const tx4 = factory.createMultiESDTNFTTransfer({

<!-- END_INCLUDE_FILE -->

<!-- BEGIN_INCLUDE_FILE { "url": "https://raw.githubusercontent.com/multiversx/mx-sdk-js-examples/v0.5.1/cookbook/generated/contracts_01_deployments.md" } -->
<!-- BEGIN_INCLUDE_FILE { "url": "https://raw.githubusercontent.com/multiversx/mx-sdk-js-examples/v0.6.0/cookbook/generated/contracts_01_deployments.md" } -->

[comment]: # (mx-context-auto)

Expand Down Expand Up @@ -415,8 +415,7 @@ console.log("Return code:", returnCode);

<!-- END_INCLUDE_FILE -->

<!-- BEGIN_INCLUDE_FILE { "url": "https://raw.githubusercontent.com/multiversx/mx-sdk-js-examples/v0.5.1/cookbook/generated/contracts_02_abi.md" } -->

<!-- BEGIN_INCLUDE_FILE { "url": "https://raw.githubusercontent.com/multiversx/mx-sdk-js-examples/v0.6.0/cookbook/generated/contracts_02_abi.md" } -->
[comment]: # (mx-context-auto)

## ABI
Expand Down Expand Up @@ -450,7 +449,7 @@ existingContract = new SmartContract({ address: existingContractAddress, abi: ab

<!-- END_INCLUDE_FILE -->

<!-- BEGIN_INCLUDE_FILE { "url": "https://raw.githubusercontent.com/multiversx/mx-sdk-js-examples/v0.5.1/cookbook/generated/contracts_03_queries.md" } -->
<!-- BEGIN_INCLUDE_FILE { "url": "https://raw.githubusercontent.com/multiversx/mx-sdk-js-examples/v0.6.0/cookbook/generated/contracts_03_queries.md" } -->

[comment]: # (mx-context-auto)

Expand Down Expand Up @@ -566,7 +565,7 @@ let firstValueAsStruct = <Struct>firstValue;

<!-- END_INCLUDE_FILE -->

<!-- BEGIN_INCLUDE_FILE { "url": "https://raw.githubusercontent.com/multiversx/mx-sdk-js-examples/v0.5.1/cookbook/generated/contracts_04_interactions.md" } -->
<!-- BEGIN_INCLUDE_FILE { "url": "https://raw.githubusercontent.com/multiversx/mx-sdk-js-examples/v0.6.0/cookbook/generated/contracts_04_interactions.md" } -->

[comment]: # (mx-context-auto)

Expand Down Expand Up @@ -789,7 +788,76 @@ For customizing the default parser, also see [extending sdk-js](/sdk-and-tools/s

<!-- END_INCLUDE_FILE -->

<!-- BEGIN_INCLUDE_FILE { "url": "https://raw.githubusercontent.com/multiversx/mx-sdk-js-examples/v0.5.1/cookbook/generated/signing.md" } -->
<!-- BEGIN_INCLUDE_FILE { "url": "https://raw.githubusercontent.com/multiversx/mx-sdk-js-examples/v0.6.0/cookbook/generated/contracts_05_events.md" } -->

[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));
```

<!-- END_INCLUDE_FILE -->

<!-- BEGIN_INCLUDE_FILE { "url": "https://raw.githubusercontent.com/multiversx/mx-sdk-js-examples/v0.6.0/cookbook/generated/codec.md" } -->

[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));
```

<!-- END_INCLUDE_FILE -->

<!-- BEGIN_INCLUDE_FILE { "url": "https://raw.githubusercontent.com/multiversx/mx-sdk-js-examples/v0.6.0/cookbook/generated/signing.md" } -->

[comment]: # (mx-context-auto)

Expand Down
3 changes: 2 additions & 1 deletion docs/sdk-and-tools/sdk-py/sdk-py-cookbook.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ id: sdk-py-cookbook
title: Cookbook
---

[comment]: # "mx-abstract"
[comment]: # (mx-abstract)

[comment]: # (mx-context-auto)

## Overview
Expand Down

0 comments on commit 06a2330

Please sign in to comment.