Skip to content

Commit a048653

Browse files
authored
Merge pull request #649 from multiversx/feat/next
Merge v15 features
2 parents 4947557 + e4eb233 commit a048653

File tree

73 files changed

+2075
-4015
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+2075
-4015
lines changed

cookbook/accountManagement.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ import { Account, Address, DevnetEntrypoint } from "../src"; // md-ignore
160160
const filePath = path.join("../src", "testdata", "testwallets", "alice.pem");
161161
const alice = await Account.newFromPem(filePath);
162162

163-
const transaction = await factory.createTransactionForUnguardingAccount(alice.address);
163+
const transaction = await factory.createTransactionForUnguardingAccount(alice.address, {});
164164

165165
// fetch the nonce of the network // md-as-comment
166166
alice.nonce = await entrypoint.recallAccountNonce(alice.address);

cookbook/cookbook.md

Lines changed: 100 additions & 34 deletions
Large diffs are not rendered by default.

cookbook/entrypoints.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ import { DevnetEntrypoint } from "../src"; // md-ignore
2020
// If you'd like to connect to a third-party API, you can specify the url parameter:
2121

2222
// ```js
23-
const apiEntrypoint = new DevnetEntrypoint("https://custom-multiversx-devnet-api.com");
23+
const apiEntrypoint = new DevnetEntrypoint({ url: "https://custom-multiversx-devnet-api.com" });
2424
// ```
2525

2626
// #### Using a Proxy
2727

2828
// By default, the DevnetEntrypoint uses the standard API. However, you can create a custom entrypoint that interacts with a proxy by specifying the kind parameter:
2929

