Skip to content
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

mxpy cookbook: "Using the Ledger hardware wallet" #725

Merged
merged 2 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion docs/developers/data/defaults.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |
Expand Down
8 changes: 4 additions & 4 deletions docs/developers/relayed-transactions.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ A relayed transaction version 1 relies on having the inner transaction JSON seri

It would look like:

```rust
```
RelayedV1Transaction {
Sender: <Relayer address>
Receiver: <Address that signed the inner transaction>
Expand All @@ -44,7 +44,7 @@ RelayedV1Transaction {

The inner transaction can have a format like this:

```rust
```
RelayedV1InnerTransaction {
Sender: <Receiver of the relayed transaction>
Receiver: <Smart Contract address>
Expand Down Expand Up @@ -168,7 +168,7 @@ the matching gas limit values between the relayed and inner transactions.

It would look like:

```rust
```
bogdan-rosianu marked this conversation as resolved.
Show resolved Hide resolved
RelayedV2Transaction {
Sender: <Relayer address>
Receiver: <Address that signed the inner transaction>
Expand All @@ -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:
Expand Down
80 changes: 80 additions & 0 deletions docs/sdk-and-tools/sdk-py/mxpy-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
bogdan-rosianu marked this conversation as resolved.
Show resolved Hide resolved

```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 \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use devnet instead of devnet2. For the other commands as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, fixed.

--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`.
:::
Loading