-
Notifications
You must be signed in to change notification settings - Fork 48
Merge main in next branch #645
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
48285a0
Add multisig documentation
danielailie 2653416
set default values for optional args
popenta 0927835
fix typos
popenta 65cf7dd
fix args default
popenta 12cc1fa
set default values for optional args
popenta 001a0dd
fix typos
popenta db8d622
fix args default
popenta 169b6ff
Fic proposeTransferExecute
danielailie 729b99b
bump version and fix critical version
danielailie f44de48
Update multisig docs
danielailie 82aeb02
Merge branch 'main' into TOOL-641-add-multisig-documentation
danielailie f2def19
Code review follow up
danielailie e0f29d0
Add missing await
danielailie 4947557
Merge pull request #639 from multiversx/TOOL-641-add-multisig-documen…
danielailie c82ded4
Merge branch 'main' into Merge-main-in-next-branch
danielailie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,188 @@ | ||
| import path from "path"; // md-ignore | ||
| import { Account, Address, DevnetEntrypoint, TransactionWatcher } from "../src"; // md-ignore | ||
| import { MultisigTransactionsOutcomeParser } from "../src/multisig/multisigTransactionsOutcomeParser"; | ||
| import { loadAbiRegistry, loadContractCode } from "../src/testutils"; | ||
| // md-start | ||
| (async () => { | ||
| // ### Multisig | ||
|
|
||
| // The sdk contains components to interact with the [Multisig Contract](https://github.com/multiversx/mx-contracts-rs/releases/tag/v0.45.5). | ||
| // We can deploy a multisig smart contract, add members, propose and execute actions and query the contract. | ||
| // The same as the other components, to interact with a multisig smart contract we can use either the MultisigController or the MultisigTransactionsFactory. | ||
|
|
||
| // These operations can be performed using both the **controller** and the **factory**. For a complete list of supported methods, please refer to the autogenerated documentation: | ||
| // - `class:MultisigController` | ||
| // - `class:MultisigTransactionsFactory` | ||
|
|
||
| // #### Deploying a Multisig Smart Contract using the controller | ||
| // ```js | ||
| { | ||
| const abi = await loadAbiRegistry("src/testdata/multisig-full.abi.json"); | ||
| const bytecode = await loadContractCode("src/testdata/multisig-full.wasm"); | ||
|
|
||
| // create the entrypoint and the multisig controller // md-as-comment | ||
| const entrypoint = new DevnetEntrypoint(); | ||
| const controller = entrypoint.createMultisigController(abi); | ||
|
|
||
| const filePath = path.join("../src", "testdata", "testwallets", "alice.pem"); | ||
| const alice = await Account.newFromPem(filePath); | ||
|
|
||
| // fetch the nonce of the network // md-as-comment | ||
| alice.nonce = await entrypoint.recallAccountNonce(alice.address); | ||
|
|
||
| const transaction = await controller.createTransactionForDeploy(alice, alice.getNonceThenIncrement(), { | ||
| quorum: 2, | ||
| board: [ | ||
| alice.address, | ||
| Address.newFromBech32("erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx"), | ||
| ], | ||
| bytecode: bytecode.valueOf(), | ||
| gasLimit: 100000000n, | ||
| }); | ||
|
|
||
| // sending the transaction // md-as-comment | ||
| const txHash = await entrypoint.sendTransaction(transaction); | ||
|
|
||
| // wait for transaction completion, extract multisig contract's address // md-as-comment | ||
| const outcome = await controller.awaitCompletedDeploy(txHash); | ||
|
|
||
| const contractAddress = outcome[0].contractAddress; | ||
| } | ||
| // ``` | ||
|
|
||
| // #### Deploying a Multisig Smart Contract using the factory | ||
| // ```js | ||
| { | ||
| const abi = await loadAbiRegistry("src/testdata/multisig-full.abi.json"); | ||
| const bytecode = await loadContractCode("src/testdata/multisig-full.wasm"); | ||
|
|
||
| // create the entrypoint and the multisig factory // md-as-comment | ||
| const entrypoint = new DevnetEntrypoint(); | ||
| const factory = entrypoint.createMultisigTransactionsFactory(abi); | ||
|
|
||
| const filePath = path.join("../src", "testdata", "testwallets", "alice.pem"); | ||
| const alice = await Account.newFromPem(filePath); | ||
|
|
||
| // fetch the nonce of the network // md-as-comment | ||
| alice.nonce = await entrypoint.recallAccountNonce(alice.address); | ||
|
|
||
| const transaction = await factory.createTransactionForDeploy(alice.address, { | ||
| quorum: 2, | ||
| board: [ | ||
| alice.address, | ||
| Address.newFromBech32("erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx"), | ||
| ], | ||
| bytecode: bytecode.valueOf(), | ||
| gasLimit: 100000000n, | ||
| }); | ||
|
|
||
| transaction.nonce = alice.getNonceThenIncrement(); | ||
| transaction.signature = await alice.signTransaction(transaction); | ||
| // sending the transaction // md-as-comment | ||
| const txHash = await entrypoint.sendTransaction(transaction); | ||
| } | ||
| // ``` | ||
|
|
||
| // #### Propose an action using the controller | ||
| // We'll propose an action to send some EGLD to Carol. After we sent the proposal, we'll also parse the outcome of the transaction to get the `proposal id`. | ||
| // The id can be used later for signing and performing the proposal. | ||
|
|
||
| // ```js | ||
| { | ||
| // create the entrypoint and the multisig controller // md-as-comment | ||
| const entrypoint = new DevnetEntrypoint(); | ||
| const abi = await loadAbiRegistry("src/testdata/multisig-full.abi.json"); | ||
| const controller = entrypoint.createMultisigController(abi); | ||
|
|
||
| const filePath = path.join("../src", "testdata", "testwallets", "alice.pem"); | ||
| const alice = await Account.newFromPem(filePath); | ||
|
|
||
| // fetch the nonce of the network // md-as-comment | ||
| alice.nonce = await entrypoint.recallAccountNonce(alice.address); | ||
|
|
||
| const contract = Address.newFromBech32("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqf8llllswuedva"); | ||
|
|
||
| const transaction = await controller.createTransactionForProposeTransferExecute( | ||
| alice, | ||
| alice.getNonceThenIncrement(), | ||
| { | ||
| multisigContract: contract, | ||
| to: Address.newFromBech32("erd1k2s324ww2g0yj38qn2ch2jwctdy8mnfxep94q9arncc6xecg3xaq6mjse8"), | ||
| gasLimit: 10000000n, | ||
| nativeTokenAmount: 1000000000000000000n, | ||
| }, | ||
| ); | ||
|
|
||
| // sending the transaction // md-as-comment | ||
| const txHash = await entrypoint.sendTransaction(transaction); | ||
|
|
||
| // parse the outcome and get the proposal id | ||
| const actionId = await controller.awaitCompletedPerformAction(txHash); | ||
| } | ||
| // ``` | ||
|
|
||
| // #### Propose an action using the factory | ||
| // Proposing an action for a multisig contract using the MultisigFactory is very similar to using the controller, but in order to get the proposal id, we need to use MultisigTransactionsOutcomeParser. | ||
|
|
||
| // ```js | ||
| { | ||
| const abi = await loadAbiRegistry("src/testdata/multisig-full.abi.json"); | ||
|
|
||
| // create the entrypoint and the multisig factory // md-as-comment | ||
| const entrypoint = new DevnetEntrypoint(); | ||
| const provider = entrypoint.createNetworkProvider(); | ||
| const factory = entrypoint.createMultisigTransactionsFactory(abi); | ||
|
|
||
| const filePath = path.join("../src", "testdata", "testwallets", "alice.pem"); | ||
| const alice = await Account.newFromPem(filePath); | ||
|
|
||
| const contract = Address.newFromBech32("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqf8llllswuedva"); | ||
|
|
||
| const transaction = await factory.createTransactionForProposeTransferExecute(alice.address, { | ||
| multisigContract: contract, | ||
| to: Address.newFromBech32("erd1k2s324ww2g0yj38qn2ch2jwctdy8mnfxep94q9arncc6xecg3xaq6mjse8"), | ||
| gasLimit: 10000000n, | ||
| nativeTokenAmount: 1000000000000000000n, | ||
| }); | ||
| // fetch the nonce of the network // md-as-comment | ||
| alice.nonce = await entrypoint.recallAccountNonce(alice.address); | ||
|
|
||
| // set the nonce // md-as-comment | ||
| transaction.nonce = alice.getNonceThenIncrement(); | ||
|
|
||
| // sign the transaction // md-as-comment | ||
| transaction.signature = await alice.signTransaction(transaction); | ||
|
|
||
| // sending the transaction // md-as-comment | ||
| const txHash = await entrypoint.sendTransaction(transaction); | ||
|
|
||
| // wait for the transaction to execute | ||
| const transactionAwaiter = new TransactionWatcher(provider); | ||
| const transactionOnNetwork = await transactionAwaiter.awaitCompleted(txHash); | ||
|
|
||
| // parse the outcome of the transaction | ||
| const parser = new MultisigTransactionsOutcomeParser({ abi }); | ||
| const actionId = parser.parseProposeAction(transactionOnNetwork); | ||
| } | ||
| // ``` | ||
|
|
||
| // #### Querying the Multisig Smart Contract | ||
| // Unlike creating transactions, querying the multisig can be performed only using the controller. | ||
| // Let's query the contract to get all board members. | ||
|
|
||
| // ```js | ||
| { | ||
| const abi = await loadAbiRegistry("src/testdata/multisig-full.abi.json"); | ||
|
|
||
| // create the entrypoint and the multisig controller // md-as-comment | ||
| const entrypoint = new DevnetEntrypoint(); | ||
| const controller = entrypoint.createMultisigController(abi); | ||
|
|
||
| const contract = Address.newFromBech32("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqf8llllswuedva"); | ||
|
|
||
| const boardMembers = await controller.getAllBoardMembers({ multisigAddress: contract.toBech32() }); | ||
| } | ||
| // ``` | ||
| })().catch((e) => { | ||
| console.log({ e }); | ||
| }); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The nonce is fetched after creating the transaction but should be fetched before creating the transaction. This creates inconsistency with the controller pattern shown earlier and may cause nonce synchronization issues.