Rayls Docs

Transfer arbitrary messages

Let's embark on creating our first contract that enables cross-chain interaction via the Rayls Protocol. To accomplish this, we must inherit from the **RaylsApp** abstract contract, which provides a diverse set of methods to facilitate communication.

// SPDX-License-Identifier: MIT
pragma solidity ^ 0.8.20;

import { RaylsApp } from "@rayls/contracts/RaylsApp.sol";

contract HelloWorldContract is RaylsApp {
    public string message;
    constructor(
        address _endpoint
    ) RaylsApp(_endpoint, msg.sender) { }

    function sendMessage(
        address to,
        uint256 toChainId,
        string memory _message
    ) public {
        _raylsSend(
            toChainId,
            to,
            abi.encodeWithSignature("receiveGreetings(string)", _message)
        );

    }

    function receiveGreetings(string memory _message) public{
        _message = message;
    }

    function getMessage() public view returns (string memory){
        return message;
    }
}

To facilitate cross-chain messaging, it's essential to identify the destination Privacy Ledger's chain ID and the address of an equivalent contract deployed there. This setup underscores the protocol's use of Arbitrary Message Communication, wherein interactions are formatted as encoded method calls.

Consequently, any data transferred between Privacy Ledgers is managed via function calls on the destination Privacy Ledger, ensuring a standardized approach to cross-chain communication.