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

Teleporter devnet guide #1624

Closed
wants to merge 15 commits into from
Closed
Changes from all commits
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
154 changes: 150 additions & 4 deletions docs/tooling/cli-create-nodes/setup-a-devnet.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ For the second case we provide three important use cases examples:

- creating a devnet an deploy a preexistent CLI Subnet (same example as the step by step)
- creating a devnet, create a Subnet based on a Custom VM, and deploy it (similar to [
this one](/tooling/cli-create-nodes/upload-a-custom-vm-to-cloud))
this one](upload-a-custom-vm-to-cloud))
- creating a devnet with warp-enabled Subnets

## Step by Step
Expand Down Expand Up @@ -428,11 +428,11 @@ Devnet <clusterName> has been created and is validating subnet <subnetName>!

### Create a Devnet with Warp-Enabled Subnets

It will contain a warp-enabled C-Chain (always enabled by default on devnets), and two warp-enabled Subnet-EVM Subnets.
It will contain a Warp-enabled C-Chain (always enabled by default on devnets), and two Warp-enabled Subnet-EVM Subnets.

#### Subnet-EVM Setup

We will create two Subnet-EVM genesis files, both with warp enabled, but with different chain IDs (68430, 68431):
[Avalanche Warp Messaging](https://docs.avax.network/learn/avalanche/awm) is a cross-chain messaging protocol that allows Avalanche to natively send messages to other . We will create two Subnet-EVM genesis files, both with Warp enabled, but with different chain IDs (68430, 68431):

- create `<genesisPathA>`, with contents:

Expand Down Expand Up @@ -630,7 +630,7 @@ Devnet <clusterName> has been created and is validating subnet <subnetNameB>!

#### Obtaining Warp Devnet Parameters

Certain parameters are usually needed for warp interaction, we will show how to use CLI to obtain them.
Certain parameters are usually needed for Warp interaction, we will show how to use CLI to obtain them.

##### Blockchain Endpoints

Expand Down Expand Up @@ -757,3 +757,149 @@ curl http://52.204.202.216:9650/ext/bc/JjDfmxM3hAEX3VuaKH4PpQskhrvp2pzGTgYLpDwin

C-Chain endpoint follows the same scheme but with the blockchain alias of `C`: `http://52.204.202.216:9650/ext/bc/C/rpc`

<!-- vale off -->

#### Deploy Teleporter

<!-- vale on -->

<!-- vale off -->

[Teleporter](https://github.com/ava-labs/teleporter) is a cross-chain messaging protocol built on top of Warp. Teleporter provides a user-friendly interface to Warp that provides additional features such as replay protection, message delivery incentives, and message execution, to name a few.

Now that the Warp-enabled devnet is up and running, Teleporter can be deployed to the C-Chain and subnet-evm Subnets. Teleporter is deployed using [Nick's method](https://yamenmerhi.medium.com/nicks-method-ethereum-keyless-execution-168a6659479c) to ensure that the Teleporter contract is deployed to the same address on all chains. For instructions on how to deploy Teleporter, please see the guide [here.](https://github.com/ava-labs/teleporter/blob/main/utils/contract-deployment/README.md) Follow those instructions to deploy Teleporter to Subnet A, Subnet B, and the C-Chain.

<!-- vale on -->

#### Run an AWM Relayer instance

<!-- vale off -->

In order to deliver Warp and Teleporter messages between chains, an off-chain relayer is required. For this tutorial, we will use [AWM Relayer.](https://github.com/ava-labs/awm-relayer)

<!-- vale on -->

> **_NOTE:_** In this tutorial, we'll run the relayer on the same local machine from which we deployed the devnets, but these steps can be adapted to deploy the relayer in a cloud environment as well. The application itself has minimal hardware requirements, and is essentially stateless.

<!-- vale off -->

##### Configure the Relayer

<!-- vale on -->

First, we need to set the configuration using our devnet values. Below is a template relayer configuration with the values for Subnet A (which we deployed previously) filled in:

```json
{
"network-id": 1337,
"p-chain-api-url": "http://52.204.202.216:9650",
"encrypt-connection": false,
"source-subnets": [
{
"subnet-id": "11111111111111111111111111111111LpoYY",
"blockchain-id": "<C_CHAIN_BLOCKCHAIN_ID>",
"vm": "evm",
"api-node-host": "127.0.0.1",
"api-node-port": 9650,
"encrypt-connection": false,
"message-contracts": {
"<TELEPORTER_CONTRACT_ADDRESS>": {
"message-format": "teleporter",
"settings": {
"reward-address": "<REWARD_ADDRESS>"
}
}
}
},
{
"subnet-id": "giY8tswWgZmcAWzPkoNrmjjrykited7GJ9799SsFzTiq5a1ML",
"blockchain-id": "JjDfmxM3hAEX3VuaKH4PpQskhrvp2pzGTgYLpDwinMzFeHJYA",
"vm": "evm",
"api-node-host": "127.0.0.1",
"api-node-port": 9650,
"encrypt-connection": false,
"message-contracts": {
"<TELEPORTER_CONTRACT_ADDRESS>": {
"message-format": "teleporter",
"settings": {
"reward-address": "<REWARD_ADDRESS>"
}
}
}
}
],
"destination-subnets": [
{
"subnet-id": "11111111111111111111111111111111LpoYY",
"blockchain-id": "<C_CHAIN_BLOCKCHAIN_ID>",
"vm": "evm",
"api-node-host": "127.0.0.1",
"api-node-port": 9650,
"encrypt-connection": false,
"account-private-key": "<ACCOUNT_PRIVATE_KEY>"
},
{
"subnet-id": "giY8tswWgZmcAWzPkoNrmjjrykited7GJ9799SsFzTiq5a1ML",
"blockchain-id": "JjDfmxM3hAEX3VuaKH4PpQskhrvp2pzGTgYLpDwinMzFeHJYA",
"vm": "evm",
"api-node-host": "127.0.0.1",
"api-node-port": 9650,
"encrypt-connection": false,
"account-private-key": "<ACCOUNT_PRIVATE_KEY>"
}
]
}
```

The following values need to be populated:

<!-- vale off -->

- `<C_CHAIN_BLOCKCHAIN_ID>`: The blockchain ID of the C-Chain. This can be retrieved using [platform.getBlockchains](https://docs.avax.network/reference/avalanchego/p-chain/api#platformgetblockchains) and looking for the blockchain with alias `C`.
- `<TELEPORTER_CONTRACT_ADDRESS>`: The address of the Teleporter contract on the source and destination chains. This is the same address that Teleporter was deployed to in [Deploy Teleporter](#deploy-teleporter).
- `<REWARD_ADDRESS>`: The address that the relayer will use to collect rewards for delivering messages. This can be any address.
- `<ACCOUNT_PRIVATE_KEY>`: The private key of the account that will be used to sign transactions on the source and destination chains. This account must have enough funds to pay for transaction fees on both chains.

<!-- vale on -->

The relayer is now configured to relay messages between the C-Chain and Subnet A. Subnet B can be added as well by extending the `source-subnets` and `destination-subnets` arrays with the appropriate values.

##### Run the Relayer

To run the relayer, we can either build the application from source, or run using a published [Docker image](https://hub.docker.com/r/avaplatform/awm-relayer/tags). For the following examples, assume we've written the relayer configuration to `~/config/config.json` on the host machine.

To run the relayer built from source:

```bash
# Clone the repository
git clone [email protected]:ava-labs/awm-relayer.git

# Build the application
./scripts/build.sh

# Run the relayer
./build/awm-relayer --config-file ~/config/config.json
```

To run the relayer from the Docker image:

```bash
# Pull the image
docker pull avaplatform/awm-relayer:latest

# Run the relayer
docker run --env CONFIG_FILE=/config/config.json -v ~/config:/config avaplatform/awm-relayer:latest
```

<!-- vale off -->

#### Interact with Teleporter

With the Warp-enabled devnet deployed, Teleporter deployed on each of the chains, and an AWM Relayer instance running, the Teleporter development environment is ready to go!
A good place to start is to explore the [example applications built on top of Teleporter](https://github.com/ava-labs/teleporter/blob/main/contracts/src/CrossChainApplications/README.md) included in the Teleporter repository. These dApps abstract away much of Warp and Teleporter from the user, and demonstrate various cross-chain messaging use cases.

See the [getting started guide](https://github.com/ava-labs/teleporter/blob/main/contracts/src/CrossChainApplications/GETTING_STARTED.md) for instructions on how to authoer a cross-chain dApp using Teleporter.

An [example script](https://github.com/ava-labs/teleporter/blob/main/scripts/local/examples/basic_send_receive.sh) demonstrates how to interact with Teleporter to send a message from one Subnet to another. Note that this script is intended to be used with a [local network running in Docker](https://github.com/ava-labs/teleporter/blob/main/README.md#run-a-local-testnet-in-docker), and will need to be adapted to use the correct values for the devnet Subnet IDs, but should serve as a good reference.

<!-- vale on -->
Loading