diff --git a/docs/sdk-and-tools/overview.md b/docs/sdk-and-tools/overview.md index 33ba567a..e0fb205a 100644 --- a/docs/sdk-and-tools/overview.md +++ b/docs/sdk-and-tools/overview.md @@ -17,18 +17,18 @@ One can (programatically) interact with the MultiversX Network by leveraging the Note that Rust is also the recommended programming language for writing Smart Contracts on MultiversX. That is, Rust can be used to write both _on-chain software_ (Smart Contracts) and _off-chain software_ (e.g. desktop applications, web applications, microservices). For the on-chain part, please follow [Smart Contracts](/developers/smart-contracts). Here, we refer to the off-chain part. ::: -| Name | Description | -|---------------------------------|------------------------------------------------------------| -| [sdk-rs](https://github.com/multiversx/mx-sdk-rs) | Rust SDK used to interact with the MultiversX Blockchain.
This is the parent repository, also home to the Rust Framework for Smart Contracts. | -| [sdk-rs/core](https://github.com/multiversx/mx-sdk-rs/tree/master/sdk/core) | Core components, accompanied by a set of usage examples. | -| [sdk-rs/snippets](https://github.com/multiversx/mx-sdk-rs/tree/master/framework/snippets) | Smart Contract interaction snippets - base components. Examples of usage: [adder](https://github.com/multiversx/mx-sdk-rs/tree/master/contracts/examples/adder/interact), [multisig](https://github.com/multiversx/mx-sdk-rs/tree/master/contracts/examples/multisig/interact). | +| Name | Description | +| ----------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| [sdk-rs](https://github.com/multiversx/mx-sdk-rs) | Rust SDK used to interact with the MultiversX Blockchain.
This is the parent repository, also home to the Rust Framework for Smart Contracts. | +| [sdk-rs/core](https://github.com/multiversx/mx-sdk-rs/tree/master/sdk/core) | Core components, accompanied by a set of usage examples. | +| [sdk-rs/snippets](https://github.com/multiversx/mx-sdk-rs/tree/master/framework/snippets) | Smart Contract interaction snippets - base components. Examples of usage: [adder](https://github.com/multiversx/mx-sdk-rs/tree/master/contracts/examples/adder/interact), [multisig](https://github.com/multiversx/mx-sdk-rs/tree/master/contracts/examples/multisig/interact). | [comment]: # (mx-context-auto) ### sdk-js - Javascript SDK | Name | Description | -|----------------------------------------------------------------------------------------------------------|-----------------------------------------------------| +| -------------------------------------------------------------------------------------------------------- | --------------------------------------------------- | | [sdk-js](/sdk-and-tools/sdk-js) | High level overview about sdk-js. | | [sdk-js cookbook](/sdk-and-tools/sdk-js/sdk-js-cookbook-v13) | Learn how to handle common tasks by using sdk-js. | | [Extending sdk-js](/sdk-and-tools/sdk-js/extending-sdk-js) | How to extend and tailor certain modules of sdk-js. | @@ -39,7 +39,7 @@ Note that Rust is also the recommended programming language for writing Smart Co In addition to sdk-js, one could use the following Javascript library for performing wallet operations via CLI: | Name | Description | -|-------------------------------------------------------|--------------------------------------------------------------| +| ----------------------------------------------------- | ------------------------------------------------------------ | | [sdk-js-wallet-cli](/sdk-and-tools/sdk-js-wallet-cli) | Lightweight CLI wrapper used to perform wallet interactions. | You might also want to have a look over [**xSuite**](https://xsuite.dev), a toolkit to init, build, test, deploy contracts using JavaScript, made by the [Arda team](https://arda.run). @@ -48,77 +48,75 @@ You might also want to have a look over [**xSuite**](https://xsuite.dev), a tool ### sdk-dapp - core functional logic of a dApp -| Name | Description | -|-------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| Name | Description | +| ----------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | [sdk-dapp](/sdk-and-tools/sdk-dapp) | React library aimed to help developers create dApps based on MultiversX Network.

It abstracts away all the boilerplate for logging in, signing transactions or messages, and also offers helper functions for common tasks. | [comment]: # (mx-context-auto) ### sdk-py - Python SDK -| Name | Description | -|--------------------------------------------------------------------------------------------|----------------------------------------------------------| -| [sdk-py](/sdk-and-tools/sdk-py/#sdk-py-the-python-libraries) | Python SDK that can be used to create wallets, create and send transactions, interact with Smart Contracts and with the MultiversX Network in general. | +| Name | Description | +| ------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------ | +| [sdk-py](/sdk-and-tools/sdk-py/#sdk-py-the-python-libraries) | Python SDK that can be used to create wallets, create and send transactions, interact with Smart Contracts and with the MultiversX Network in general. | [comment]: # (mx-context-auto) ### mxpy - Python SDK (CLI) -| Name | Description | -|--------------------------------------------------------------------------------------------|----------------------------------------------------------| -| [mxpy](/sdk-and-tools/sdk-py/) | High level overview about mxpy. | -| [Installing mxpy](/sdk-and-tools/sdk-py/installing-mxpy) | How to install and get started with mxpy. | -| [Configuring mxpy](/sdk-and-tools/sdk-py/configuring-mxpy) | Change mxpy's basic configurations. | -| [mxpy cli](/sdk-and-tools/sdk-py/mxpy-cli) | How to use the Command Line Interface. | -| [Deriving the wallet pem file](/sdk-and-tools/sdk-py/deriving-the-wallet-pem-file) | How to use a wallet PEM file. | -| [Smart contract interactions](/sdk-and-tools/sdk-py/smart-contract-interactions) | Interact with Smart Contract. | +| Name | Description | +| -------------------------------------------------------------------------------- | ----------------------------------------- | +| [mxpy](/sdk-and-tools/sdk-py/) | High level overview about mxpy. | +| [Installing mxpy](/sdk-and-tools/sdk-py/installing-mxpy) | How to install and get started with mxpy. | +| [mxpy cli](/sdk-and-tools/sdk-py/mxpy-cli) | How to use the Command Line Interface. | +| [Smart contract interactions](/sdk-and-tools/sdk-py/smart-contract-interactions) | Interact with Smart Contract. | [comment]: # (mx-context-auto) ### sdk-nestjs - NestJS SDK -| Name | Description | -|------------------------------------------|--------------------------------------------------------------------| +| Name | Description | +| --------------------------------------- | ------------------------------------------------------------------ | | [sdk-nestjs](/sdk-and-tools/sdk-nestjs) | NestJS SDK commonly used in the MultiversX Microservice ecosystem. | [comment]: # (mx-context-auto) ### mx-sdk-go - Golang SDK -| Name | Description | -|-------------------------------|------------------------------------------------------------| +| Name | Description | +| ------------------------------- | -------------------------------------------------------------- | | [sdk-go](/sdk-and-tools/sdk-go) | Go/Golang SDK used to interact with the MultiversX Blockchain. | [comment]: # (mx-context-auto) ### mx-sdk-java - Java SDK -| Name | Description | -|-----------------------------------|-------------------------------------------------------| +| Name | Description | +| ------------------------------- | --------------------------------------------------------- | | [mxjava](/sdk-and-tools/mxjava) | Java SDK used to interact with the MultiversX Blockchain. | [comment]: # (mx-context-auto) ### erdcpp - C++ SDK -| Name | Description | -|---------------------------------|------------------------------------------------------| +| Name | Description | +| ------------------------------- | -------------------------------------------------------- | | [erdcpp](/sdk-and-tools/erdcpp) | C++ SDK used to interact with the MultiversX Blockchain. | [comment]: # (mx-context-auto) ### erdkotlin - Kotlin SDK -| Name | Description | -|---------------------------------------|---------------------------------------------------------| +| Name | Description | +| ------------------------------------- | ----------------------------------------------------------- | | [erdkotlin](/sdk-and-tools/erdkotlin) | Kotlin SDK used to interact with the MultiversX Blockchain. | [comment]: # (mx-context-auto) ### nesdtjs-sdk - NestJS SDK -| Name | Description | -|-----------------------------------------|---------------------------------------------------------| +| Name | Description | +| --------------------------------------- | ----------------------------------------------------------- | | [sdk-nestjs](/sdk-and-tools/sdk-nestjs) | NestJS SDK used to interact with the MultiversX Blockchain. | [comment]: # (mx-context-auto) @@ -126,7 +124,7 @@ You might also want to have a look over [**xSuite**](https://xsuite.dev), a tool ### Node Rest API | Name | Description | -|--------------------------------------------------------------------------|-------------------------------------------------------------------| +| ------------------------------------------------------------------------ | ----------------------------------------------------------------- | | [Rest API](/sdk-and-tools/rest-api/) | High level overview over the MultiversX's Rest API. | | [api.multiversx.com](/sdk-and-tools/rest-api/multiversx-api) | MultiversX's main API instance. | | [Gateway overview](/sdk-and-tools/rest-api/gateway-overview) | Gateway overview - public proxy instance. | @@ -146,7 +144,7 @@ Proxy is an abstraction layer over the MultiversX Network's sharding. It routes merges results when needed. | Name | Description | -|------------------------------------------|------------------------------------------------------| +| ---------------------------------------- | ---------------------------------------------------- | | [MultiversX Proxy](/sdk-and-tools/proxy) | A Rest API requests handler that abstracts sharding. | [comment]: # (mx-context-auto) @@ -156,7 +154,7 @@ merges results when needed. MultiversX Network uses Elasticsearch to index historical data. Find out more about how it can be configured. | Name | Description | -|------------------------------------------------|-----------------------------------------------------------------------------| +| ---------------------------------------------- | --------------------------------------------------------------------------- | | [Elasticsearch](/sdk-and-tools/elastic-search) | Make use of Elasticsearch near your nodes in order to keep historical data. | [comment]: # (mx-context-auto) @@ -166,24 +164,24 @@ MultiversX Network uses Elasticsearch to index historical data. Find out more ab Events notifier is an external service that can be used to fetch block events and push them to subscribers. | Name | Description | -|--------------------------------------------|--------------------------------------| +| ------------------------------------------ | ------------------------------------ | | [Events notifier](/sdk-and-tools/notifier) | A notifier service for block events. | [comment]: # (mx-context-auto) ### Chain simulator -Chain simulator is designed to replicate the behavior of a local testnet. +Chain simulator is designed to replicate the behavior of a local testnet. It can also be pre-initialized / initialized with blockchain state from other networks, such as mainnet or something similar. | Name | Description | -|---------------------------------------------------|------------------------------| +| ------------------------------------------------- | ---------------------------- | | [Chain simulator](/sdk-and-tools/chain-simulator) | A service for local testing. | [comment]: # (mx-context-auto) ### Devcontainers (for VSCode or GitHub Codespaces) -| Name | Description | -|-----------------------------------------------|--------------------------------------| +| Name | Description | +| --------------------------------------------- | ----------------------------------------------------------------------- | | [Devcontainers](/sdk-and-tools/devcontainers) | Overview of MultiversX devcontainers (for VSCode or GitHub Codespaces). | diff --git a/docs/sdk-and-tools/sdk-py/configuring-mxpy.md b/docs/sdk-and-tools/sdk-py/configuring-mxpy.md deleted file mode 100644 index 0e57d4af..00000000 --- a/docs/sdk-and-tools/sdk-py/configuring-mxpy.md +++ /dev/null @@ -1,34 +0,0 @@ ---- -id: configuring-mxpy -title: Configuring mxpy ---- - -[comment]: # (mx-abstract) - -This page describes how to configure `mxpy` (the CLI tool), using the `mxpy config` command. - -:::tip -mxpy's configuration is stored in the file `~/multiversx-sdk/mxpy.json`. -::: - -[comment]: # (mx-context-auto) - -## Viewing the current `mxpy` configuration - -In order to view the current configuration, one can issue the command `mxpy config dump`. Output example: - -```json -{ - "dependencies.rust.tag": "" -} -``` - -[comment]: # (mx-context-auto) - -## Updating the `mxpy` configuration - -One can alter the current configuration using the command `mxpy config set`. For example, in order to set the **_rust version_** to be used, one would do the following: - -```bash -$ mxpy config set dependencies.rust.tag stable -``` diff --git a/docs/sdk-and-tools/sdk-py/deriving-the-wallet-pem-file.md b/docs/sdk-and-tools/sdk-py/deriving-the-wallet-pem-file.md deleted file mode 100644 index 76a3bedd..00000000 --- a/docs/sdk-and-tools/sdk-py/deriving-the-wallet-pem-file.md +++ /dev/null @@ -1,61 +0,0 @@ ---- -id: deriving-the-wallet-pem-file -title: Deriving the Wallet PEM file ---- - -[comment]: # (mx-abstract) - -Submitting transactions with **mxpy** requires a JSON wallet (keystore) or a PEM file. On this page, we'll focus on deriving (creating) a PEM file, given a mnemonic (seed phrase). - -[comment]: # (mx-context-auto) - -## The `wallet convert` command - -To derive a PEM file for a Wallet, the mnemonic words (seed phrase) of that account are needed. Make sure you have them before continuing. - -The command for generating the PEM file from mnemonic words is: - -``` -mxpy wallet convert --in-format=raw-mnemonic --out-format=pem --outfile= -``` - -In the above command, you must replace `` with the name of the PEM file to be created. Upon running the command you will be asked to provide the mnemonic words. - -Here is an example: - -``` -mxpy wallet convert --in-format=raw-mnemonic --out-format=pem --outfile=./walletKey.pem -> words here some mnemonic words more words et cetera -``` - -The command above will generate a file called `walletKey.pem` in the current folder, using the mnemonic words you provided. - -[comment]: # (mx-context-auto) - -## Keep the PEM file safe - -:::caution -A PEM file generated from a Wallet should be kept very safe, because **it contains the private key** of that Wallet. -::: - -:::caution -Always safeguard any PEM files you have. Anyone who has them can submit transactions and perform actions in the MultiversX network as if they were you, so make sure nobody can get to them. -::: - -[comment]: # (mx-context-auto) - -## Passing the PEM file as a CLI parameter - -Now, whenever you want to submit a transaction from the command-line, you can tell **mxpy** to use this generated PEM file to sign the transaction with. For example: - -```bash -$ mxpy tx new --recall-nonce --data="Hello, World" --gas-limit=70000 \ - --receiver=erd1... \ - --pem=walletKey.pem \ - --send -``` - -:::tip -The MultiversX network makes no distinction between manually submitting a transaction, and submitting a transaction through **mxpy**. This means that every transaction you send with **mxpy** will appear on [https://wallet.multiversx.com](https://wallet.multiversx.com/) when you open the Wallet which you generated the PEM for. -::: - diff --git a/docs/sdk-and-tools/sdk-py/installing-mxpy.md b/docs/sdk-and-tools/sdk-py/installing-mxpy.md index a85d019f..168be854 100644 --- a/docs/sdk-and-tools/sdk-py/installing-mxpy.md +++ b/docs/sdk-and-tools/sdk-py/installing-mxpy.md @@ -21,14 +21,10 @@ Before installing **mxpy**, please make sure you have a working **Python 3** env ## **Install using pipx** -:::info -Keep in mind that installing using **pipx** is only available for **mxpy v9.2.0** or later. -::: - You'll need **pipx** installed on your machine. For more details on how to install **pipx** check out [**this page**](https://pipx.pypa.io/stable/#install-pipx). :::note -If you've previously installed **mxpy** using **mxpy-up** and you'd like to switch to **pipx**, make sure to remove the old `mxpy` shortcut and virtual Python environment beforehand: +If you've previously installed **mxpy** using **mxpy-up**, we advise you to switch to **pipx**, but make sure to remove the old `mxpy` shortcut and virtual Python environment beforehand: ```sh rm ~/multiversx-sdk/mxpy @@ -63,27 +59,18 @@ To check that **mxpy** installed successfully you can run the following command: mxpy --version ``` -[comment]: # (mx-context-auto) - -## **Upgrade mxpy using pipx** - -To upgrade **mxpy** to a newer version you can simply run the following command: +Additionally, if you'd like to have shell completion for `bash` and `zsh`, run the following command, then restart the shell: ```sh -pipx upgrade multiversx-sdk-cli +activate-global-python-argcomplete ``` [comment]: # (mx-context-auto) -## **Install using mxpy-up** - -Installing **mxpy** using **mxpy-up** is not recommended anymore. We recommend using **pipx** instead. +## **Upgrade mxpy using pipx** -If you've previously installed **mxpy** using the legacy **mxpy-up**, you should switch to the **pipx** approach. Make sure to remove the old `mxpy` shortcut and virtual Python environment beforehand: +To upgrade **mxpy** to a newer version, you can simply run the following command: ```sh -rm ~/multiversx-sdk/mxpy -rm -rf ~/multiversx-sdk/mxpy-venv +pipx upgrade multiversx-sdk-cli ``` - -Additionally, you might want to cleanup the shell profile files, to not alter anymore the `PATH` variable with respect to `~/multiversx-sdk`: `~/.profile`, `~/.bashrc` and / or `~/.zshrc`. diff --git a/docs/sdk-and-tools/sdk-py/mxpy-cli.md b/docs/sdk-and-tools/sdk-py/mxpy-cli.md index 1101dbb9..3af5065e 100644 --- a/docs/sdk-and-tools/sdk-py/mxpy-cli.md +++ b/docs/sdk-and-tools/sdk-py/mxpy-cli.md @@ -7,7 +7,7 @@ title: mxpy CLI cookbook ## mxpy (Command Line Interface) -**mxpy**, as a command-line tool, can be used to simplify and automate the interaction with the MultiversX network - it can be easily used in shell scripts, as well. It implements a set of **commands**, organized within **groups**. +**mxpy**, as a command-line tool, can be used to simplify and automate the interaction with the MultiversX network - it can be easily used in shell scripts, as well. It implements a set of **commands**, organized within **groups**. The complete Command Line Interface is listed [**here**](https://github.com/multiversx/mx-sdk-py-cli/blob/main/CLI.md). Command usage and description are available through the `--help` or `-h` flags. @@ -23,33 +23,6 @@ This page will guide you through the process of handling common tasks using **mx [comment]: # (mx-context-auto) -## Upgrading mxpy - -[comment]: # (mx-context-auto) - -### Upgrade using pipx - -In case you used **pipx** to install **mxpy**, to upgrade to a newer version, you can run the following command: - -```sh -pipx upgrade multiversx-sdk-cli -``` - -[comment]: # (mx-context-auto) - -### Using the installation script - -If you've previously installed **mxpy** using the legacy **mxpy-up** installation script, you should switch to the **pipx** approach. Make sure to remove the old `mxpy` shortcut and virtual Python environment beforehand: - -```sh -rm ~/multiversx-sdk/mxpy -rm -rf ~/multiversx-sdk/mxpy-venv -``` - -Additionally, you might want to cleanup the shell profile files, to not alter anymore the `PATH` variable with respect to `~/multiversx-sdk`: `~/.profile`, `~/.bashrc` and / or `~/.zshrc`. - -[comment]: # (mx-context-auto) - ## Managing dependencies Using `mxpy` you can either check if a dependency is installed or install a new dependency. @@ -68,7 +41,7 @@ mxpy deps install Both `mxpy deps check ` and `mxpy deps install ` use the `` as a positional argument. -To find out which dependencies can be managed using `mxpy` you can type one of the following commands and you will see which positional arguments it accepts: +To find out which dependencies can be managed using `mxpy`, you can type one of the following commands to see the positional arguments it accepts: ```sh mxpy deps check -h @@ -81,15 +54,21 @@ For example, in order to check if `rust` is installed you would type: mxpy deps check rust ``` -When installing dependecies the `--overwrite` argument can be used to overwrite an existing version. - For example, to install `rust`, you can simply type the command: ```sh mxpy deps install rust ``` -If no tag is provided **the default version** will be installed. +When installing dependencies, the `--overwrite` argument can be used to overwrite an existing version. + +For example, to overwrite your current `rust` installation, you can simply type the command: + +```sh +mxpy deps install rust --overwrite +``` + +If the configuration is not altered, **the default version** will be installed. :::note Default rust version Generally speaking, the default `rust` version installed by `mxpy` is the one referenced by [the latest Docker image](https://github.com/multiversx/mx-sdk-rust-contract-builder/blob/main/Dockerfile) used for reproducible builds. @@ -104,10 +83,34 @@ sudo apt-get install build-essential pkg-config libssl-dev ::: -Here's how to install a specific version of `rust` (example): +## Configuring mxpy -```sh -mxpy deps install rust --overwrite +The configuration can be altered using the `mxpy config` command. + +:::tip +mxpy's configuration is stored in the file `~/multiversx-sdk/mxpy.json`. +::: + +[comment]: # (mx-context-auto) + +### Viewing the current `mxpy` configuration + +In order to view the current configuration, one can issue the command `mxpy config dump`. Output example: + +```json +{ + "dependencies.rust.tag": "" +} +``` + +[comment]: # (mx-context-auto) + +### Updating the `mxpy` configuration + +One can alter the current configuration using the command `mxpy config set`. For example, in order to set the **_rust version_** to be used, one would do the following: + +```bash +$ mxpy config set dependencies.rust.tag stable ``` [comment]: # (mx-context-auto) @@ -174,7 +177,7 @@ mxpy wallet convert --help ## Building a smart contract -In order to deploy a smart contract on the network, you need to build it first. +In order to deploy a smart contract on the network, you need to build it first. The contract can be built using `mxpy`, but for a more granular approach, [sc-meta](/developers/meta/sc-build-reference#how-to-basic-build) should be used. To learn more about `sc-meta`, please check out [this page](/developers/meta/sc-meta). The contract we will be using for this examples can be found [here](https://github.com/multiversx/mx-contracts-rs/tree/main/contracts/adder). @@ -194,8 +197,6 @@ The command accepts a few parameters that you can check out [here](https://githu mxpy contract build --help ``` -If you'd like to build a smart contract directly using `sc-meta` instead, please follow [this](/developers/meta/sc-meta). - [comment]: # (mx-context-auto) ## Deploying a smart contract @@ -242,6 +243,44 @@ The `--pem` argument is used to provide the sender of the transaction, the payer [comment]: # (mx-context-auto) +### Deploying a smart contract providing the ABI file + +For functions that have complex arguments, we can use the ABI file generated when building the contract. The ABI can be provided using the `--abi` argument. When using the ABI, and only when using the ABI, the arguments should be written in a `json` file and should be provided via the `--arguments-file` argument. + +For this example, we'll use the [multisig contract](https://github.com/multiversx/mx-contracts-rs/tree/main/contracts/multisig). + +First, we'll prepare the file containing the constructors arguments. We'll refer to this file as `deploy_multisig_arguments.json`. The constructor requires two arguments, the first is of type `u32` and the second one is of type `variadic
`. All the arguments in this file **should** be placed inside a list. The arguments file should look like this: + +```json +[ + 2, + [ + { + "bech32": "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th" + }, + { + "hex": "8049d639e5a6980d1cd2392abcce41029cda74a1563523a202f09641cc2618f8" + } + ] +] +``` + +Let's go a bit through our file and see why it looks like this. First, as mentioned above, we have to place all the arguments inside a list. Then, the value `2` corresponds to the type `u32`. After that, we have another list that coresponds to the type `variadic`. Inside this list, we need to insert our addresses. For `mxpy`to encode addresses properly, we need to provide the address values inside a dictionary that can contain two keys: we can provide the address as the `bech32` representation or as the `hex encoded` public key. + +After finishing the arguments file, we can run the following command to deploy the contract: + +```sh +mxpy contract deploy --bytecode ~/contracts/multisig/output/multisig.wasm \ + --proxy=https://devnet-gateway.multiversx.com --recall-nonce \ + --abi ~/contracts/multisig/output/multisig.abi.json \ + --arguments-file deploy_multisig_arguments.json \ + --gas-limit 500000000 \ + --pem=~/multiversx-sdk/testwallets/latest/users/alice.pem \ + --send +``` + +[comment]: # (mx-context-auto) + ## Calling the Smart Contract After deploying our smart contract we can start interacting with it. The contract has a function called `add()` that we can call and it will increase the value stored in the contract with the value we provide. @@ -262,7 +301,47 @@ Using the `--function` argument we specify the function we want to call and with [comment]: # (mx-context-auto) -## Querying a Smart Contract +### Calling the smart contract providing the ABI file + +Same as we did for deploying the contract, we can call functions by providing the ABI file and the arguments file. + +Since we deployed the [multisig contract](https://github.com/multiversx/mx-contracts-rs/tree/main/contracts/multisig), we'll call the `proposeTransferExecute` endpoint. + +First, we'll prepare the file containing the endpoints arguments. We'll refer to this file as `call_multisig_arguments.json`. The `proposeTransferExecute` endpoint requires four arguments, the first is of type `Address`, the second one is of type `BigUInt`, the third is of type `Option` and the fourth is of type `variadic`. All the arguments in this file **should** be placed inside a list. The arguments file should look like this: + +```json +[ + { + "bech32": "erd1qqqqqqqqqqqqqpgqs63rcpahnwtjnedj5y6uuqh096nzf75gczpsc4fgtu" + }, + 1000000000000000000, + 5000000, + [ + { + "hex": "616464403037" + } + ] +] +``` + +Let's go a bit through our file and see why it looks like this. First, as mentioned above, we have to place all the arguments inside a list. Then, the contract expects an address, so we provide the `bech32` representation. After that, we have a `BigUInt` value that we can provide as a number. The third value is `Option`, so we provide it as a number, as well. In case we wanted to skip this value, we could've simply used `0`. The last parameter is of type `variadic`. Because it's a variadic value, we have to place the arguments inside a list. Since we can't write bytes, we `hex encode` the value and place it in a dictionary containing the key-value pair `"hex": ""`, same as we did above for the address. + +After finishing the arguments file, we can run the following command to call the endpoint: + +```sh +mxpy contract call erd1qqqqqqqqqqqqqpgqjsg84gq5e79rrc2rm5ervval3jrrfvvfd8sswc6xjy \ + --proxy=https://devnet-gateway.multiversx.com --recall-nonce \ + --abi ~/contracts/multisig/output/multisig.abi.json \ + --arguments-file call_multisig_arguments.json \ + --function proposeTransferExecute + --gas-limit 500000000 \ + --pem=~/multiversx-sdk/testwallets/latest/users/alice.pem \ + --send +``` + +[comment]: # (mx-context-auto) + +## Querying the Smart Contract Querying a contract is done by calling a so called `view function`. We can get data from a contract without sending a transaction to the contract, basically without spending money. @@ -280,6 +359,35 @@ We see that `mxpy` returns our value as a base64 string, as a hex number and as [comment]: # (mx-context-auto) +### Querying the smart contract providing the ABI file + +We'll call the `signed` readonly endpoint of the [multisig contract](https://github.com/multiversx/mx-contracts-rs/tree/main/contracts/multisig). This endpoint accepts two arguments: the first is the address, and the second is the proposal ID, which will be used to verify if the address has signed the proposal. The endpoint returns a `boolean` value, `true` if the address has signed the proposal and `false` otherwise. + +Let's prepare the arguments file. The first argument is of type `Address` and the second one is of type `u32`, so our file looks like this: + +```json +[ + { + "bech32": "erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx" + }, + 1 +] +``` + +As above, we encapsulate the address in a dictionary and the `u32` value is simply a number. We'll refer to this file as `query_multisig_arguments.json`. + +After preparing the file, we can run the following command: + +```sh +mxpy contract query erd1qqqqqqqqqqqqqpgqjsg84gq5e79rrc2rm5ervval3jrrfvvfd8sswc6xjy \ + --proxy https://devnet-gateway.multiversx.com \ + --function signed \ + --abi ~/contracts/multisig/output/multisig.abi.json \ + --arguments-file query_multisig_arguments.json +``` + +[comment]: # (mx-context-auto) + ## Upgrading a Smart Contract In case there's a new release of your Smart Contract, or perhaps you've patched a possible vulnerability you can upgrade the code of the Smart Contract deployed on the network. @@ -307,6 +415,19 @@ mxpy contract upgrade erd1qqqqqqqqqqqqqpgq3zrpqj3sulnc9xq95sljetxhf9s07pqtd8ssfk We provide as a positional argument the contract's address that we want to upgrade, in our case the previously deployed adder contract. The `--bytecode` is used to provide the new code that will replace the old code. We also set the `--arguments` to `0` as we didn't change the constructor and the contract will start counting from `0` again. The rest of the arguments you know from all the previous operations we've done. +As shown above, we can also upgrade the contract by providing the ABI file and the arguments file: + +```sh +mxpy contract upgrade erd1qqqqqqqqqqqqqpgq3zrpqj3sulnc9xq95sljetxhf9s07pqtd8ssfkxjv4 \ + --bytecode ~/contracts/adder/output/adder.wasm \ + --proxy=https://devnet-gateway.multiversx.com --chain D \ + --recall-nonce --gas-limit 5000000 \ + --pem=~/multiversx-sdk/testwallets/latest/users/alice.pem \ + --abi=~/contracts/multisig/output/multisig.abi.json, + --arguments-file=upgrade_arguments.json + --send +``` + Now let's add `5` to the contract one more time. We do so by running the following: ```sh @@ -373,7 +494,7 @@ mxpy tx new --pem ~/multiversx-sdk/testwallets/latest/users/alice.pem --recall-n --send ``` -That's it! As easy as that. We sent a transaction from Alice to Bob. We choose the receiver of our transaction using the `--receiver` argument and set the gas limit to `50000` because that is the gas cost of a simple move balance transaction. Notice we used the `--value` argument to pass the value that we want to transfer but we passed in the denomintated value. We transferred 1 eGLD (1 * 10^18). We then specify the proxy and the chain ID for the network we want to send our transaction to and use the `--send` argument to broadcast it. +That's it! As easy as that. We sent a transaction from Alice to Bob. We choose the receiver of our transaction using the `--receiver` argument and set the gas limit to `50000` because that is the gas cost of a simple move balance transaction. Notice we used the `--value` argument to pass the value that we want to transfer but we passed in the denomintated value. We transferred 1 eGLD (1 \* 10^18). We then specify the proxy and the chain ID for the network we want to send our transaction to and use the `--send` argument to broadcast it. In case you want to save the transaction you can also provide the `--outfile` argument and a `json` file containing the transaction will be saved at the specified location. If you just want to prepare the transaction without broadcasting it simply remove the `--send` argument. @@ -381,7 +502,7 @@ In case you want to save the transaction you can also provide the `--outfile` ar ## Guarded transactions -If your address is guarded, you'll have to provide some additional arguments because your transaction needs to be co-signed. +If your address is guarded, you'll have to provide some additional arguments because your transaction needs to be co-signed. The first extra argument we'll need is the `--guardian` argument. This specifies the guardian address of our address. Then, if our account is guarded by a service like our trusted co-signer service we have to provide the `--guardian-service-url` which specifies where the transaction is sent to be co-signed. @@ -413,6 +534,40 @@ If your address is guarded by another wallet, you'll still need to provide the ` [comment]: # (mx-context-auto) +## Relayed V3 transactions + +Relayed transactions are transactions with the fee paid by a so-called relayer. In other words, if a relayer is willing to pay for a transaction, it is not mandatory for the sender to have any EGLD for fees. To learn more about relayed transactions check out [this page](/developers/relayed-transactions/). + +In this section we'll see how we can send `Relayed V3` transactions using `mxpy`. For a more detailed look on `Relayed V3` transactions, take a look [here](/developers/relayed-transactions/#relayed-transactions-version-3). For these kind of transactions a new transaction field has been introduced, called `innerTransactions`. In this example we'll see how we can create both the inner transactions and the relayed transaction. + +### Creating the inner transactions + +We can simply create the inner transactions the same way we did above, by using the `mxpy tx new` command. The only difference is that we'll have to provide an additional argument called `--inner-transactions-outfile`, which represents the file where the inner transactions are saved to be later used by the relayer. To keep it simple, we'll send 1 EGLD from Alice to Bob and Carol will be the relayer. To create the EGLD transfer transaction from Alice to Bob we run the following command: + +```sh +mxpy tx new --pem ~/multiversx-sdk/testwallets/latest/users/alice.pem --recall-nonce \ + --receiver erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx \ + --gas-limit 50000 --value 1000000000000000000 \ + --proxy https://devnet-gateway.multiversx.com --chain D \ + --relayer erd1k2s324ww2g0yj38qn2ch2jwctdy8mnfxep94q9arncc6xecg3xaq6mjse8 + --inner-transactions-outfile inner_transactions.json +``` + +After creating the inner transaction, we are ready to create the relayed transaction. We have to keep in mind that for `Relayed V3` transactions, the receiver has to be the same as the relayer, in our case, Carol. Another requirement is that the relayed transaction has to have enough gas. The gas is computed by multiplying the base cost (50_000) with the number of inner transactions plus the gasLimit for each inner transaction. For more details on how the gas is computed, check out [this page](/developers/relayed-transactions/#relayed-transactions-version-3). + +We can create the relayed transaction by running the following command: + +```sh +mxpy tx new --pem ~/multiversx-sdk/testwallets/latest/users/carol.pem --recall-nonce \ + --receiver erd1k2s324ww2g0yj38qn2ch2jwctdy8mnfxep94q9arncc6xecg3xaq6mjse8 \ + --gas-limit 1000000 --value 0 \ + --proxy https://devnet-gateway.multiversx.com --chain D \ + --inner-transactions inner_transactions.json \ + --send +``` + +[comment]: # (mx-context-auto) + ## Using the Ledger hardware wallet You can sign any transaction (regular transfers, smart contract deployments and calls) using a Ledger hardware wallet by leveraging the `--ledger` command-line argument. diff --git a/docs/validators/staking/staking.md b/docs/validators/staking/staking.md index 2f142c1c..4f1fed8f 100644 --- a/docs/validators/staking/staking.md +++ b/docs/validators/staking/staking.md @@ -82,7 +82,7 @@ Make sure `mxpy` is installed by issuing this command on a terminal: mxpy --version ``` -The version reported by this command must be at least `mxpy 0.8.0`, or higher. If `mxpy` is not installed (`command not found`), or if the version is lower, please follow [these instructions](/sdk-and-tools/sdk-py/installing-mxpy). +If `mxpy` is not installed (`command not found`), please follow [these instructions](/sdk-and-tools/sdk-py/installing-mxpy). Make sure `mxpy` is installed and has the latest version before continuing. @@ -92,9 +92,9 @@ Make sure `mxpy` is installed and has the latest version before continuing. To send transactions on your behalf _without_ using the online MultiversX Wallet, `mxpy` must be able to sign for you. For this reason, you have to generate a PEM file using your Wallet mnemonic. -Please follow the guide [Deriving the Wallet PEM file](/sdk-and-tools/sdk-py/deriving-the-wallet-pem-file). Make sure you know exactly where the PEM file was generated, because you'll need to reference its path in the `mxpy` commands. +Please follow the guide [Deriving the Wallet PEM file](/sdk-and-tools/sdk-py/mxpy-cli#converting-a-wallet). Make sure you know exactly where the PEM file was generated, because you'll need to reference its path in the `mxpy` commands. -After the PEM file was generated, you can issue transactions from `mxpy`directly. +After the PEM file was generated, you can issue transactions from `mxpy` directly. [comment]: # (mx-context-auto) diff --git a/docusaurus.config.js b/docusaurus.config.js index 31e5da71..f40159de 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -447,44 +447,12 @@ const config = { to: "/sdk-and-tools/sdk-js/sdk-js-signing-providers", }, { - from: "/sdk-and-tools/erdpy", - to: "/sdk-and-tools/sdk-py", - }, - { - from: "/sdk-and-tools/erdpy/erdpy", - to: "/sdk-and-tools/sdk-py", - }, - { - from: "/sdk-and-tools/erdpy/erdpy-cookbook", - to: "/sdk-and-tools/sdk-py/sdk-py-cookbook", - }, - { - from: "/sdk-and-tools/erdpy/installing-erdpy", - to: "/sdk-and-tools/sdk-py/installing-mxpy", - }, - { - from: "/sdk-and-tools/erdpy/configuring-erdpy", - to: "/sdk-and-tools/sdk-py/configuring-mxpy", - }, - { - from: "/sdk-and-tools/erdpy/erdpy-cli", + from: "/sdk-and-tools/sdk-py/configuring-mxpy", to: "/sdk-and-tools/sdk-py/mxpy-cli", }, { - from: "/sdk-and-tools/erdpy/deriving-the-wallet-pem-file", - to: "/sdk-and-tools/sdk-py/deriving-the-wallet-pem-file", - }, - { - from: "/sdk-and-tools/erdpy/smart-contract-interactions", - to: "/sdk-and-tools/sdk-py/smart-contract-interactions", - }, - { - from: "/sdk-and-tools/erdpy/sending-bulk-transactions", - to: "/sdk-and-tools/sdk-py/sdk-py-cookbook", - }, - { - from: "/sdk-and-tools/erdpy/writing-and-running-mxpy-scripts", - to: "/sdk-and-tools/sdk-py/sdk-py-cookbook", + from: "/sdk-and-tools/sdk-py/deriving-the-wallet-pem-file", + to: "/sdk-and-tools/sdk-py/mxpy-cli", }, { from: "/developers/log-events/esdt-events", diff --git a/sidebars.js b/sidebars.js index a60b5321..69174bf9 100644 --- a/sidebars.js +++ b/sidebars.js @@ -200,9 +200,7 @@ const sidebars = { "sdk-and-tools/sdk-py/sdk-py", "sdk-and-tools/sdk-py/sdk-py-cookbook", "sdk-and-tools/sdk-py/installing-mxpy", - "sdk-and-tools/sdk-py/configuring-mxpy", "sdk-and-tools/sdk-py/mxpy-cli", - "sdk-and-tools/sdk-py/deriving-the-wallet-pem-file", "sdk-and-tools/sdk-py/smart-contract-interactions", "sdk-and-tools/sdk-py/sdk-py-migration-guides", ],