logoAcademy

Two-Way Messaging Configuration

Learn how to configure a relayer for multiple L1s

Important: The relayer needs funds on both L1s to deliver messages.

Two-Way Messaging Configuration

In this section, you’ll learn how to configure a relayer to support two-way messaging between multiple Layer 1 blockchains (L1s). By extending your existing configuration, you can enable the relayer to handle communication in both directions, eliminating the need to run multiple relayers.

Accessing the Relayer Configuration File

The relayer configuration is supplied as a JSON file. To open the configuration file automatically created by the Avalanche-CLI, run the following command:

code ~/.avalanche-cli/runs/network_xxxx_xxxx/awm-relayer-config.json 
Replace xxxx_xxxx with the name automatically assigned to your local deployment.

Alternatively, navigate to the directory ~/.avalanche-cli/runs/ and locate the relayer configuration file for your network.

Understanding the Existing Configuration

Assuming you have a configuration as described in the Relayer Configuration section, your current configuration should look similar to the following:

{
  "p-chain-api": {
    "base-url": "http://127.0.0.1:9650",
    "query-parameters": {},
    "http-headers": null
  },
  "info-api": {
    "base-url": "http://127.0.0.1:9650",
    "query-parameters": {},
    "http-headers": null
  },  
  "source-blockchains": [
    {
      "subnet-id": "11111111111111111111111111111111LpoYY",
      "blockchain-id": "epm5fG6Pn1Y5rBHdTe36aZYeLqpXugreyHLZB5dV81rVTs7Ku",
      "vm": "evm",
      "rpc-endpoint": {
        "base-url": "http://127.0.0.1:9650/ext/bc/<blockchain-id>/rpc",
        "query-parameters": null,
        "http-headers": null
      },
      "ws-endpoint": {
        "base-url": "ws://127.0.0.1:9650/ext/bc/<blockchain-id>/ws",
        "query-parameters": null,
        "http-headers": null
      },
      "message-contracts": {
        "0x0000000000000000000000000000000000000000": {
          "message-format": "off-chain-registry",
          "settings": {
            "teleporter-registry-address": "0x<registry-address>"
          }
        },
        "0x<contract-address>": {
          "message-format": "teleporter",
          "settings": {
            "reward-address": "0x<reward-address>"
          }
        }
      }
    }
  ],
  "destination-blockchains": [
    {
      "subnet-id": "11111111111111111111111111111111LpoYY",
      "blockchain-id": "epm5fG6Pn1Y5rBHdTe36aZYeLqpXugreyHLZB5dV81rVTs7Ku",
      "vm": "evm",
      "rpc-endpoint": {
        "base-url": "http://127.0.0.1:9650/ext/bc/<blockchain-id>/rpc",
        "query-parameters": null,
        "http-headers": null
      },
      "kms-key-id": "",
      "kms-aws-region": "",
      "account-private-key": "<your-private-key>"
    }
  ]
}

Updating the Configuration for Two-Way Communication

To enable two-way communication between L1s, you need to extend the configuration to include both blockchains in the source-blockchains and destination-blockchains arrays.

Updated Configuration:

{
  "p-chain-api": {
    "base-url": "http://127.0.0.1:9650",
    "query-parameters": {},
    "http-headers": null
  },
  "info-api": {
    "base-url": "http://127.0.0.1:9650",
    "query-parameters": {},
    "http-headers": null
  },
  "source-blockchains": [
    {
      "subnet-id": "<blockchain-id-A>",
      "blockchain-id": "<blockchain-id-A>",
      "vm": "evm",
      "rpc-endpoint": {
        "base-url": "http://127.0.0.1:9650/ext/bc/<blockchain-id-A>/rpc",
        "query-parameters": null,
        "http-headers": null
      },
      "ws-endpoint": {
        "base-url": "ws://127.0.0.1:9650/ext/bc/<blockchain-id-A>/ws",
        "query-parameters": null,
        "http-headers": null
      },
      "message-contracts": {
        "0x0000000000000000000000000000000000000000": {
          "message-format": "off-chain-registry",
          "settings": {
            "teleporter-registry-address": "0x<registry-address-A>"
          }
        },
        "0x<contract-address-A>": {
          "message-format": "teleporter",
          "settings": {
            "reward-address": "0x<reward-address-A>"
          }
        }
      }
    },
    {
      "subnet-id": "<blockchain-id-B>",
      "blockchain-id": "<blockchain-id-B>",
      "vm": "evm",
      "rpc-endpoint": {
        "base-url": "http://127.0.0.1:9650/ext/bc/<blockchain-id-B>/rpc",
        "query-parameters": null,
        "http-headers": null
      },
      "ws-endpoint": {
        "base-url": "ws://127.0.0.1:9650/ext/bc/<blockchain-id-B>/ws",
        "query-parameters": null,
        "http-headers": null
      },
      "message-contracts": {
        "0x0000000000000000000000000000000000000000": {
          "message-format": "off-chain-registry",
          "settings": {
            "teleporter-registry-address": "0x<registry-address-B>"
          }
        },
        "0x<contract-address-B>": {
          "message-format": "teleporter",
          "settings": {
            "reward-address": "0x<reward-address-B>"
          }
        }
      }
    }
  ],
  "destination-blockchains": [
    {
      "subnet-id": "<blockchain-id-A>",
      "blockchain-id": "<blockchain-id-A>",
      "vm": "evm",
      "rpc-endpoint": {
        "base-url": "http://127.0.0.1:9650/ext/bc/<blockchain-id-A>/rpc",
        "query-parameters": null,
        "http-headers": null
      },
      "kms-key-id": "",
      "kms-aws-region": "",
      "account-private-key": "<your-private-key-A>"
    },
    {
      "subnet-id": "<blockchain-id-B>",
      "blockchain-id": "<blockchain-id-B>",
      "vm": "evm",
      "rpc-endpoint": {
        "base-url": "http://127.0.0.1:9650/ext/bc/<blockchain-id-B>/rpc",
        "query-parameters": null,
        "http-headers": null
      },
      "kms-key-id": "",
      "kms-aws-region": "",
      "account-private-key": "<your-private-key-B>"
    }
  ]
}

Explanation of Changes

By adding both blockchains to the source-blockchains and destination-blockchains arrays, the relayer is configured to:

  • Listen for messages on both blockchains.
  • Relay messages to the opposite blockchain.

This setup enables two-way communication between the blockchains using a single relayer instance.

Important Considerations

  • Private Keys: Ensure that the account-private-key field contains the private key for the respective blockchain. This key is used to sign transactions when relaying messages.
  • Funding: The relaxyer account must have sufficient funds on both L1s to cover transaction fees.

Next Steps

After updating the configuration file:

  • Save the changes.
  • Restart the relayer to apply the new configuration.
  • Test the two-way communication by sending messages between the blockchains.

On this page