From 045926daf151c977e68b02abdcb6dd70b2044916 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Mon, 23 Oct 2023 21:33:31 +0300 Subject: [PATCH 1/2] mxpy cookbook: "Using the Ledger hardware wallet". --- docs/developers/data/defaults.md | 2 +- docs/developers/relayed-transactions.md | 8 +-- docs/sdk-and-tools/sdk-py/mxpy-cli.md | 80 +++++++++++++++++++++++++ 3 files changed, 85 insertions(+), 5 deletions(-) diff --git a/docs/developers/data/defaults.md b/docs/developers/data/defaults.md index 4d875128..b6b4828a 100644 --- a/docs/developers/data/defaults.md +++ b/docs/developers/data/defaults.md @@ -26,7 +26,7 @@ For instance, for all numeric types, zero is the default value, because we repre | `u32` | `0` | | `u64` | `0` | | `usize` | `0` | -| `BigUnt` | `0` | +| `BigUint` | `0` | | `i8` | `0` | | `i16` | `0` | | `i32` | `0` | diff --git a/docs/developers/relayed-transactions.md b/docs/developers/relayed-transactions.md index 2848bccf..bc37382f 100644 --- a/docs/developers/relayed-transactions.md +++ b/docs/developers/relayed-transactions.md @@ -31,7 +31,7 @@ A relayed transaction version 1 relies on having the inner transaction JSON seri It would look like: -```rust +``` RelayedV1Transaction { Sender: Receiver:
@@ -44,7 +44,7 @@ RelayedV1Transaction { The inner transaction can have a format like this: -```rust +``` RelayedV1InnerTransaction { Sender: Receiver: @@ -168,7 +168,7 @@ the matching gas limit values between the relayed and inner transactions. It would look like: -```rust +``` RelayedV2Transaction { Sender: Receiver:
@@ -183,7 +183,7 @@ RelayedV2Transaction { ``` :::note -Noticing the arguments needed, there are some limitations for the inner transaction: it cannot have call value, a custom gas price or a guardian +Noticing the arguments needed, there are some limitations for the inner transaction: it cannot have call value, a custom gas price or a guardian. ::: Therefore, when one wants to build such a transaction, the steps would be: diff --git a/docs/sdk-and-tools/sdk-py/mxpy-cli.md b/docs/sdk-and-tools/sdk-py/mxpy-cli.md index a11474ce..911a6da1 100644 --- a/docs/sdk-and-tools/sdk-py/mxpy-cli.md +++ b/docs/sdk-and-tools/sdk-py/mxpy-cli.md @@ -329,3 +329,83 @@ mxpy tx new --pem ~/multiversx-sdk/testwallets/latest/users/alice.pem --recall-n 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. + +## 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. + +First, connect your device to the computer, unlock it and open the MultiversX Ledger app. + +Then, you can perform a trivial connectivty check by running: + +```sh +mxpy ledger version +``` + +The output should look like this: + +```sh +MultiversX App version: ... +``` + +Another trivial check is to ask the device for the (first 10) MultiversX addresses it manages: + +```sh +mxpy ledger addresses +``` + +The output should look like this: + +```sh +account index = 0 | address index = 0 | address: erd1... +account index = 0 | address index = 1 | address: erd1... +account index = 0 | address index = 2 | address: erd1... +... +``` + +Now let's sign and broadcast a transaction (EGLD transfer): + +```sh +mxpy tx new --proxy https://devnet2-gateway.multiversx.com --recall-nonce \ + --receiver erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th \ + --gas-limit 50000 --value 1000000000000000000 \ + --ledger \ + --send +``` + +By default, the first MultiversX address managed by the device is used as the sender (signer) of the transaction. In order to select a different address, you can use the `--ledger-address-index` CLI parameter: + +```sh +mxpy tx new --proxy https://devnet2-gateway.multiversx.com --recall-nonce \ + --receiver erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th \ + --gas-limit 50000 --value 1000000000000000000 \ + --ledger --ledger-address-index=42 \ + --send +``` + +:::info +For MultiversX, **the account index should always be `0`**, while the address index is allowed to vary. Therefore, you should not use the `--ledger-account-index` CLI parameter (it will be removed in a future release). +::: + +Now let's deploy a smart contract using the Ledger: + +```sh +mxpy contract deploy --proxy=https://devnet2-gateway.multiversx.com --recall-nonce \ + --bytecode=counter.wasm --gas-limit=5000000 \ + --ledger --ledger-address-index=42 \ + --send +``` + +Then, perform a contract call: + +```sh +mxpy contract call erd1qqqqqqqqqqqqqpgqwwef37kmegph97egvvrxh3nccx7xuygez8ns682zz0 \ + --proxy=https://devnet2-gateway.multiversx.com --recall-nonce \ + --function increment --gas-limit 5000000 \ + --ledger --ledger-address-index=42 \ + --send +``` + +:::note +As of October 2023, on Windows (or WSL), you might encounter some issues when trying to use Ledger in `mxpy`. +::: From 45fef0d880ed6fc1b1450dfba02977d113581273 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Tue, 24 Oct 2023 13:11:37 +0300 Subject: [PATCH 2/2] Fix after review. --- docs/developers/relayed-transactions.md | 6 +++--- docs/sdk-and-tools/sdk-py/mxpy-cli.md | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/developers/relayed-transactions.md b/docs/developers/relayed-transactions.md index bc37382f..8cc75352 100644 --- a/docs/developers/relayed-transactions.md +++ b/docs/developers/relayed-transactions.md @@ -31,7 +31,7 @@ A relayed transaction version 1 relies on having the inner transaction JSON seri It would look like: -``` +```rust RelayedV1Transaction { Sender: Receiver:
@@ -44,7 +44,7 @@ RelayedV1Transaction { The inner transaction can have a format like this: -``` +```rust RelayedV1InnerTransaction { Sender: Receiver: @@ -168,7 +168,7 @@ the matching gas limit values between the relayed and inner transactions. It would look like: -``` +```rust RelayedV2Transaction { Sender: Receiver:
diff --git a/docs/sdk-and-tools/sdk-py/mxpy-cli.md b/docs/sdk-and-tools/sdk-py/mxpy-cli.md index 911a6da1..6f3a6efc 100644 --- a/docs/sdk-and-tools/sdk-py/mxpy-cli.md +++ b/docs/sdk-and-tools/sdk-py/mxpy-cli.md @@ -336,7 +336,7 @@ You can sign any transaction (regular transfers, smart contract deployments and First, connect your device to the computer, unlock it and open the MultiversX Ledger app. -Then, you can perform a trivial connectivty check by running: +Then, you can perform a trivial connectivity check by running: ```sh mxpy ledger version @@ -366,7 +366,7 @@ account index = 0 | address index = 2 | address: erd1... Now let's sign and broadcast a transaction (EGLD transfer): ```sh -mxpy tx new --proxy https://devnet2-gateway.multiversx.com --recall-nonce \ +mxpy tx new --proxy https://devnet-gateway.multiversx.com --recall-nonce \ --receiver erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th \ --gas-limit 50000 --value 1000000000000000000 \ --ledger \ @@ -376,7 +376,7 @@ mxpy tx new --proxy https://devnet2-gateway.multiversx.com --recall-nonce \ By default, the first MultiversX address managed by the device is used as the sender (signer) of the transaction. In order to select a different address, you can use the `--ledger-address-index` CLI parameter: ```sh -mxpy tx new --proxy https://devnet2-gateway.multiversx.com --recall-nonce \ +mxpy tx new --proxy https://devnet-gateway.multiversx.com --recall-nonce \ --receiver erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th \ --gas-limit 50000 --value 1000000000000000000 \ --ledger --ledger-address-index=42 \ @@ -390,7 +390,7 @@ For MultiversX, **the account index should always be `0`**, while the address in Now let's deploy a smart contract using the Ledger: ```sh -mxpy contract deploy --proxy=https://devnet2-gateway.multiversx.com --recall-nonce \ +mxpy contract deploy --proxy=https://devnet-gateway.multiversx.com --recall-nonce \ --bytecode=counter.wasm --gas-limit=5000000 \ --ledger --ledger-address-index=42 \ --send @@ -400,7 +400,7 @@ Then, perform a contract call: ```sh mxpy contract call erd1qqqqqqqqqqqqqpgqwwef37kmegph97egvvrxh3nccx7xuygez8ns682zz0 \ - --proxy=https://devnet2-gateway.multiversx.com --recall-nonce \ + --proxy=https://devnet-gateway.multiversx.com --recall-nonce \ --function increment --gas-limit 5000000 \ --ledger --ledger-address-index=42 \ --send