Advanced guides
Sending Data
Iris Protocol does support sending Data from the sender (Channel) to the registered listeners
Sending Data
To send data just simply prepare the data to send it in your Channel (sender)
import { Channel } from "@aurelianoa/iris-channels/contracts/channel/Channel.sol";
contract MyChannel is Channel {
function foo() {
/// your logic
/// broadcast the message
address networkAddress = "0x...."
string memory myEventIndex = "myEventIndex"
bytes memory data = abi.encode("my data");
broadcast(networkAddress, myEventIndex, data);
}
}
Receiving your data
In yopur listeners just simply access the data on the onReceivedMessage
import { Listener } from "@aurelianoa/iris-channels/contracts/listener/Listener.sol";
contract MyListener is Listener {
/// Override the onReceivedMessage function
function onReceivedMessage(address sender, string memory eventIndex, bytes memory data) internal override {
if(isChannelAvailable(sender) && compareIndex(eventIndex, "myEventIndex")) {
/// access the data from the message
(_string) = abi.decode(data);
/// your logic here
}
}
}
Important!
Iris Protocol does not process or check the intergrity of the data passed. Every Channel should know the format and the data it self being sent trhough their messages.
Access the last message
The Listener.sol
does store the last message sent from a specific channel and to access it simply call lastMessages[channel]
mapping.