Here’s how you write a contract on Sepolia that dispatches a message using Hashi’s Yaho contract. This message will be relayed to Chiado and trigger the callback.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface IYaho {
function dispatchMessageToAdapters(
uint256 targetChainId,
uint256 threshold,
address targetAddress,
bytes memory data,
address[] memory reporters,
address[] memory adapters
) external;
}
contract SepoliaSender {
IYaho public yaho = IYaho(0x21eAB033C7D2DF6A67AeF6C5Bda9A7F151eB9f52); // Yaho address on Sepolia
uint256 public threshold;
address[] public reporters;
address[] public adapters;
constructor(address _yaho, uint256 _threshold, address[] memory _reporters, address[] memory _adapters) {
threshold = _threshold;
reporters = _reporters;
adapters = _adapters;
}
// Function to send a cross-chain message to Chiado
function sendMessageToChiado(
uint256 targetChainId,
address targetAddress,
string memory _message
) public {
bytes memory data = abi.encode(_message);
yaho.dispatchMessageToAdapters(targetChainId, threshold, targetAddress, data, reporters, adapters);
}
}
Explanation:
The contract interacts with the Yaho contract on Sepolia to dispatch a message to Chiado using dispatchMessageToAdapters.
The sendMessageToChiado function takes the target chain ID(10200 for Chiado), target address (ChiadoReceiver contract on Chiado), and the message to be sent.
The reporters, adapters, and threshold are passed into the Yaho contract for cross-chain message validation and relaying.
Deployment:
Deploy this contract on Sepolia, passing the reporters, adapters, and threshold into the constructor.
A list of reporters and adapters contract can be found in: Oracles
Threshold must equal to expectedThreshold in Receiver contract.