Endless
  • 🚀README
  • Discovery
    • 🚀Endless Web3 Genesis Cloud
    • 💎Business Model
    • 🎯Vision
    • ✈️Roadmap
    • 🪙Economics
    • 👤Team
      • Yu Xiong
      • Amit Kumar Jaiswal
      • Ned
      • 0xfun
      • Scott Trowbridge
      • Neeraj Sharma LLB
      • Amjad Suleman
      • Binu Paul
      • Eduard Romulus GOEAN
    • ❤️Developer Community
  • Endless Chain
    • Tech Docs
      • Account Address Format
      • Endless Account
      • Endless Coin(EDS)
      • Sponsored Transaction
      • On-Chain Multisig
      • Randomness
      • Safety Transaction
      • Token Locking & Distribution
    • Start
      • Learn about Endless
        • Accounts
        • Resources
        • Events
        • Transactions and States
        • Gas and Storage Fees
        • Computing Transaction Gas
        • Blocks
        • Staking
          • Delegated Staking
        • Governance
        • Endless Blockchain Deep Dive
          • Validator Nodes Overview
          • Fullnodes Overview
          • Node Networks and Synchronization
        • Move - A Web3 Language and Runtime
      • Explore Endless
      • Latest Endless Releases
      • Networks
    • Build
      • Tutorials
        • Your First Transaction
        • Your First Fungible Asset
        • Your First NFT
        • Your First Move Module
        • Your First Multisig
      • Learn the Move Language
        • The Move Book
          • Getting Started
            • Introduction
            • Modules and Scripts
          • Primitive Types
            • Move Tutorial
            • Integers
            • Bool
            • Address
            • Vector
            • Signer
            • References
            • Tuples and Unit
          • Basic Concepts
            • Local Variables and Scope
            • Equality
            • Abort and Assert
            • Conditionals
            • While, For, and Loop
            • Functions
            • Structs and Resources
            • Constants
            • Generics
            • Abilities
            • Uses and Aliases
            • Friends
            • Packages
            • Package Upgrades
            • Unit Tests
          • Global Storage
            • Global Storage - Structure
            • Global Storage - Operators
          • Reference
            • Libraries
            • Move Coding Conventions
        • Advanced Move Guides
          • Objects
            • Creating Objects
            • Configuring objects
            • Using objects
          • Move Scripts
            • Writing Move Scripts
            • Compiling Move Scripts
            • Running Move Scripts
            • Move Scripts Tutorial
          • Resource Accounts
          • Modules on Endless
          • Cryptography
          • Gas Profiling
          • Security
      • Endless Standards
        • Object
        • Endless Fungible Asset Standard
        • Endless Digital Asset Standard
        • Endless Wallet Standard
      • Endless APIs
        • Fullnode Rest API
        • Indexer Restful API
          • Indexer Installation
        • GRPC Transaction Stream
          • Running Locally
          • Custom Processors
            • End-to-End Tutorial
            • Parsing Transactions
          • Self-Hosted Transaction Stream Service
      • Endless SDKs
        • TypeScript SDK
          • Account
          • SDK Configuration
          • Fetch data from chain
          • Transaction Builder
          • HTTP Client
          • Move Types
          • Testing
          • Typescript
        • Rust SDK
        • Go SDK
      • Endless CLI
        • Install the Endless CLI
          • Install On Mac
          • Install On Alibaba Cloud
          • Install On Linux
          • Install On Windows
        • CLI Configuration
        • Use Endless CLI
          • Working With Move Contracts
            • Arguments in JSON Tutorial
          • Trying Things On-Chain
            • Look Up On-Chain Account Info
            • Create Test Accounts
          • Running A Local Network
            • Running a Public Network
          • Managing a Network Node
      • Integrate with Endless
        • Endless Token Overview
        • Application Integration Guide
      • Endless VSCode extension
      • Advanced Builder Guides
        • Develop Locally
          • Running a Local Network
          • Run a Localnet with Validator
    • Nodes
      • Learn about Nodes
      • Run a Validator and VFN
        • Node Requirements
        • Deploy Nodes
          • Using Docker
          • Using AWS
          • Using Azure
          • Using GCP
        • Connect Nodes
          • Connect to a Network
        • Verify Nodes
          • Node Health
          • Validator Leaderboard
      • Run a Public Fullnode
        • PFN Requirements
        • Deploy a PFN
          • Using Pre-compiled Binary
          • Using Docker
          • Using GCP 🚧 (under_construction)
        • Verify a PFN
        • Modify a PFN
          • Upgrade your PFN
          • Generate a PFN Identity
          • Customize PFN Networks
      • Bootstrap a Node
        • Bootstrap from a Snapshot
        • Bootstrap from a Backup
      • Configure a Node
        • State Synchronization
        • Data Pruning
        • Telemetry
        • Locating Node Files
          • Files For Mainnet
          • Files For Testnet
          • Files For Devnet
      • Monitor a Node
        • Node Inspection Service
        • Important Node Metrics
        • Node Health Checker
    • Reference
      • Endless Error Codes
      • Move Reference Documentation
      • Endless Glossary
    • FAQs
  • Endless Bridge
    • Intro to Endless Bridge
    • How to use bridge
    • Liquidity Management
    • Faucet
    • Developer Integration
      • Contract Integration
        • Message Contract
        • Execute Contract
      • Server-Side Integration
        • Message Sender
        • Example of Message Listener Service (Rust)
        • Example of Token Cross-Chain (JS)
  • Endless Wallet
    • User Guide
    • Basic Tutorial
    • FAQs
    • MultiAccount
    • SDK
      • Functions
      • Events
  • GameFi
    • Intro
    • GameFi & Endless
  • Endless Modules
    • Stacks
    • Storage
    • Module List
  • Endless Ecosystem
    • Intro
    • Show Cases
    • App Demo
  • Whitepaper
  • Endless SCAN
    • User Guide
  • MULTI-SIGNATURE
    • Multi-Signature User Guide
  • Regulations
    • Privacy Policy
    • Terms of Service
    • Funding Terms - Disclaimer
