If you have any questions or need assistance, please feel free to use our contact form to connect with an expert on our team.
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.
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.
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.
1
Deploy the Ethereum Sepolia contract.
npx hardhat run scripts/deployMessenger.ts --network ethereum_sepolia
2
Deploy the Polygon Amoy contract.
npx hardhat run scripts/deployMessenger.ts --network polygon_amoy
Example Deployment Log
After deploying the contract using the Hardhat run command, a log will confirm the successful deployment.
Using network: mantle_sepolia
ChainID mantle_sepolia: 5003
Signer: 0xB3B029c49EA026BaCc0901a071Cf8Fd0D5Bde9AF
Signer native balance: 98.477296506288888787
Deploying MessengerProtocol
With args: 0xB3B029c49EA026BaCc0901a071Cf8Fd0D5Bde9AF,0x5C4eCE5c0D29f7D6c47abd2341421d9f9f7c4FFB
MessengerProtocol deployed to: 0xf66e086e0032D3ba517469E6217BeeF0aB44b728
MessengerProtocol implementation deployed to: 0x49b6B710b0F9ACC20225aE54D9E10f9B3DD76ed7
Data successfully saved to ./addresses/mantle_sepolia/MessengerProtocol.json
The MessengerProtocol file will also be generated, containing the addresses mentioned in the log. You can find it in the following directory:
The deployment address is required for sending messages using Hardhat in the next section of this guide, so it's recommended to note or save the MessengerProtocol deployment address.
Sending and Receiving Messages
In this section, we'll take a look at sending and receiving messages.
Sending Messages
The Chain ID specifies that the message is being sent to the Polygon Amoy chain. For a complete list of chain IDs, you can refer to ChainList. Make sure to check the "Include Testnets" box to show testnet chains.
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
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.
Last message from address <your sender wallet address> is: "hello"
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.