3030
// ```js
31-
const customEntrypoint = new DevnetEntrypoint("https://devnet-gateway.multiversx.com", "proxy");
31+
const customEntrypoint = new DevnetEntrypoint({ url: "https://devnet-gateway.multiversx.com", kind: "proxy" });
3232
// ```
3333
})().catch((e) => {
3434
console.log({ e });

cookbook/generate.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import re
22
from pathlib import Path
3-
from typing import Dict, List
3+
from typing import List
44

55
current_dir = Path(__file__).parent.absolute()
66

@@ -32,7 +32,7 @@
3232

3333
# we don't want this ceremonial piece of code to show up in the rendered cookbook
3434
TO_REMOVE = [
35-
"""(async () => {""",
35+
"""(async () => {""",
3636
"""})().catch((e) => {
3737
console.log({ e });
3838
});"""]
@@ -59,12 +59,12 @@ def main():
5959
def render_file(input_file: Path) -> List[str]:
6060
input_text = input_file.read_text()
6161

62-
for item in TO_REMOVE:
62+
for item in TO_REMOVE:
6363
input_text = input_text.replace(item, "")
6464

6565
input_lines = input_text.splitlines()
6666
start = input_lines.index(DIRECTIVE_START)
67-
67+
6868
input_lines = input_lines[start:]
6969
output_lines: List[str] = []
7070

@@ -86,9 +86,9 @@ def render_file(input_file: Path) -> List[str]:
8686

8787
if is_comment and not should_keep_as_comment:
8888
line = line.strip().strip("/").strip()
89-
else:
89+
else:
9090
if line.startswith(TO_UNINDENT_SPACE):
91-
line = line[len(TO_UNINDENT_SPACE):]
91+
line = line[len(TO_UNINDENT_SPACE):]
9292

9393

9494

cookbook/governance.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ import { Account, DevnetEntrypoint, GovernanceTransactionsOutcomeParser, Vote }
5656

5757
const commitHash = "1db734c0315f9ec422b88f679ccfe3e0197b9d67";
5858

59-
const transaction = factory.createTransactionForNewProposal(alice.address, {
59+
const transaction = await factory.createTransactionForNewProposal(alice.address, {
6060
commitHash: commitHash,
6161
startVoteEpoch: 10,
6262
endVoteEpoch: 15,
@@ -127,7 +127,7 @@ import { Account, DevnetEntrypoint, GovernanceTransactionsOutcomeParser, Vote }
127127
const filePath = path.join("../src", "testdata", "testwallets", "alice.pem");
128128
const alice = await Account.newFromPem(filePath);
129129

130-
const transaction = factory.createTransactionForVoting(alice.address, {
130+
const transaction = await factory.createTransactionForVoting(alice.address, {
131131
proposalNonce: 1,
132132
vote: Vote.YES,
133133
});

cookbook/multisig.ts

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1+
import * as fs from "fs"; // md-ignore
12
import path from "path"; // md-ignore
2-
import { Account, Address, DevnetEntrypoint, TransactionWatcher } from "../src"; // md-ignore
3-
import { MultisigTransactionsOutcomeParser } from "../src/multisig/multisigTransactionsOutcomeParser";
4-
import { loadAbiRegistry, loadContractCode } from "../src/testutils";
3+
import { Abi, Account, Address, DevnetEntrypoint, MultisigTransactionsOutcomeParser, TransactionWatcher } from "../src"; // md-ignore
54
// md-start
65
(async () => {
76
// ### Multisig
@@ -17,8 +16,11 @@ import { loadAbiRegistry, loadContractCode } from "../src/testutils";
1716
// #### Deploying a Multisig Smart Contract using the controller
1817
// ```js
1918
{
20-
const abi = await loadAbiRegistry("src/testdata/multisig-full.abi.json");
21-
const bytecode = await loadContractCode("src/testdata/multisig-full.wasm");
19+
const jsonContent: string = await fs.promises.readFile("src/testdata/multisig-full.abi.json", {
20+
encoding: "utf8",
21+
});
22+
const abi = Abi.create(JSON.parse(jsonContent));
23+
const bytecode = await fs.promises.readFile("src/testdata/multisig-full.wasm");
2224

2325
// create the entrypoint and the multisig controller // md-as-comment
2426
const entrypoint = new DevnetEntrypoint();
@@ -53,8 +55,11 @@ import { loadAbiRegistry, loadContractCode } from "../src/testutils";
5355
// #### Deploying a Multisig Smart Contract using the factory
5456
// ```js
5557
{
56-
const abi = await loadAbiRegistry("src/testdata/multisig-full.abi.json");
57-
const bytecode = await loadContractCode("src/testdata/multisig-full.wasm");
58+
const jsonContent: string = await fs.promises.readFile("src/testdata/multisig-full.abi.json", {
59+
encoding: "utf8",
60+
});
61+
const abi = Abi.create(JSON.parse(jsonContent));
62+
const bytecode = await fs.promises.readFile("src/testdata/multisig-full.wasm");
5863

5964
// create the entrypoint and the multisig factory // md-as-comment
6065
const entrypoint = new DevnetEntrypoint();
@@ -89,9 +94,12 @@ import { loadAbiRegistry, loadContractCode } from "../src/testutils";
8994

9095
// ```js
9196
{
97+
const jsonContent: string = await fs.promises.readFile("src/testdata/multisig-full.abi.json", {
98+
encoding: "utf8",
99+
});
100+
const abi = Abi.create(JSON.parse(jsonContent));
92101
// create the entrypoint and the multisig controller // md-as-comment
93102
const entrypoint = new DevnetEntrypoint();
94-
const abi = await loadAbiRegistry("src/testdata/multisig-full.abi.json");
95103
const controller = entrypoint.createMultisigController(abi);
96104

97105
const filePath = path.join("../src", "testdata", "testwallets", "alice.pem");
@@ -126,7 +134,10 @@ import { loadAbiRegistry, loadContractCode } from "../src/testutils";
126134

127135
// ```js
128136
{
129-
const abi = await loadAbiRegistry("src/testdata/multisig-full.abi.json");
137+
const jsonContent: string = await fs.promises.readFile("src/testdata/multisig-full.abi.json", {
138+
encoding: "utf8",
139+
});
140+
const abi = Abi.create(JSON.parse(jsonContent));
130141

131142
// create the entrypoint and the multisig factory // md-as-comment
132143
const entrypoint = new DevnetEntrypoint();
@@ -172,7 +183,10 @@ import { loadAbiRegistry, loadContractCode } from "../src/testutils";
172183

173184
// ```js
174185
{
175-
const abi = await loadAbiRegistry("src/testdata/multisig-full.abi.json");
186+
const jsonContent: string = await fs.promises.readFile("src/testdata/multisig-full.abi.json", {
187+
encoding: "utf8",
188+
});
189+
const abi = Abi.create(JSON.parse(jsonContent));
176190

177191
// create the entrypoint and the multisig controller // md-as-comment
178192
const entrypoint = new DevnetEntrypoint();

cookbook/smartContracts.ts

Lines changed: 52 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import axios from "axios"; // md-ignore
2-
import { promises } from "fs"; // md-ignore
2+
import * as fs from "fs"; // md-ignore
33
import path from "path"; // md-ignore
44
import {
55
Abi,
@@ -20,7 +20,6 @@ import {
2020
U32Value,
2121
U64Value,
2222
} from "../src"; // md-ignore
23-
import { loadAbiRegistry } from "../src/testutils";
2423
// md-start
2524
(async () => {
2625
// ### Smart Contracts
@@ -33,9 +32,8 @@ import { loadAbiRegistry } from "../src/testutils";
3332
// #### Loading the ABI from a file
3433
// ```js
3534
{
36-
let abiJson = await promises.readFile("../src/testData/adder.abi.json", { encoding: "utf8" });
37-
let abiObj = JSON.parse(abiJson);
38-
let abi = Abi.create(abiObj);
35+
let abiJson = await fs.promises.readFile("../src/testdata/adder.abi.json", { encoding: "utf8" });
36+
const abi = Abi.create(JSON.parse(abiJson));
3937
}
4038
// ```
4139

@@ -104,9 +102,12 @@ import { loadAbiRegistry } from "../src/testutils";
104102
sender.nonce = await entrypoint.recallAccountNonce(sender.address);
105103

106104
// load the contract bytecode
107-
const bytecode = await promises.readFile("../src/testData/adder.wasm");
105+
const bytecode = await fs.promises.readFile("../src/testdata/adder.wasm");
108106
// load the abi file
109-
const abi = await loadAbiRegistry("../src/testdata/adder.abi.json");
107+
const jsonContent: string = await fs.promises.readFile("../src/testdata/adder.abi.json", {
108+
encoding: "utf8",
109+
});
110+
const abi = Abi.create(JSON.parse(jsonContent));
110111

111112
const controller = entrypoint.createSmartContractController(abi);
112113

@@ -142,8 +143,10 @@ import { loadAbiRegistry } from "../src/testutils";
142143
// ```js
143144
{
144145
// We use the transaction hash we got when broadcasting the transaction
145-
146-
const abi = await loadAbiRegistry("../src/testdata/adder.abi.json");
146+
const jsonContent: string = await fs.promises.readFile("../src/testdata/adder.abi.json", {
147+
encoding: "utf8",
148+
});
149+
const abi = Abi.create(JSON.parse(jsonContent));
147150
const entrypoint = new DevnetEntrypoint();
148151
const controller = entrypoint.createSmartContractController(abi);
149152
const outcome = await controller.awaitCompletedDeploy("txHash"); // waits for transaction completion and parses the result
@@ -176,7 +179,7 @@ import { loadAbiRegistry } from "../src/testutils";
176179
{
177180
const entrypoint = new DevnetEntrypoint();
178181
const factory = entrypoint.createSmartContractTransactionsFactory();
179-
const bytecode = await promises.readFile("../contracts/adder.wasm");
182+
const bytecode = await fs.promises.readFile("../contracts/adder.wasm");
180183

181184
// For deploy arguments, use "TypedValue" objects if you haven't provided an ABI to the factory: // md-as-comment
182185
let args: any[] = [new BigUIntValue(42)];
@@ -185,7 +188,7 @@ import { loadAbiRegistry } from "../src/testutils";
185188

186189
const filePath = path.join("../src", "testdata", "testwallets", "alice.pem");
187190
const alice = await Account.newFromPem(filePath);
188-
const deployTransaction = factory.createTransactionForDeploy(alice.address, {
191+
const deployTransaction = await factory.createTransactionForDeploy(alice.address, {
189192
bytecode: bytecode,
190193
gasLimit: 6000000n,
191194
arguments: args,
@@ -209,7 +212,7 @@ import { loadAbiRegistry } from "../src/testutils";
209212
const factory = entrypoint.createSmartContractTransactionsFactory();
210213

211214
// load the contract bytecode
212-
const bytecode = await promises.readFile("../src/testData/adder.wasm");
215+
const bytecode = await fs.promises.readFile("../src/testdata/adder.wasm");
213216

214217
// For deploy arguments, use "TypedValue" objects if you haven't provided an ABI to the factory: // md-as-comment
215218
let args: any[] = [new BigUIntValue(42)];
@@ -265,7 +268,10 @@ import { loadAbiRegistry } from "../src/testutils";
265268
sender.nonce = await entrypoint.recallAccountNonce(sender.address);
266269

267270
// load the abi file
268-
const abi = await loadAbiRegistry("../src/testdata/adder.abi.json");
271+
const jsonContent: string = await fs.promises.readFile("../src/testdata/adder.abi.json", {
272+
encoding: "utf8",
273+
});
274+
const abi = Abi.create(JSON.parse(jsonContent));
269275
const controller = entrypoint.createSmartContractController(abi);
270276

271277
const contractAddress = Address.newFromBech32("erd1qqqqqqqqqqqqqpgq7cmfueefdqkjsnnjnwydw902v8pwjqy3d8ssd4meug");
@@ -317,7 +323,10 @@ import { loadAbiRegistry } from "../src/testutils";
317323
sender.nonce = await entrypoint.recallAccountNonce(sender.address);
318324

319325
// load the abi file
320-
const abi = await loadAbiRegistry("../src/testdata/adder.abi.json");
326+
const jsonContent: string = await fs.promises.readFile("../src/testdata/adder.abi.json", {
327+
encoding: "utf8",
328+
});
329+
const abi = Abi.create(JSON.parse(jsonContent));
321330

322331
// get the smart contracts controller
323332
const controller = entrypoint.createSmartContractController(abi);
@@ -407,7 +416,10 @@ import { loadAbiRegistry } from "../src/testutils";
407416
{
408417
// load the abi file
409418
const entrypoint = new DevnetEntrypoint();
410-
const abi = await loadAbiRegistry("../src/testdata/adder.abi.json");
419+
const jsonContent: string = await fs.promises.readFile("../src/testdata/adder.abi.json", {
420+
encoding: "utf8",
421+
});
422+
const abi = Abi.create(JSON.parse(jsonContent));
411423
const parser = new SmartContractTransactionsOutcomeParser({ abi });
412424
const txHash = "b3ae88ad05c464a74db73f4013de05abcfcb4fb6647c67a262a6cfdf330ef4a9";
413425
const transactionOnNetwork = await entrypoint.getTransaction(txHash);
@@ -426,7 +438,10 @@ import { loadAbiRegistry } from "../src/testutils";
426438
{
427439
// load the abi files
428440
const entrypoint = new DevnetEntrypoint();
429-
const abi = await loadAbiRegistry("../src/testdata/adder.abi.json");
441+
const jsonContent: string = await fs.promises.readFile("../src/testdata/adder.abi.json", {
442+
encoding: "utf8",
443+
});
444+
const abi = Abi.create(JSON.parse(jsonContent));
430445
const parser = new TransactionEventsParser({ abi });
431446
const txHash = "b3ae88ad05c464a74db73f4013de05abcfcb4fb6647c67a262a6cfdf330ef4a9";
432447
const transactionOnNetwork = await entrypoint.getTransaction(txHash);
@@ -441,7 +456,10 @@ import { loadAbiRegistry } from "../src/testutils";
441456
// Let's encode a struct called EsdtTokenPayment (of [multisig](https://github.com/multiversx/mx-contracts-rs/tree/main/contracts/multisig) contract) into binary data.
442457
// ```js
443458
{
444-
const abi = await loadAbiRegistry("../src/testdata/multisig-full.abi.json");
459+
const jsonContent: string = await fs.promises.readFile("../src/testdata/multisig-full.abi.json", {
460+
encoding: "utf8",
461+
});
462+
const abi = Abi.create(JSON.parse(jsonContent));
445463
const paymentType = abi.getStruct("EsdtTokenPayment");
446464
const codec = new BinaryCodec();
447465

@@ -460,7 +478,10 @@ import { loadAbiRegistry } from "../src/testutils";
460478
// Now let's decode a struct using the ABI.
461479
// ```js
462480
{
463-
const abi = await loadAbiRegistry("../src/testdata/multisig-full.abi.json");
481+
const jsonContent: string = await fs.promises.readFile("../src/testdata/multisig-full.abi.json", {
482+
encoding: "utf8",
483+
});
484+
const abi = Abi.create(JSON.parse(jsonContent));
464485
const actionStructType = abi.getEnum("Action");
465486
const data = Buffer.from(
466487
"0500000000000000000500d006f73c4221216fa679bc559005584c4f1160e569e1000000012a0000000003616464000000010000000107",
@@ -483,7 +504,10 @@ import { loadAbiRegistry } from "../src/testutils";
483504
{
484505
const entrypoint = new DevnetEntrypoint();
485506
const contractAddress = Address.newFromBech32("erd1qqqqqqqqqqqqqpgq7cmfueefdqkjsnnjnwydw902v8pwjqy3d8ssd4meug");
486-
const abi = await loadAbiRegistry("../src/testdata/adder.abi.json");
507+
const jsonContent: string = await fs.promises.readFile("../src/testdata/adder.abi.json", {
508+
encoding: "utf8",
509+
});
510+
const abi = Abi.create(JSON.parse(jsonContent));
487511

488512
// create the controller
489513
const controller = entrypoint.createSmartContractController(abi);
@@ -501,7 +525,10 @@ import { loadAbiRegistry } from "../src/testutils";
501525
const entrypoint = new DevnetEntrypoint();
502526

503527
// load the abi
504-
const abi = await loadAbiRegistry("../src/testdata/adder.abi.json");
528+
const jsonContent: string = await fs.promises.readFile("../src/testdata/adder.abi.json", {
529+
encoding: "utf8",
530+
});
531+
const abi = Abi.create(JSON.parse(jsonContent));
505532

506533
// the contract address we'll query
507534
const contractAddress = Address.newFromBech32("erd1qqqqqqqqqqqqqpgq7cmfueefdqkjsnnjnwydw902v8pwjqy3d8ssd4meug");
@@ -534,13 +561,16 @@ import { loadAbiRegistry } from "../src/testutils";
534561
sender.nonce = await entrypoint.recallAccountNonce(sender.address);
535562

536563
// load the abi
537-
const abi = await loadAbiRegistry("../src/testdata/adder.abi.json");
564+
const jsonContent: string = await fs.promises.readFile("../src/testdata/adder.abi.json", {
565+
encoding: "utf8",
566+
});
567+
const abi = Abi.create(JSON.parse(jsonContent));
538568

539569
// create the controller
540570
const controller = entrypoint.createSmartContractController(abi);
541571

542572
// load the contract bytecode; this is the new contract code, the one we want to upgrade to
543-
const bytecode = await promises.readFile("../src/testData/adder.wasm");
573+
const bytecode = await fs.promises.readFile("../src/testdata/adder.wasm");
544574

545575
// For deploy arguments, use "TypedValue" objects if you haven't provided an ABI to the factory: // md-as-comment
546576
let args: any[] = [new U32Value(42)];

0 commit comments

Comments
 (0)