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 above command, you will see this log as a result, notifying you of the successful contract deployment.
Note down or save the "MessengerProtocol" address as it will be required in order to send further messages.
Using network: polygon_amoy
ChainID polygon_amoy : 80002
With RPC: https://rpc.ankr.com/polygon_amoy
Signer: 0xB3B029c49EA026BaCc0901a071Cf8Fd0D5Bde9AF
Signer native balance: 0.795489155215821829
Deployment address loaded from
./addresses/polygon_amoy/EndPoint.json
Deploying MessengerProtocol
With args:
0xB3B029c49EA026BaCc0901a071Cf8Fd0D5Bde9AF,0x410dEc5b10a4B1A2eF25De1Fb798339126b7d84b
MessengerProtocol deployed to: 0x14e6578B4a9Ef9D1A2BD24fBbbbf9Ef4A0459EA8
MessengerProtocol implementation deployed to: 0xf69bC40C6C4d25Df0882a45399f5a623Aa7b9783
Data successfully saved to ./addresses/polygon_amoy/MessengerProtocol.json
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.