Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,27 @@ tags:
### Fetching the network config

```js
import { DevnetEntrypoint } from "@multiversx/sdk-core";

{
const entrypoint = new DevnetEntrypoint();
const networkProvider = entrypoint.createNetworkProvider();

const networkConfig = networkProvider.getNetworkConfig();
const networkConfig = await networkProvider.getNetworkConfig();
}
```

### Fetching the network status

```js
import { DevnetEntrypoint } from "@multiversx/sdk-core";

{
const entrypoint = new DevnetEntrypoint();
const networkProvider = entrypoint.createNetworkProvider();

const metaNetworkStatus = networkProvider.getNetworkStatus(); // fetches status from metachain
const networkStatus = networkProvider.getNetworkStatus(); // fetches status from shard one
const metaNetworkStatus = await networkProvider.getNetworkStatus(); // fetches status from metachain
const shardOneNetworkStatus = await networkProvider.getNetworkStatus(1); // fetches status from shard one
}
```

Expand All @@ -43,6 +47,8 @@ When using the **PROXY**, keep in mind that the shard must also be specified in

#### Fetching a block using the **API**
```js
import { ApiNetworkProvider } from "@multiversx/sdk-core";

{
const api = new ApiNetworkProvider("https://devnet-api.multiversx.com");
const blockHash = "1147e111ce8dd860ae43a0f0d403da193a940bfd30b7d7f600701dd5e02f347a";
Expand All @@ -53,6 +59,8 @@ When using the **PROXY**, keep in mind that the shard must also be specified in
Additionally, we can fetch the latest block from the network:

```js
import { ApiNetworkProvider } from "@multiversx/sdk-core";