Powered by GitBook
On this page
  • 1. Send Message Contract Interface
  • 2. Consumer message contract interface
Export as PDF
  1. Endless Bridge
  2. Developer Integration
  3. Contract Integration

Message Contract

In a cross-chain bridge, the message contract (Messager) plays a very important role. It is mainly responsible for encoding, decoding, verifying, and sending cross-chain messages. Developers only need to focus on sending and consuming messages; other aspects such as replay protection and message authenticity verification are all ensured by the message contract.

1. Send Message Contract Interface

1.1. In the Endless chain, the Message sending interface is defined as follows:

public fun send_message_v2(
        sender: &signer,
        executor: &signer,
        excutor_account: &address,
        mtype: u8,
        to_chain: vector<u8>,
        to_addr: vector<u8>,
        mbody: vector<u8>,
        fee: u128
    )

1.1.1. Function Description

The send_message function is used to send a cross-chain message within a Move contract. This function allows the user (sender) to send a message to a specified target chain and address through an executor (executor).

1.1.2. Parameter Description

  1. sender: &signer - a reference to the signature of the sender of the message, used to verify the sender's identity and permissions and to pay gas fees.

  2. executor: &signer - a reference to the signature of the executor, used to perform additional permission checks.

  3. excutor_account: &address -the account address of the executor, used to perform additional permission checks.

  4. mtype: u8 - the message type, represented as an 8-bit unsigned integer.

  5. to_chain: vector<u8> - the identifier of the target chain, represented as a byte vector.

  6. to_addr: vector<u8> - the target address, represented as a byte vector.

  7. mbody: vector<u8> -the message body, containing the actual data to be sent, represented as a byte vector.

  8. fee: u128 - the fee required to send the message, represented as a 128-bit unsigned integer.

1.2. The messages and ABI sent on the sepolia, bsc, and nile chains are as follows:

function emit_msg(
    uint8 msg_type,
    Types.Chain memory to_chain,
    bytes32 receiver,
    bytes memory body_message,
    uint128 upload_gas_fee
) public payable
​
{
    "type": "function",
    "name": "emit_msg",
    "inputs": [
      {
        "name": "msg_type",
        "type": "uint8",
        "internalType": "uint8"
      },
      {
        "name": "to_chain",
        "type": "tuple",
        "internalType": "struct Types.Chain",
        "components": [
          {
            "name": "chain_type",
            "type": "uint8",
            "internalType": "uint8"
          },
          {
            "name": "chain_id",
            "type": "uint64",
            "internalType": "uint64"
          }
        ]
      },
      {
        "name": "receiver",
        "type": "bytes32",
        "internalType": "bytes32"
      },
      {
        "name": "body_message",
        "type": "bytes",
        "internalType": "bytes"
      },
      {
        "name": "upload_gas_fee",
        "type": "uint128",
        "internalType": "uint128"
      }
    ],
    "outputs": [],
    "stateMutability": "payable"
  }

1.2.1. Parameter Description

  1. msg_type:message type

  2. to_chain:target chain information

  3. receiver:receiver address (target chain execution contract address)

  4. body_message:message body (defined by the developer)

  5. upload_gas_fee:target chain gas fee (can be estimated before cross-chain)

1.3. The method definition and IDL for sending messages on the solana chain are as follows:

