From 002a2cf044c6aba9e53a5c1faeedf34258d88283 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Tue, 2 Apr 2024 17:39:26 +0300 Subject: [PATCH 1/2] js-core v13: ABIs, queries etc. --- .../sdk-js/sdk-js-cookbook-v13.md | 191 +++++++++++++++--- 1 file changed, 160 insertions(+), 31 deletions(-) diff --git a/docs/sdk-and-tools/sdk-js/sdk-js-cookbook-v13.md b/docs/sdk-and-tools/sdk-js/sdk-js-cookbook-v13.md index 8646d47a2..87d7471b4 100644 --- a/docs/sdk-and-tools/sdk-js/sdk-js-cookbook-v13.md +++ b/docs/sdk-and-tools/sdk-js/sdk-js-cookbook-v13.md @@ -372,6 +372,48 @@ const response = await axios.get("https://github.com/multiversx/mx-sdk-js-core/r abi = AbiRegistry.create(response.data); ``` +### Manually construct the ABI + +If an ABI file isn't directly available, but you do have knowledge of the contract's endpoints and types, you can manually construct the ABI. Let's see a simple example: + +``` +abi = AbiRegistry.create({ + "endpoints": [{ + "name": "add", + "inputs": [], + "outputs": [] + }] +}); +``` + +An endpoint with both inputs and outputs: + +``` +abi = AbiRegistry.create({ + "endpoints": [ + { + "name": "foo", + "inputs": [ + { "type": "BigUint" }, + { "type": "u32" }, + { "type": "Address" } + ], + "outputs": [ + { "type": "u32" } + ] + }, + { + "name": "bar", + "inputs": [ + { "type": "counted-variadic" }, + { "type": "variadic" } + ], + "outputs": [] + } + ] +}); +``` + ## Contract deployments ### Load the bytecode from a file @@ -427,7 +469,7 @@ const deployTransaction = factory.createTransactionForDeploy({ sender: addressOfAlice, bytecode: code.valueOf(), gasLimit: 6000000n, - args: args + arguments: args }); ``` @@ -436,20 +478,14 @@ When creating transactions using `SmartContractTransactionsFactory`, even if the you can still use `TypedValue` objects as arguments for deployments and interactions. Even further, you can use a mix of `TypedValue` objects and plain JavaScript values and objects. For example: - ``` let args = [new U32Value(42), "hello", { foo: "bar" }, new TokenIdentifierValue("TEST-abcdef")]; ``` - ::: Then, as [previously seen](#working-with-accounts), set the transaction nonce (the account nonce must be synchronized beforehand). ``` -const deployer = new Account(addressOfAlice); -const deployerOnNetwork = await networkProvider.getAccount(addressOfAlice); -deployer.update(deployerOnNetwork); - deployTransaction.nonce = deployer.getNonceThenIncrement(); ``` @@ -471,7 +507,17 @@ const serializedTx = computer.computeBytesForSigning(deployTransaction); deployTransaction.signature = await signer.sign(serializedTx); ``` -Once you know the sender address and nonce for your deployment transaction, you can (deterministically) compute the (upcoming) address of the contract: +Then, broadcast the transaction and await its completion, as seen in the section [broadcasting transactions](#broadcasting-transactions): + +``` +const txHash = await apiNetworkProvider.sendTransaction(deployTransaction); +const transactionOnNetwork = await new TransactionWatcher(apiNetworkProvider).awaitCompleted(txHash); +``` + +### Computing the contract address + +Even before broadcasting, +at the moment you know the _sender_ address and the _nonce_ for your deployment transaction, you can (deterministically) compute the (upcoming) address of the contract: ``` import { AddressComputer } from "@multiversx/sdk-core"; @@ -485,12 +531,7 @@ const contractAddress = addressComputer.computeContractAddress( console.log("Contract address:", contractAddress.bech32()); ``` -Then, broadcast the transaction and await its completion, as seen in the section [broadcasting transactions](#broadcasting-transactions): - -``` -const txHash = await networkProvider.sendTransaction(deployTransaction); -const transactionOnNetwork = await new TransactionWatcher(networkProvider).awaitCompleted(txHash); -``` +### Parsing transaction outcome In the end, you can parse the results using a [`SmartContractTransactionsOutcomeParser`](https://multiversx.github.io/mx-sdk-js-core/v13/classes/SmartContractTransactionsOutcomeParser.html). However, since the `parseDeploy` method requires a [`TransactionOutcome`](https://multiversx.github.io/mx-sdk-js-core/v13/classes/TransactionOutcome.html) object as input, @@ -564,9 +605,9 @@ args = [42]; const transaction = factory.createTransactionForExecute({ sender: addressOfAlice, contract: Address.fromBech32("erd1qqqqqqqqqqqqqpgq6qr0w0zzyysklfneh32eqp2cf383zc89d8sstnkl60"), - functionName: "add", + function: "add", gasLimit: 5000000, - args: args + arguments: args }); ``` @@ -575,21 +616,15 @@ When creating transactions using `SmartContractTransactionsFactory`, even if the you can still use `TypedValue` objects as arguments for deployments and interactions. Even further, you can use a mix of `TypedValue` objects and plain JavaScript values and objects. For example: - ``` let args = [new U32Value(42), "hello", { foo: "bar" }, new TokenIdentifierValue("TEST-abcdef")]; ``` - ::: Then, as [previously seen](#working-with-accounts), set the transaction nonce (the account nonce must be synchronized beforehand). ``` -const caller = new Account(addressOfAlice); -const callerOnNetwork = await networkProvider.getAccount(addressOfAlice); -caller.update(callerOnNetwork); - -transaction.nonce = caller.getNonceThenIncrement(); +transaction.nonce = alice.getNonceThenIncrement(); ``` Now, **sign the transaction** using a wallet / signing provider of your choice. @@ -613,8 +648,8 @@ transaction.signature = await signer.sign(serializedTx); Then, broadcast the transaction and await its completion, as seen in the section [broadcasting transactions](#broadcasting-transactions): ``` -const txHash = await networkProvider.sendTransaction(transaction); -const transactionOnNetwork = await new TransactionWatcher(networkProvider).awaitCompleted(txHash); +const txHash = await apiNetworkProvider.sendTransaction(transaction); +const transactionOnNetwork = await new TransactionWatcher(apiNetworkProvider).awaitCompleted(txHash); ``` ### Transfer & execute @@ -627,9 +662,9 @@ For transfer & execute with native EGLD, prepare your transaction as follows: const transactionWithNativeTransfer = factory.createTransactionForExecute({ sender: addressOfAlice, contract: Address.fromBech32("erd1qqqqqqqqqqqqqpgq6qr0w0zzyysklfneh32eqp2cf383zc89d8sstnkl60"), - functionName: "add", + function: "add", gasLimit: 5000000, - args: args, + arguments: args, nativeTransferAmount: 1000000000000000000n }); ``` @@ -642,9 +677,9 @@ For transfer & execute with ESDT tokens, prepare your transaction as follows: const transactionWithTokenTransfer = factory.createTransactionForExecute({ sender: addressOfAlice, contract: Address.fromBech32("erd1qqqqqqqqqqqqqpgq6qr0w0zzyysklfneh32eqp2cf383zc89d8sstnkl60"), - functionName: "add", + function: "add", gasLimit: 5000000, - args: args, + arguments: args, tokenTransfers: [ new TokenTransfer({ token: new Token({ identifier: "UTK-14d57d" }), @@ -660,9 +695,9 @@ Or, for transferring multiple tokens (NFTs included): const transactionWithMultipleTokenTransfers = factory.createTransactionForExecute({ sender: addressOfAlice, contract: Address.fromBech32("erd1qqqqqqqqqqqqqpgq6qr0w0zzyysklfneh32eqp2cf383zc89d8sstnkl60"), - functionName: "add", + function: "add", gasLimit: 5000000, - args: args, + arguments: args, tokenTransfers: [ new TokenTransfer({ token: new Token({ identifier: "UTK-14d57d" }), @@ -678,6 +713,100 @@ const transactionWithMultipleTokenTransfers = factory.createTransactionForExecut Above, we've prepared the `TokenTransfer` objects as seen in the section [token transfers](#token-transfers). +### Parsing transaction outcome + +Once a transaction is completed, you can parse the results using a [`SmartContractTransactionsOutcomeParser`](https://multiversx.github.io/mx-sdk-js-core/v13/classes/SmartContractTransactionsOutcomeParser.html). +However, since the `parseExecute` method requires a [`TransactionOutcome`](https://multiversx.github.io/mx-sdk-js-core/v13/classes/TransactionOutcome.html) object as input, +we need to first convert our `TransactionOnNetwork` object to a `TransactionOutcome`, by means of a [`TransactionsConverter`](https://multiversx.github.io/mx-sdk-js-core/v13/classes/TransactionsConverter.html). + +:::important +Generally speaking, the components of `sdk-core` and `sdk-network-providers` have different concerns. +The former aims to be agnostic to network providers, while the latter is designed to cover specifics of [the available REST APIs](https://docs.multiversx.com/sdk-and-tools/rest-api). + +This being said, a certain impedance mismatch is expected between the two packages. This is resolved by means of specially crafted _converters_ and _adapters_. +Currently, for the JavaScript / TypeScript SDKs, the _converters_ and _adapters_ are residents of the `sdk-core` package. +However, this might change in the future - see the [sdk-specs](https://github.com/multiversx/mx-sdk-specs). +::: + +``` +import { SmartContractTransactionsOutcomeParser, TransactionsConverter } from "@multiversx/sdk-core"; + +const converter = new TransactionsConverter(); +const parser = new SmartContractTransactionsOutcomeParser({ + abi: abi +}); + +const transactionOutcome = converter.transactionOnNetworkToOutcome(transactionOnNetwork); +const parsedOutcome = parser.parseExecute({ transactionOutcome }); + +console.log(parsedOutcome); +``` + +## Contract queries + +In order to perform Smart Contract queries, we recommend the use of `SmartContractQueriesController`. +The legacy approaches that rely on `SmartContract.createQuery()` or `Interaction.buildQuery()` are still available, but they will be deprecated in the (distant) future. + +You will notice that the `SmartContractQueriesController` requires a `QueryRunner` object at initialization. +A `NetworkProvider`, slighly adapted, is used to satisfy this requirement. + +:::important +Generally speaking, the components of `sdk-core` and `sdk-network-providers` have different concerns. +The former aims to be agnostic to network providers, while the latter is designed to cover specifics of [the available REST APIs](https://docs.multiversx.com/sdk-and-tools/rest-api). + +This being said, a certain impedance mismatch is expected between the two packages. This is resolved by means of specially crafted _converters_ and _adapters_. +Currently, for the JavaScript / TypeScript SDKs, the _converters_ and _adapters_ are residents of the `sdk-core` package. +However, this might change in the future - see the [sdk-specs](https://github.com/multiversx/mx-sdk-specs). +::: + +``` +import { QueryRunnerAdapter, SmartContractQueriesController } from "@multiversx/sdk-core"; + +const queryRunner = new QueryRunnerAdapter({ + networkProvider: apiNetworkProvider +}); + +let controller = new SmartContractQueriesController({ + queryRunner: queryRunner +}); +``` + +If the contract ABI is available, provide it to the controller: + +``` +controller = new SmartContractQueriesController({ + queryRunner: queryRunner, + abi: abi +}); +``` + +Let's create a query object: + +``` +const query = controller.createQuery({ + contract: "erd1qqqqqqqqqqqqqpgq6qr0w0zzyysklfneh32eqp2cf383zc89d8sstnkl60", + function: "getSum", + arguments: [], +}); +``` + +Then, run the query against the network. You will get a `SmartContractQueryResponse` object. + +``` +const response = await controller.runQuery(query); +``` + +:::tip +The invocation of `controller.runQuery()` ultimately calls the VM query endpoints of the MultiversX REST API. +::: + +The response object contains the raw output of the query, which can be parsed as follows: + +``` +const [sum] = controller.parseQueryResponse(response); +console.log(sum); +``` + :::important This page is a work in progress. Please check back later for more content. ::: From 2711d97452d082759e1baa79b24067e02bba4cf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Wed, 3 Apr 2024 11:14:56 +0300 Subject: [PATCH 2/2] Add links to auto-generated docs. --- .../sdk-js/sdk-js-cookbook-v13.md | 62 +++++++++---------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/docs/sdk-and-tools/sdk-js/sdk-js-cookbook-v13.md b/docs/sdk-and-tools/sdk-js/sdk-js-cookbook-v13.md index 87d7471b4..5330acfa9 100644 --- a/docs/sdk-and-tools/sdk-js/sdk-js-cookbook-v13.md +++ b/docs/sdk-and-tools/sdk-js/sdk-js-cookbook-v13.md @@ -76,7 +76,7 @@ console.log("Nonce:", alice.nonce); ``` :::note -Since `sdk-core v13`, the `Transaction` class exhibits its state as public read-write properties. For example, you can access and set the `nonce` property, instead of using `getNonce` and `setNonce`. +Since `sdk-core v13`, the [`Transaction`](https://multiversx.github.io/mx-sdk-js-core/v13/classes/Transaction.html) class exhibits its state as public read-write properties. For example, you can access and set the `nonce` property, instead of using `getNonce` and `setNonce`. ::: If you are using `sdk-core v13` or later, use `tx.nonce = ` to apply the nonce to a transaction. @@ -93,7 +93,7 @@ For further reference, please see [nonce management](https://docs.multiversx.com ### Preparing a simple transaction :::note -Since `sdk-core v13`, the `Transaction` class exhibits its state as public read-write properties. For example, you can access and set the `nonce` property, instead of using `getNonce` and `setNonce`. +Since `sdk-core v13`, the [`Transaction`](https://multiversx.github.io/mx-sdk-js-core/v13/classes/Transaction.html) class exhibits its state as public read-write properties. For example, you can access and set the `nonce` property, instead of using `getNonce` and `setNonce`. ::: ``` @@ -157,7 +157,7 @@ const watcherUsingApi = new TransactionWatcher(apiNetworkProvider); const transactionOnNetworkUsingApi = await watcherUsingApi.awaitCompleted(txHash); ``` -If, instead, you use a `ProxyNetworkProvider` to instantiate the `TransactionWatcher`, you'll need to patch the `getTransaction` method, +If, instead, you use a `ProxyNetworkProvider` to instantiate the [`TransactionWatcher`](https://multiversx.github.io/mx-sdk-js-core/v13/classes/TransactionWatcher.html), you'll need to patch the `getTransaction` method, so that it instructs the network provider to fetch the so-called _processing status_, as well (required by the watcher to detect transaction completion). ``` @@ -184,19 +184,19 @@ For a different awaiting strategy, also see [extending sdk-js](https://docs.mult ## Token transfers -Generally speaking, in order to create transactions that transfer native tokens or ESDT tokens, one should use the `TransferTransactionsFactory` class. +Generally speaking, in order to create transactions that transfer native tokens or ESDT tokens, one should use the [`TransferTransactionsFactory`](https://multiversx.github.io/mx-sdk-js-core/v13/classes/TransferTransactionsFactory.html) class. :::note -In `sdk-core v13`, the `TransferTransactionsFactory` class was extended with new methods, +In `sdk-core v13`, the [`TransferTransactionsFactory`](https://multiversx.github.io/mx-sdk-js-core/v13/classes/TransferTransactionsFactory.html) class was extended with new methods, to be aligned with the [SDKs specs](https://github.com/multiversx/mx-sdk-specs/blob/main/core/transactions-factories/transfer_transactions_factory.md). The old, legacy methods are still available (see below), thus existing client code isn't affected. ::: :::note -In `sdk-core v13`, the `TokenTransfer` class has changed, in a non-breaking manner. +In `sdk-core v13`, the [`TokenTransfer`](https://multiversx.github.io/mx-sdk-js-core/v13/classes/TokenTransfer.html) class has changed, in a non-breaking manner. Though, from now on, it should only be used for prepairing ESDT token transfers, not native EGLD transfers. -A `TokenTransfer` object can still be instantiated using the legacy methods, e.g. `fungibleFromAmount`, `nonFungible` (which are still available), +A [`TokenTransfer`](https://multiversx.github.io/mx-sdk-js-core/v13/classes/TokenTransfer.html) object can still be instantiated using the legacy methods, e.g. `fungibleFromAmount`, `nonFungible` (which are still available), but we recommend using the new approach instead (which, among others, makes abstraction of the number of decimals a token has). ::: @@ -204,7 +204,7 @@ but we recommend using the new approach instead (which, among others, makes abst For formatting or parsing token amounts, see [formatting and parsing amounts](#formatting-and-parsing-amounts). ::: -First, let's create a `TransferTransactionsFactory`: +First, let's create a [`TransferTransactionsFactory`](https://multiversx.github.io/mx-sdk-js-core/v13/classes/TransferTransactionsFactory.html): ``` import { Token, TokenTransfer, TransactionsFactoryConfig, TransferTransactionsFactory } from "@multiversx/sdk-core"; @@ -429,12 +429,12 @@ const code = Code.fromBuffer(codeBuffer); In `sdk-core v13`, the recommended way to create transactions for deploying (and, for that matter, upgrading and interacting with) -smart contracts is through a `SmartContractTransactionsFactory`. +smart contracts is through a [`SmartContractTransactionsFactory`](https://multiversx.github.io/mx-sdk-js-core/v13/classes/SmartContractTransactionsFactory.html). -The older (legacy) approach, using the method `SmartContract.deploy()`, is still available, however. -At some point in the future, `SmartContract.deploy()` will be deprecated and removed. +The older (legacy) approach, using the method [`SmartContract.deploy()`](https://multiversx.github.io/mx-sdk-js-core/v13/classes/SmartContract.html#deploy), is still available, however. +At some point in the future, [`SmartContract.deploy()`](https://multiversx.github.io/mx-sdk-js-core/v13/classes/SmartContract.html#deploy) will be deprecated and removed. -Now, let's create a `SmartContractTransactionsFactory`: +Now, let's create a [`SmartContractTransactionsFactory`](https://multiversx.github.io/mx-sdk-js-core/v13/classes/SmartContractTransactionsFactory.html): ``` import { SmartContractTransactionsFactory, TransactionsFactoryConfig } from "@multiversx/sdk-core"; @@ -460,7 +460,7 @@ Now, prepare the deploy transaction: ``` import { U32Value } from "@multiversx/sdk-core"; -// For deploy arguments, use `TypedValue` objects if you haven't provided an ABI to the factory: +// For deploy arguments, use [`TypedValue`](https://multiversx.github.io/mx-sdk-js-core/v13/classes/TypedValue.html) objects if you haven't provided an ABI to the factory: let args = [new U32Value(42)]; // Or use simple, plain JavaScript values and objects if you have provided an ABI to the factory: args = [42]; @@ -474,10 +474,10 @@ const deployTransaction = factory.createTransactionForDeploy({ ``` :::tip -When creating transactions using `SmartContractTransactionsFactory`, even if the ABI is available and provided, -you can still use `TypedValue` objects as arguments for deployments and interactions. +When creating transactions using [`SmartContractTransactionsFactory`](https://multiversx.github.io/mx-sdk-js-core/v13/classes/SmartContractTransactionsFactory.html), even if the ABI is available and provided, +you can still use [`TypedValue`](https://multiversx.github.io/mx-sdk-js-core/v13/classes/TypedValue.html) objects as arguments for deployments and interactions. -Even further, you can use a mix of `TypedValue` objects and plain JavaScript values and objects. For example: +Even further, you can use a mix of [`TypedValue`](https://multiversx.github.io/mx-sdk-js-core/v13/classes/TypedValue.html) objects and plain JavaScript values and objects. For example: ``` let args = [new U32Value(42), "hello", { foo: "bar" }, new TokenIdentifierValue("TEST-abcdef")]; ``` @@ -535,10 +535,10 @@ console.log("Contract address:", contractAddress.bech32()); In the end, you can parse the results using a [`SmartContractTransactionsOutcomeParser`](https://multiversx.github.io/mx-sdk-js-core/v13/classes/SmartContractTransactionsOutcomeParser.html). However, since the `parseDeploy` method requires a [`TransactionOutcome`](https://multiversx.github.io/mx-sdk-js-core/v13/classes/TransactionOutcome.html) object as input, -we need to first convert our `TransactionOnNetwork` object to a `TransactionOutcome`, by means of a [`TransactionsConverter`](https://multiversx.github.io/mx-sdk-js-core/v13/classes/TransactionsConverter.html). +we need to first convert our `TransactionOnNetwork` object to a [`TransactionOutcome`](https://multiversx.github.io/mx-sdk-js-core/v13/classes/TransactionOutcome.html), by means of a [`TransactionsConverter`](https://multiversx.github.io/mx-sdk-js-core/v13/classes/TransactionsConverter.html). :::important -Generally speaking, the components of `sdk-core` and `sdk-network-providers` have different concerns. +Generally speaking, the components of `sdk-core` and `sdk-network-providers` have different concerns. The former aims to be agnostic to network providers, while the latter is designed to cover specifics of [the available REST APIs](https://docs.multiversx.com/sdk-and-tools/rest-api). This being said, a certain impedance mismatch is expected between the two packages. This is resolved by means of specially crafted _converters_ and _adapters_. @@ -562,13 +562,13 @@ console.log(parsedOutcome); In `sdk-core v13`, the recommended way to create transactions for calling (and, for that matter, deploying and upgrading) -smart contracts is through a `SmartContractTransactionsFactory`. +smart contracts is through a [`SmartContractTransactionsFactory`](https://multiversx.github.io/mx-sdk-js-core/v13/classes/SmartContractTransactionsFactory.html). The older (legacy) approaches, using `SmartContract.call()`, `SmartContract.methods.myFunction()`, `SmartContract.methodsExplicit.myFunction()` and `new Interaction(contract, "myFunction", args)` are still available. However, at some point in the (more distant) future, they will be deprecated and removed. -Now, let's create a `SmartContractTransactionsFactory`: +Now, let's create a [`SmartContractTransactionsFactory`](https://multiversx.github.io/mx-sdk-js-core/v13/classes/SmartContractTransactionsFactory.html): ``` import { SmartContractTransactionsFactory, TransactionsFactoryConfig } from "@multiversx/sdk-core"; @@ -597,7 +597,7 @@ previously deployed smart contract: ``` import { U32Value } from "@multiversx/sdk-core"; -// For arguments, use `TypedValue` objects if you haven't provided an ABI to the factory: +// For arguments, use [`TypedValue`](https://multiversx.github.io/mx-sdk-js-core/v13/classes/TypedValue.html) objects if you haven't provided an ABI to the factory: let args = [new U32Value(42)]; // Or use simple, plain JavaScript values and objects if you have provided an ABI to the factory: args = [42]; @@ -612,10 +612,10 @@ const transaction = factory.createTransactionForExecute({ ``` :::tip -When creating transactions using `SmartContractTransactionsFactory`, even if the ABI is available and provided, -you can still use `TypedValue` objects as arguments for deployments and interactions. +When creating transactions using [`SmartContractTransactionsFactory`](https://multiversx.github.io/mx-sdk-js-core/v13/classes/SmartContractTransactionsFactory.html), even if the ABI is available and provided, +you can still use [`TypedValue`](https://multiversx.github.io/mx-sdk-js-core/v13/classes/TypedValue.html) objects as arguments for deployments and interactions. -Even further, you can use a mix of `TypedValue` objects and plain JavaScript values and objects. For example: +Even further, you can use a mix of [`TypedValue`](https://multiversx.github.io/mx-sdk-js-core/v13/classes/TypedValue.html) objects and plain JavaScript values and objects. For example: ``` let args = [new U32Value(42), "hello", { foo: "bar" }, new TokenIdentifierValue("TEST-abcdef")]; ``` @@ -711,7 +711,7 @@ const transactionWithMultipleTokenTransfers = factory.createTransactionForExecut }); ``` -Above, we've prepared the `TokenTransfer` objects as seen in the section [token transfers](#token-transfers). +Above, we've prepared the [`TokenTransfer`](https://multiversx.github.io/mx-sdk-js-core/v13/classes/TokenTransfer.html) objects as seen in the section [token transfers](#token-transfers). ### Parsing transaction outcome @@ -744,10 +744,10 @@ console.log(parsedOutcome); ## Contract queries -In order to perform Smart Contract queries, we recommend the use of `SmartContractQueriesController`. -The legacy approaches that rely on `SmartContract.createQuery()` or `Interaction.buildQuery()` are still available, but they will be deprecated in the (distant) future. +In order to perform Smart Contract queries, we recommend the use of [`SmartContractQueriesController`](https://multiversx.github.io/mx-sdk-js-core/v13/classes/SmartContractQueriesController.html). +The legacy approaches that rely on [`SmartContract.createQuery()`](https://multiversx.github.io/mx-sdk-js-core/v13/classes/SmartContract.html#createQuery) or [`Interaction.buildQuery()`](https://multiversx.github.io/mx-sdk-js-core/v13/classes/Interaction.html#buildQuery) are still available, but they will be deprecated in the (distant) future. -You will notice that the `SmartContractQueriesController` requires a `QueryRunner` object at initialization. +You will notice that the [`SmartContractQueriesController`](https://multiversx.github.io/mx-sdk-js-core/v13/classes/SmartContractQueriesController.html) requires a `QueryRunner` object at initialization. A `NetworkProvider`, slighly adapted, is used to satisfy this requirement. :::important @@ -766,7 +766,7 @@ const queryRunner = new QueryRunnerAdapter({ networkProvider: apiNetworkProvider }); -let controller = new SmartContractQueriesController({ +let controller = new SmartContractQueriesController({ queryRunner: queryRunner }); ``` @@ -774,7 +774,7 @@ let controller = new SmartContractQueriesController({ If the contract ABI is available, provide it to the controller: ``` -controller = new SmartContractQueriesController({ +controller = new SmartContractQueriesController({ queryRunner: queryRunner, abi: abi }); @@ -790,7 +790,7 @@ const query = controller.createQuery({ }); ``` -Then, run the query against the network. You will get a `SmartContractQueryResponse` object. +Then, run the query against the network. You will get a [`SmartContractQueryResponse`](https://multiversx.github.io/mx-sdk-js-core/v13/classes/SmartContractQueryResponse.html) object. ``` const response = await controller.runQuery(query);