{
const api = new ApiNetworkProvider("https://devnet-api.multiversx.com");
const latestBlock = await api.getLatestBlock();
Expand All @@ -63,27 +71,33 @@ Additionally, we can fetch the latest block from the network:

When using the proxy, we have to provide the shard, as well.
```js
import { ProxyNetworkProvider } from "@multiversx/sdk-core";

{
const proxy = new ProxyNetworkProvider("https://devnet-api.multiversx.com");
const proxy = new ProxyNetworkProvider("https://devnet-gateway.multiversx.com");
const blockHash = "1147e111ce8dd860ae43a0f0d403da193a940bfd30b7d7f600701dd5e02f347a";
const block = proxy.getBlock({ blockHash, shard: 1 });
const block = await proxy.getBlock({ blockHash, shard: 1 });
}
```

We can also fetch the latest block from the network.
By default, the shard will be the metachain, but we can specify a different shard if needed.

```js
import { ProxyNetworkProvider } from "@multiversx/sdk-core";

{
const proxy = new ProxyNetworkProvider("https://devnet-api.multiversx.com");
const latestBlock = proxy.getLatestBlock();
const proxy = new ProxyNetworkProvider("https://devnet-gateway.multiversx.com");
const latestBlock = await proxy.getLatestBlock();
}
```

### Fetching an Account
To fetch an account, we need its address. Once we have the address, we create an `Address` object and pass it as an argument to the method.

```js
import { Address, DevnetEntrypoint } from "@multiversx/sdk-core";

{
const entrypoint = new DevnetEntrypoint();
const api = entrypoint.createNetworkProvider();
Expand All @@ -96,6 +110,8 @@ To fetch an account, we need its address. Once we have the address, we create an
We can also fetch an account's storage, allowing us to retrieve all key-value pairs saved for that account.

```js
import { Address, DevnetEntrypoint } from "@multiversx/sdk-core";

{
const entrypoint = new DevnetEntrypoint();
const api = entrypoint.createNetworkProvider();
Expand All @@ -107,6 +123,8 @@ We can also fetch an account's storage, allowing us to retrieve all key-value pa
If we only want to fetch a specific key, we can do so as follows:

```js
import { Address, DevnetEntrypoint } from "@multiversx/sdk-core";

{
const entrypoint = new DevnetEntrypoint();
const api = entrypoint.createNetworkProvider();
Expand All @@ -124,11 +142,13 @@ To implement this, we need to define the condition to check each time the accoun
Keep in mind that this method has a default timeout, which can be adjusted using the `AwaitingOptions` class.

```js
import { Address, DevnetEntrypoint } from "@multiversx/sdk-core";

{
const entrypoint = new DevnetEntrypoint();
const api = entrypoint.createNetworkProvider();

const condition = (account: any) => {
const condition = (account) => {
return account.balance >= 7000000000000000000n; // 7 EGLD
};
const alice = Address.newFromBech32("erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th");
Expand All @@ -142,6 +162,8 @@ To execute transactions, we use the network providers to broadcast them to the n
#### Sending a Transaction

```js
import { Address, DevnetEntrypoint, Transaction } from "@multiversx/sdk-core";

{
const entrypoint = new DevnetEntrypoint();
const api = entrypoint.createNetworkProvider();
Expand All @@ -164,6 +186,8 @@ To execute transactions, we use the network providers to broadcast them to the n

#### Sending multiple transactions
```js
import { Address, DevnetEntrypoint, Transaction } from "@multiversx/sdk-core";

{
const entrypoint = new DevnetEntrypoint();
const api = entrypoint.createNetworkProvider();
Expand Down Expand Up @@ -210,6 +234,8 @@ To execute transactions, we use the network providers to broadcast them to the n
A transaction can be simulated before being sent for processing by the network. This is primarily used for smart contract calls, allowing you to preview the results produced by the smart contract.

```js
import { Address, DevnetEntrypoint, Transaction } from "@multiversx/sdk-core";

{
const entrypoint = new DevnetEntrypoint();
const api = entrypoint.createNetworkProvider();
Expand All @@ -233,6 +259,8 @@ A transaction can be simulated before being sent for processing by the network.
Before sending a transaction to the network for processing, you can retrieve the estimated gas limit required for the transaction to be executed.

```js
import { Address, DevnetEntrypoint, Transaction } from "@multiversx/sdk-core";

{
const entrypoint = new DevnetEntrypoint();
const api = entrypoint.createNetworkProvider();
Expand All @@ -259,6 +287,8 @@ Before sending a transaction to the network for processing, you can retrieve the
After sending a transaction, you may want to wait until it is processed before proceeding with another action. Keep in mind that this method has a default timeout, which can be adjusted using the `AwaitingOptions` class.

```js
import { DevnetEntrypoint } from "@multiversx/sdk-core";

{
const entrypoint = new DevnetEntrypoint();
const api = entrypoint.createNetworkProvider();
Expand All @@ -272,11 +302,13 @@ After sending a transaction, you may want to wait until it is processed before p
Similar to accounts, we can wait until a transaction meets a specific condition.

```js
import { DevnetEntrypoint } from "@multiversx/sdk-core";

{
const entrypoint = new DevnetEntrypoint();
const api = entrypoint.createNetworkProvider();

const condition = (txOnNetwork: any) => !txOnNetwork.status.isSuccessful();
const condition = (txOnNetwork) => txOnNetwork.status.isSuccessful();

const txHash = "exampletransactionhash";
const transactionOnNetwork = await api.awaitTransactionOnCondition(txHash, condition);
Expand All @@ -287,6 +319,8 @@ Similar to accounts, we can wait until a transaction meets a specific condition.
After sending a transaction, you may want to wait until it is processed before proceeding with another action. Keep in mind that this method has a default timeout, which can be adjusted using the `AwaitingOptions` class.

```js
import { DevnetEntrypoint } from "@multiversx/sdk-core";

{
const entrypoint = new DevnetEntrypoint();
const api = entrypoint.createNetworkProvider();
Expand All @@ -300,6 +334,8 @@ After sending a transaction, you may want to wait until it is processed before p
After sending a transaction, we can fetch it from the network using the transaction hash, which we receive after broadcasting the transaction.

```js
import { DevnetEntrypoint } from "@multiversx/sdk-core";

{
const entrypoint = new DevnetEntrypoint();
const api = entrypoint.createNetworkProvider();
Expand All @@ -313,6 +349,8 @@ After sending a transaction, we can fetch it from the network using the transact
We can fetch a specific token (ESDT, MetaESDT, SFT, NFT) from an account by providing the account's address and the token identifier.

```js
import { Address, DevnetEntrypoint, Token } from "@multiversx/sdk-core";

{
const entrypoint = new DevnetEntrypoint();
const api = entrypoint.createNetworkProvider();
Expand All @@ -330,6 +368,8 @@ We can fetch a specific token (ESDT, MetaESDT, SFT, NFT) from an account by prov
Fetches all fungible tokens held by an account. Note that this method does not handle pagination, but it can be achieved using `doGetGeneric`.

```js
import { Address, DevnetEntrypoint } from "@multiversx/sdk-core";

{
const entrypoint = new DevnetEntrypoint();
const api = entrypoint.createNetworkProvider();
Expand All @@ -343,6 +383,8 @@ Fetches all fungible tokens held by an account. Note that this method does not h
Fetches all non-fungible tokens held by an account. Note that this method does not handle pagination, but it can be achieved using `doGetGeneric`.

```js
import { Address, DevnetEntrypoint } from "@multiversx/sdk-core";

{
const entrypoint = new DevnetEntrypoint();
const api = entrypoint.createNetworkProvider();
Expand All @@ -356,6 +398,8 @@ Fetches all non-fungible tokens held by an account. Note that this method does n
If we want to fetch the metadata of a token (e.g., owner, decimals, etc.), we can use the following methods:

```js
import { DevnetEntrypoint } from "@multiversx/sdk-core";

{
const entrypoint = new DevnetEntrypoint();
const api = entrypoint.createNetworkProvider();
Expand All @@ -372,6 +416,8 @@ If we want to fetch the metadata of a token (e.g., owner, decimals, etc.), we ca
Smart contract queries, or view functions, are endpoints that only read data from the contract. To send a query to the observer nodes, we can proceed as follows:

```js
import { Address, DevnetEntrypoint, SmartContractQuery } from "@multiversx/sdk-core";

{
const entrypoint = new DevnetEntrypoint();
const api = entrypoint.createNetworkProvider();
Expand All @@ -390,14 +436,15 @@ The methods exposed by the `ApiNetworkProvider` or `ProxyNetworkProvider` are th
Let’s assume we want to retrieve all the transactions sent by Alice in which the `delegate` function was called.

```js
import { Address, DevnetEntrypoint } from "@multiversx/sdk-core";

{
const entrypoint = new DevnetEntrypoint();
const api = entrypoint.createNetworkProvider();

const alice = Address.newFromBech32("erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th");
const url = `transactions/${alice.toBech32()}?function=delegate`;
const url = `accounts/${alice.toBech32()}/transactions?function=delegate`;

const response = await api.doGetGeneric(url);
}
```

Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@ These operations can be performed using both the **controller** and the **factor

#### Deploying a Multisig Smart Contract using the controller
```js
import * as fs from 'fs';
import * as path from 'path';
import { Abi, Account, Address, DevnetEntrypoint } from '@multiversx/sdk-core';

{
const abi = await loadAbiRegistry("src/testdata/multisig-full.abi.json");
const bytecode = await loadContractCode("src/testdata/multisig-full.wasm");
const abiJson = fs.readFileSync('src/testdata/multisig-full.abi.json', { encoding: 'utf8' });
const abi = Abi.create(JSON.parse(abiJson));
const bytecode = new Uint8Array(fs.readFileSync('src/testdata/multisig-full.wasm'));

// create the entrypoint and the multisig controller
const entrypoint = new DevnetEntrypoint();
Expand All @@ -44,7 +49,7 @@ These operations can be performed using both the **controller** and the **factor
alice.address,
Address.newFromBech32("erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx"),
],
bytecode: bytecode.valueOf(),
bytecode,
gasLimit: 100000000n,
});

Expand All @@ -54,15 +59,20 @@ These operations can be performed using both the **controller** and the **factor
// wait for transaction completion, extract multisig contract's address
const outcome = await controller.awaitCompletedDeploy(txHash);

const contractAddress = outcome[0].contractAddress;
const contractAddress = outcome.contracts[0].address;
}
```

#### Deploying a Multisig Smart Contract using the factory
```js
import * as fs from 'fs';
import * as path from 'path';
import { Abi, Account, Address, DevnetEntrypoint } from '@multiversx/sdk-core';

{
const abi = await loadAbiRegistry("src/testdata/multisig-full.abi.json");
const bytecode = await loadContractCode("src/testdata/multisig-full.wasm");
const abiJson = fs.readFileSync('src/testdata/multisig-full.abi.json', { encoding: 'utf8' });
const abi = Abi.create(JSON.parse(abiJson));
const bytecode = new Uint8Array(fs.readFileSync('src/testdata/multisig-full.wasm'));

// create the entrypoint and the multisig factory
const entrypoint = new DevnetEntrypoint();
Expand All @@ -80,7 +90,7 @@ These operations can be performed using both the **controller** and the **factor
alice.address,
Address.newFromBech32("erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx"),
],
bytecode: bytecode.valueOf(),
bytecode,
gasLimit: 100000000n,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -592,5 +592,5 @@ transfer with no function call adds nothing after it. Pass `optGasLimit` /
is what happens to the action id this recipe creates.
- [Read a multisig's state](/sdk-and-tools/sdk-js/cookbook/multisig/read-multisig-state)
checks roles, quorum, and pending actions before proposing.
- [Deploy a smart contract](/sdk-and-tools/sdk-js/cookbook/smart-contracts-deploy/deploy-contract)
- [Deploy a smart contract](/sdk-and-tools/sdk-js/cookbook/multisig/deploy-multisig-contract)
is how the multisig itself, being a contract, gets deployed.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"write-translations": "docusaurus write-translations",
"write-heading-ids": "docusaurus write-heading-ids",
"generate:llms": "node scripts/generate-llms-txt.js",
"generate:md-urls": "node scripts/generate-md-urls.js",
"generate:md-urls": "npm run generate:cookbook && node scripts/generate-md-urls.js",
"generate:cookbook": "node scripts/generate-cookbook-manifest.js"
},
"dependencies": {
Expand Down
Loading