Simple Abstract Messenger Example
An effective implementation of blockchain interoperability is sending cross-chain messages. Traditionally, without UIP, this would be a challenging task. However, UIP makes this an easy and safe process. This guide walks you through building a simple dApp that utilises UIP to send cross-chain text messages with EVM smart contracts.
For this guide, we won't need to worry about fees as we will deploy two smart contracts on the testnet — one on the Ethereum Sepolia testnet and the other on the Polygon Amoy network.
Prerequisites
Before you begin, you'll need to enure you're familiar with the concepts and have the tools we'll be using for this guide. If you're unsure about anything, we recommend reading more via the provided links.
We will be using the following native tokens:
Click on the respective token to be taken to a public faucet and complete the steps to acquire the necessary funds in your wallet.
Environment Setup
To begin with, let's setup the working environment. We'll initialize the Hardhat project and configure the environment file with the necessary information.
Clone the example project from GitHub.
git clone https://github.com/Entangle-Protocol/UIP-examples.git
Change your directory to the project folder.
cd UIP-examples/other/Messenger/EVM
Install the dependencies.
npm install
You can setup your wallet details using a mnemonic phrase (default) or a private key. Below we describe the configuration process for each type.
Since the same wallet can be used across multiple networks, there's no need to add separate wallets. However, if you're alternating between working on Testnet and Mainnet you have to make sure you update the .env file to specify wallet details for both.
Ensure spaces are included between words for your mnemonic phrase.
The mnemonic phrase is configured in the .env file and is used by default. You may need to create this file in your root directory if it's missing.
Please specify details for Testnet and Mainnet individually as described below.
TESTNET_MNEMONIC = ""
MAINNET_MNEMONIC = ""
Deploying Contracts
Once the environment has been successfully setup we can begin deploying contracts. Before beginning, double check to make sure your environment variables are all correct.
Hardhat makes it easy to deploy contracts, simply run the commands below.
Deploy the Ethereum Sepolia contract.
npx hardhat run scripts/deployMessenger.ts --network ethereum_sepolia
Deploy the Polygon Amoy contract.
npx hardhat run scripts/deployMessenger.ts --network polygon_amoy
Sending and Receiving Messages
In this section, we'll take a look at sending and receiving messages.
Sending Messages
To send a message from the source chain (Ethereum Sepolia) to the destination chain (Polygon Amoy) copy the below command, update the address of the deployed contract on Polygon Amoy and run it.
npx hardhat sendMessage --destchainid 80002 --destaddress <address of deployed contract on polygon amoy> --message "hello" --network ethereum_sepolia
By default, we use our recommended transmitter settings when sending messages. If you are familiar with the customizable message transmission options and prefer manual configuration, your command will include two additional arguments:
npx hardhat sendMessage --destchainid <destination_chain_id> --destaddress <destination_address> --message <message> --finalization <block_finalization_option> --gaslimit <custom_gas_limit> --network <network_name>
Receiving Messages
To read the last message on the destination chain (in this example it's Polygon Amoy) copy the below command, update your sender wallet address and run it.
npx hardhat getLastMessage --sender <your sender wallet address> --network polygon_amoy
Conclusion
In this guide we created a DApp utilising EVM contracts to facilitate in cross-chain text messaging between the Ethereum Sepolia and Polygon Amoy chains.
Last updated
Was this helpful?