pub fn send_message(
    ctx: Context<SendToOtherChain>,
    to_chain: Chain,
    to_addr: [u8; 32],
    mbody: Vec<u8>,
    mtype: u8,
    upload_fee: u64,
) -> Result<()>
{
      "name": "send_message",
      "discriminator": [
        57,
        40,
        34,
        178,
        189,
        10,
        65,
        26
      ],
      "accounts": [
        {
          "name": "to_chain_nonce_account",
          "writable": true,
          "pda": {
            "seeds": [
              {
                "kind": "arg",
                "path": "to_chain"
              },
              {
                "kind": "const",
                "value": [
                  116,
                  111,
                  78,
                  111,
                  110,
                  99,
                  101
                ]
              }
            ]
          }
        },
        {
          "name": "sender",
          "writable": true,
          "signer": true
        },
        {
          "name": "message_fee",
          "writable": true,
          "pda": {
            "seeds": [
              {
                "kind": "const",
                "value": [
                  118,
                  97,
                  117,
                  108,
                  116,
                  70,
                  101,
                  101
                ]
              }
            ]
          }
        },
        {
          "name": "bridge_config",
          "pda": {
            "seeds": [
              {
                "kind": "const",
                "value": [
                  103,
                  108,
                  111,
                  98,
                  97,
                  108
                ]
              }
            ]
          }
        },
        {
          "name": "caller_auth_pda",
          "signer": true,
          "pda": {
            "seeds": [
              {
                "kind": "const",
                "value": [
                  98,
                  114,
                  105,
                  100,
                  103,
                  101
                ]
              }
            ],
            "program": {
              "kind": "account",
              "path": "caller_program"
            }
          }
        },
        {
          "name": "caller_program"
        },
        {
          "name": "system_program",
          "address": "11111111111111111111111111111111"
        }
      ],
      "args": [
        {
          "name": "to_chain",
          "type": {
            "defined": {
              "name": "Chain"
            }
          }
        },
        {
          "name": "to_addr",
          "type": {
            "array": [
              "u8",
              32
            ]
          }
        },
        {
          "name": "mbody",
          "type": "bytes"
        },
        {
          "name": "mtype",
          "type": "u8"
        },
        {
          "name": "upload_fee",
          "type": "u64"
        }
      ]
    }

1.3.1. Parameter Description

  1. ctx: Context<SendToOtherChain> Context object, containing all information related to the current transaction, including the status and permissions of the account. This parameter is used to ensure that the function is executed in the correct context.

  2. to_chain: Chain Enumeration type of the target chain, specifying the chain to which the message is to be sent. It can be different blockchain networks, such as Ethereum, Binance Smart Chain, etc.

  3. to_addr: [u8; 32] Byte array of the target address, with a length of 32 bytes. This parameter is used to specify the receiving address of the message.

  4. mbody: Vec<u8> Byte vector of the message body, containing the actual data to be sent. It can be any type of data, such as transaction information, instructions, etc.

  5. mtype: u8 Byte of the message type, indicating the classification or format of the message. It can be used to distinguish different types of messages, such as notifications, instructions, etc.

  6. upload_fee: u64 Unsigned 64-bit integer of the upload fee, indicating the fee required to send the message. This parameter is used to ensure that the sender has enough balance when sending the message.

2. Consumer message contract interface

2.1. In the Endless chain, the consumption message interface is defined as follows:

public fun confirm_message(
        executor: &signer,
        multisig: vector<u8>,
        accum_pk: vector<PublicKeyWithPoP>,
        msg_header: vector<u8>,
        msg_body: vector<u8>
    )

2.1.1. Function Description

confirm_message is a public function used to confirm a message in a multisignature contract. The primary purpose of this function is to ensure that only authorized executors can confirm specific messages, thereby enhancing the security and reliability of the contract.

2.1.2. Parameter Description

  1. executor:A reference to the signer's account executing the function, representing the account authorized to confirm the message.

  2. multisig:The address of the multisignature contract, indicating the contract where the message will be confirmed.

  3. accum_pk:The aggregated public key, representing the cumulative public key used in the multisignature verification process.

  4. msg_header:The message header, containing metadata about the message.

  5. msg_body:The message body, containing the actual content or payload of the message.

2.2. Consumption of Messages on Sepolia, BSC, and Nile Chains — Definition and ABI:

function consume_bridge_msg(
        Types.Message memory messageDec,
        bytes[] memory signature
    ) public returns (bool)
