bitoftrade docs
  • 👋Welcome to the bitoftrade docs!
  • 🤖bitoftrade intro
  • 📨Contact Us
  • For traders
    • ✅Cross-Chain Swaps
      • How it works
        • Liquidity providers & validators
        • Security
      • User Guide
    • 🔄Trading platform
      • Features
        • Leverage trading
        • Token swaps
        • Buy crypto with fiat
        • Market screener
      • Quick start
        • How do I swap tokens on bitoftrade?
        • How to buy crypto with fiat?
        • How to trade with leverage on bitoftrade?
        • How to use the Markets page?
        • How to place limit order?
      • Fees
      • FAQ
  • For businesses
    • 🛒AllPay Widget
      • Use cases
        • Token Owners
        • Personal Exchange
        • Creators
        • GameFi, Metaverse
        • Crypto Payments (soon)
      • Quick start
        • Customization Panel
        • Swap and Sale Integration
        • NFT Widget Integration
          • NFT Listing
          • Code Integration
      • FAQ
  • For developers
    • 🔀Cross-Chain Messaging Protocol
      • How it works
        • Signer Service
          • Event Hash
          • Signer interface
        • Signers Registry Contract
      • Quick start
        • Emit event
        • Verify event
        • Receive event
      • Smart contracts
      • Advanced
        • Threshold Signature
        • Hosted TSS signer
      • Security
      • FAQ
  • Guides
    • 📚General
      • How to download and connect MetaMask for desktop?
      • How do I download and connect MetaMask for mobile?
      • How do I import ERC20 tokens to MetaMask?
      • How do I manage my funds in a volatile market?
      • How to invest in cryptocurrency
    • ⛓️Polygon
      • How to swap on the Polygon network
      • How to bridge my Polygon tokens
      • How to add Polygon to my MetaMask
    • ⛓️Binance Smart Chain
      • How to bridge my BSC tokens
      • How to swap on the BSC network
      • How to add BSC to my MetaMask
    • ⛓️Fantom
      • How to bridge my Fantom tokens
      • How to swap on the Fantom network
      • How to add Fantom to my MetaMask
    • ⛓️Avalanche
      • How to bridge my Avalanche tokens
      • How to swap on the Avalanche network
      • How to add Avalanche to my MetaMask
Powered by GitBook
On this page
  1. For developers
  2. Cross-Chain Messaging Protocol
  3. Quick start

Receive event

PreviousVerify eventNextSmart contracts

Last updated 2 years ago

After the event was made on the SRC chain and verified by the Signer, the last step of the protocol is receiving that event on the DEST chain.

We can trust that event happened on the SRC chain if proof of this event was made by the correct signer. is responsible for this validation.

In our example, to receive the event on the DEST chain, we have to call receiveMyMessage method on the MsgReceiver.

pragma solidity ^0.8.0;

contract MsgReceiver {
    event MyMessageReceived(string message);

    ISignersRegistry signersRegistry;

    constructor(address _signersRegistry) {
        signersRegistry = ISignersRegistry(_signersRegistry);
    }

    function receiveMyMessage(
        bytes calldata _signature,
        string memory _message,
        address _msgSender,
        uint256 _chainId,
        bytes calldata _transactionHash
    ) external {
        bytes32 eventHash = keccak256(abi.encodePacked("MyMessage", _chainId, _msgSender, _transactionHash, _message));
        address signer = eventHash.recover(_signature);
        bool isSignerWhitelisted = signersRegistry.isPublicWhitelisted(signer);
        
        require(isSignerWhitelisted, "Signer is not whitelisted");

        emit MyMessageReceived(_message);
    }
}

After the signature maker was recovered, signersRegistry checked if the signer was whitelisted. That's why all public and private Signers have to be whitelisted before producing any event proofs.

If signersRegistry approved that the signer was whitelisted, it means that we can trust this event. Therefore, do any steps required by your dApp.

In our example, it just emits the MyMessageReceived event.

You can check, that was made the same way as Signer did while making the signature. It's very important to recover the signature with the same eventHash.

See the example of the receiveMyMessage transaction on the .

🔀
Signers Registry smart contract
eventHash
explorer