Skip to content

Commit

Permalink
Add example to README.md (#5)
Browse files Browse the repository at this point in the history
Co-authored-by: Stephen <[email protected]>
  • Loading branch information
samliok and StephenButtolph authored Feb 21, 2023
1 parent 7f10540 commit 30849fc
Showing 1 changed file with 90 additions and 1 deletion.
91 changes: 90 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
# Cross Subnet Virtual Machine (XSVM)

Cross Subnet Asset Transfers
Cross Subnet Asset Transfers README Overview

[Background](#avalanche-subnets-and-custom-vms)

[Introduction](#introduction)

[Usage](#how-it-works)

[Running](#running-the-vm)

[Demo](#cross-subnet-transaction-example)

## Avalanche Subnets and Custom VMs

Expand Down Expand Up @@ -286,3 +296,82 @@ You can do this by following the [subnet tutorial] or by using the [subnet-cli].
[Coreth]: https://github.com/ava-labs/coreth
[C-Chain]: https://docs.avax.network/learn/platform-overview/#contract-chain-c-chain
[Subnet]: https://docs.avax.network/learn/platform-overview/#subnets

## Cross Subnet Transaction Example

The following example shows how to interact with the XSVM to send and receive native assets across subnets.

### Overview of Steps

1. Create & deploy Subnet A
2. Create & deploy Subnet B
3. Issue an **export** Tx on Subnet A
4. Issue an **import** Tx on Subnet B
5. Confirm Txs processed correctly

> **Note:** This demo requires [avalanche-cli](https://github.com/ava-labs/avalanche-cli) version > 1.0.5, [xsvm](https://github.com/ava-labs/xsvm) version > 1.0.2 and [avalanche-network-runner](https://github.com/ava-labs/avalanche-network-runner) v1.3.5.
### Create and Deploy Subnet A, Subnet B

Using the avalanche-cli, this step deploys two subnets running the XSVM. Subnet A will act as the sender in this demo, and Subnet B will act as the receiver.

Steps

Build the [XSVM](https://github.com/ava-labs/xsvm)

### Create a genesis file

```bash
xsvm chain genesis --encoding binary > xsvm.genesis
```

### Create Subnet A and Subnet B

```bash
avalanche subnet create subnetA --custom --genesis <path_to_genesis> --vm <path_to_vm_binary>
avalanche subnet create subnetB --custom --genesis <path_to_genesis> --vm <path_to_vm_binary>
```

### Deploy Subnet A and Subnet B

```bash
avalanche subnet deploy subnetA --local
avalanche subnet deploy subnetB --local
```

### Issue Export Tx from Subnet A

The SubnetID and ChainIDs are stored in the sidecar.json files in your avalanche-cli directory. Typically this is located at $HOME/.avalanche/subnets/

```bash
xsvm issue export --source-chain-id <SubnetA.BlockchainID> --amount <export_amount> --destination-chain-id <SubnetB.BlockchainID>
```

Save the TxID printed out by running the export command.

### Issue Import Tx from Subnet B

> Note: The import tx requires **snowman++** consensus to be activated on the importing chain. A chain requires ~3 blocks to be produced for snowman++ to start.
> Run `xsvm issue transfer --chain-id <SubnetB.BlockchainID> --amount 1000` to issue simple Txs on SubnetB
```bash
xsvm issue import --source-chain-id <SubnetA.BlockchainID> --destination-chain-id <SubnetB.BlockchainID> --tx-id <exportTxID> --source-uris <source_uris>
```

> The <source_uris> can be found by running `avalanche network status`. The default URIs are
"http://localhost:9650,http://localhost:9652,http://localhost:9654,http://localhost:9656,http://localhost:9658"

**Account Values**
To check proper execution, use the `xsvm account` command to check balances.

Verify the balance on SubnetA decreased by your export amount using

```bash
xsvm account --chain-id <SubnetA.BlockchainID>
```

Now verify chain A's assets were successfully imported to SubnetB

```bash
xsvm account --chain-id <SubnetB.BlockchainID> --asset-id <SubnetA.BlockchainID>
```

0 comments on commit 30849fc

Please sign in to comment.