​
{
    "type": "function",
    "name": "consume_bridge_msg",
    "inputs": [
      {
        "name": "messageDec",
        "type": "tuple",
        "internalType": "struct Types.Message",
        "components": [
          {
            "name": "msg_header",
            "type": "tuple",
            "internalType": "struct Types.MessageHeader",
            "components": [
              {
                "name": "msg_type",
                "type": "uint8",
                "internalType": "uint8"
              },
              {
                "name": "nonce",
                "type": "uint64",
                "internalType": "uint64"
              },
              {
                "name": "from_chain",
                "type": "tuple",
                "internalType": "struct Types.Chain",
                "components": [
                  {
                    "name": "chain_type",
                    "type": "uint8",
                    "internalType": "uint8"
                  },
                  {
                    "name": "chain_id",
                    "type": "uint64",
                    "internalType": "uint64"
                  }
                ]
              },
              {
                "name": "sender",
                "type": "bytes32",
                "internalType": "bytes32"
              },
              {
                "name": "to_chain",
                "type": "tuple",
                "internalType": "struct Types.Chain",
                "components": [
                  {
                    "name": "chain_type",
                    "type": "uint8",
                    "internalType": "uint8"
                  },
                  {
                    "name": "chain_id",
                    "type": "uint64",
                    "internalType": "uint64"
                  }
                ]
              },
              {
                "name": "receiver",
                "type": "bytes32",
                "internalType": "bytes32"
              },
              {
                "name": "upload_gas_fee",
                "type": "uint128",
                "internalType": "uint128"
              }
            ]
          },
          {
            "name": "msg_body",
            "type": "bytes",
            "internalType": "bytes"
          }
        ]
      },
      {
        "name": "signature",
        "type": "bytes[]",
        "internalType": "bytes[]"
      }
    ],
    "outputs": [
      {
        "name": "",
        "type": "bool",
        "internalType": "bool"
      }
    ],
    "stateMutability": "nonpayable"
  }

2.2.1. Parameter Description

  1. messageDec:Type is Types.Message,containing the following structure:

    • msg_header:Message header, type is Types.MessageHeader

    • msg_type:Message type(uint8)

    • nonce:Message sequence number(uint64)

    • from_chain:Source chain information(Types.Chain)

      1. chain_type:Chain type(uint8)

      2. chain_id:Chain ID(uint64)

    • sender:Sender address(bytes32)

    • to_chain:Target chain information(Types.Chain)

      1. chain_type:Chain type(uint8)

      2. chain_id:Chain ID(uint64)

    • receiver:Receiver address(bytes32)

    • upload_gas_fee:pload gas fee(uint128)

    • msg_body:Message body(bytes)

  2. signature:Message signature array(bytes[])

2.3.The definition and IDL of the message consumption method on the Solana chain are as follows:

pub fn confirm_message(
    ctx: Context<ConfirmFromOtherChain>,
    msg_header: MsgHeader,
    msg_body: Vec<u8>,
    _accum_pk: Vec<u8>,
    signatures: Vec<[u8; 65]>,
) -> Result<()>
{
      "name": "confirm_message",
      "discriminator": [
        215,
        137,
        81,
        162,
        147,
        50,
        198,
        231
      ],
      "accounts": [
        {
          "name": "from_chain_nonce_account",
          "writable": true,
          "pda": {
            "seeds": [
              {
                "kind": "arg",
                "path": "msg_header.from_chain"
              },
              {
                "kind": "const",
                "value": [
                  102,
                  114,
                  111,
                  109,
                  78,
                  111,
                  110,
                  99,
                  101
                ]
              }
            ]
          }
        },
        {
          "name": "bridge_config",
          "pda": {
            "seeds": [
              {
                "kind": "const",
                "value": [
                  103,
                  108,
                  111,
                  98,
                  97,
                  108
                ]
              }
            ]
          }
        },
        {
          "name": "user",
          "writable": true,
          "signer": true
        },
        {
          "name": "system_program",
          "address": "11111111111111111111111111111111"
        }
      ],
      "args": [
        {
          "name": "msg_header",
          "type": {
            "defined": {
              "name": "MsgHeader"
            }
          }
        },
        {
          "name": "msg_body",
          "type": "bytes"
        },
        {
          "name": "accum_pk",
          "type": "bytes"
        },
        {
          "name": "signatures",
          "type": {
            "vec": {
              "array": [
                "u8",
                65
              ]
            }
          }
        }
      ]
    }

2.3.1. Parameter Description

  1. ctx: Context<ConfirmFromOtherChain> Context object, containing all information related to the current transaction, including the status and permissions of the account. This parameter is used to ensure that the function is executed in the correct context.

  2. msg_header: MsgHeader The structure of the message header, containing metadata about the message, such as the sender address, timestamp, message type, etc. This parameter is used to provide basic information about the message.

  3. msg_body: Vec<u8> The byte vector of the message body, containing the actual data to be confirmed. It can be any type of data, such as transaction information, instructions, etc.

  4. _accum_pk: Vec<u8> The byte vector of the accumulated public key, which is usually used to verify the signature of the message. This parameter can contain multiple public keys to ensure the legitimacy of the message.

  5. signatures: Vec<[u8; 65]> The byte array vector of the signature, with a length of 65 bytes. This parameter is used to store the signature of the message to verify the source and integrity of the message.

PreviousContract IntegrationNextExecute Contract

Last updated 9 days ago