Function Calls

Function Call #1 – Calling The Receivers

    /// @notice function of emitting event Propose for catching by receiverkeepers
    /// @param protocolId protocol id to interact
    /// @param dstChainId dest chain id
    /// @param protocolAddress dest protocol address is bytes32 cause dstChainId may be non-EVM
    /// @param functionSelector dest protocol function id, for EVM is abi func selector, for non-EVM may be any id format
    /// @param params function params for dest protocol function
    function propose(
        bytes32 protocolId,
        uint256 dstChainId,
        bytes calldata protocolAddress,
        bytes functionSelector,
        bytes calldata params
    ) external isAllowedProposer(protocolId) {
        emit Propose(protocolId, nonce++, dstChainId, protocolAddress, functionSelector, params);


import "@entangle_protocol/oracle-sdk/contracts/IProposer.sol";
import "@entangle_protocol/oracle-sdk/contracts/lib/PhotonFunctionSelectorLib.sol";
contract MyContract {
    struct YourMsgStruct {
        string str;
        uint num;

    IProposer endPoint;
    address ethContractAddress;

    function sendProposeOperation() external {
        bytes32 protocolId = bytes32("your-protocol-id");
        uint destChainId = 1; // eth
        bytes memory destContractAddress = abi.encode(ethContractAddress);
        // encode EVM selector as PhotonSelector
        bytes memory selector = PhotonFunctionSelectorLib.encodeEvmSelector(bytes4(keccak256(bytes("receive(bytes)"))));
        YourMsgStruct memory msg = YourMsgStruct("hello world", 9000);
        bytes memory encodedPayload = abi.encode(msg);


The `propose` function is designed to emit a structured event containing details about a proposed interaction with a protocol on possibly another blockchain.

This event can then be caught by Receivers, which may perform further actions such as validating the proposal, executing cross-chain calls, or any other required process as per the system's design.

Function Call #2 – Receive Prompt From End Point

/// @notice Receive function example, always should take 1 arg (bytes)
/// @param data encoded: bytes32 protocolId, uint256 srcChainId, uint256 srcBlockNumber, bytes32[2] srcOpTxId, bytes payload
function receive(bytes calldata data) external onlyRole(SPOTTER) {
    (bytes32 protocolId, uint256 srcChainId, uint256 srcBlockNumber, bytes32[2] memory srcOpTxId, bytes memory payload) = abi.decode(data, (bytes32, uint256, uint256, bytes32[2], bytes));
    YourMsgStruct memory msg = abi.decode(payload, (YourMsgStruct));


This `receiver`function, is designed to be triggered by an End Point contract on a destination blockchain network as part of an operation that has gained consensus approval. This role restriction ensures that only authorized entities can trigger this function, enhancing security.

The function receives a single parameter, `data`, which is a byte array (`bytes calldata`). This array encapsulates multiple pieces of information:

  • protocolId: The identifier of protocol, where this operation was created and approved.

  • srcChainId: The ID of the source blockchain from which the operation originated.

  • srcBlockNumber: The block number on the source blockchain at which the operation was initiated or recorded.

  • srcOpTxId: A unique identifier (transaction ID) for the operation on the source blockchain is represented as srcOpTxId. For blockchains like Solana, the transaction ID format includes two bytes32 words. When the transaction ID from the source is only 32 bytes long, it populates only the srcOpTxId[0] word, while srcOpTxId[1] is set to 0x00. This structure allows for consistent handling of transaction identifiers across different blockchain technologies.

  • payload: Additional data associated with the operation, which can be specific to the operation's context.

The function begins by decoding the `data` parameter to extract the `srcChainId`, `srcBlockNumber`, `srcOpTxId`, and the `payload`. This is done using the `abi.decode` function.

After extracting the basic information, the function further decodes the `payload` to obtain more specific data relevant to the operation.

For Web2 triggers, the srcChainId, srcBlockNumber, and srcOpTxId parameters can contain information about source identifier. This can be beneficial for processing information from various sources differently.

Last updated