Skip to content

Commit

Permalink
Updated Rust guide to include information about transferring assets (#…
Browse files Browse the repository at this point in the history
…483)

* Updated Rust guide to include information about transferring assets

Signed-off-by: enxtur <[email protected]>

* Apply suggestions from code review

Signed-off-by: Ekaterina Mekhnetsova <[email protected]>

* Update instructions.md

Signed-off-by: Ekaterina Mekhnetsova <[email protected]>

* Update instructions.md

Signed-off-by: Ekaterina Mekhnetsova <[email protected]>

---------

Signed-off-by: enxtur <[email protected]>
Signed-off-by: Ekaterina Mekhnetsova <[email protected]>
Co-authored-by: Ekaterina Mekhnetsova <[email protected]>
  • Loading branch information
enxtur and outoftardis authored May 14, 2024
1 parent 45f94c4 commit 5ed9fe0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/guide/blockchain/instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ process of minting assets in a blockchain:
Here are examples of burning assets:

- [Bash](/guide/get-started/bash.md#_7-burning-assets)
- [Rust](/guide/get-started/rust.md#_6-burning-assets)
- [Rust](/guide/get-started/rust.md#_7-burning-assets)

## Transfer

Expand All @@ -149,7 +149,7 @@ can transfer assets between different accounts.
To do this, an account have to be granted the
[permission to transfer assets](/reference/permissions.md).
Refer to an example on how to
[transfer assets in Bash](/guide/get-started/bash.md#_6-transferring-assets).
transfer assets in [Bash](/guide/get-started/bash.md#_6-transferring-assets) or [Rust](/guide/get-started/rust.md#_6-transferring-assets).

<!--TODO: add links to transferring assets example in which guide after https://github.com/hyperledger/iroha-2-docs/issues/81 is addressed -->

Expand Down
38 changes: 36 additions & 2 deletions src/guide/get-started/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,41 @@ in that transaction?_

:::

## 6. Burning assets
## 6. Transferring assets

Transferring assets is a bit more involved than minting them. First, you
need to know the account ID of the account that you're transferring from
and the account ID of the account that you're transferring to.

```rust
let from_account_id: AccountId = "alice@wonderland".parse().unwrap();
let to_id: AccountId = "bob@wonderland".parse().unwrap();
```

You also need to know the asset ID of the asset that you're transferring:

```rust
let asset_definition_id: AssetDefinitionId = "time#looking_glass".parse().unwrap();
let from_asset_id = AssetId::new(asset_definition_id, from_account_id);
```

Then you need to specify the amount that you're transferring:

```rust
let amount = 1 as u32;
let value: Value = amount.into();
```

Then you can create a transfer instruction and submit it:

```rust
let from_id_box = IdBox::AssetId(from_asset_id);
let to_id_box = IdBox::AccountId(to_id);
let transfer_expr = TransferExpr::new(from_id_box, value, to_id_box);
client.submit(transfer_expr);
```

## 7. Burning assets

Burning assets is quite similar to minting. First, you create the burn
instruction indicating which asset to burn and its quantity.
Expand All @@ -330,7 +364,7 @@ Then submit this instruction:
iroha_client.submit(burn_roses)?;
```

## 7. Visualising outputs
## 8. Visualising outputs

Finally, we should talk about visualising data. The Rust API is currently
the most complete in terms of available queries and instructions. After
Expand Down

0 comments on commit 5ed9fe0

Please sign in to comment.