Use Registry in a Cross-Chain dApp.
Let's now integrate the registry into a smart contract. Let's go back to the very simple string sending contract from the beginning:
contracts/interchain-messaging/registry/SenderOnCChainWithRegistry.sol pragma solidity ^0.8.18;
import "@teleporter/upgrades/TeleporterRegistry.sol";
import "@teleporter/ITeleporterMessenger.sol";
contract SenderOnCChain {
// The Interchain Messaging registry contract manages different Interchain Messaging contract versions. //
TeleporterRegistry public immutable teleporterRegistry = TeleporterRegistry(0x827364Da64e8f8466c23520d81731e94c8DDe510);
/**
* @dev Sends a message to another chain.
*/
function sendMessage(address destinationAddress, string calldata message) external {
ITeleporterMessenger messenger = teleporterRegistry.getLatestTeleporter();
messenger.sendCrossChainMessage(
TeleporterMessageInput({
// Replace with blockchainID of your Avalanche L1 (see instructions in Readme)
destinationBlockchainID: 0x92756d698399805f0088fc07fc42af47c67e1d38c576667ac6c7031b8df05293,
destinationAddress: destinationAddress,
feeInfo: TeleporterFeeInfo({feeTokenAddress: address(0), amount: 0}),
requiredGasLimit: 100000,
allowedRelayerAddresses: new address[](0),
message: abi.encode(message)
})
);
}
}
Don't forget to replace the destinationBlockchainID with Blockchain ID (HEX) from your Avalanche L1!
The key things to understand:
- We are importing the
ITeleporterRegistry.sol
interface
- We have a variable for the registry address instead of the messenger address
- Before sending the message we get the latest version from the registry