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. Cross-Chain Proposal Contract Interface
  • 2. Cross-Chain Completion Contract Interface
Export as PDF
  1. Endless Bridge
  2. Developer Integration
  3. Contract Integration

Execute Contract

In a cross-chain bridge, the executor contract (Executor) plays a crucial role. The executor contract for token cross-chain mainly provides two core methods for users to call:

  1. bridge_proposal: Cross-Chain Proposal

  2. bridge_finish: Cross-Chain Completion (Optional)

1. Cross-Chain Proposal Contract Interface

1.1. On the Endless chain, the interface for sending a cross-chain proposal is defined as follows:

public entry fun bridge_proposal(
        sender: &signer,
        source_token: address,
        to_chain: vector<u8>,
        to_contract: vector<u8>,
        to_who: vector<u8>,
        all_amount: u128,
        upload_gas_fee: u128
    )
​
public entry fun bridge_proposal_with_extra_data(
        sender: &signer,
        source_token: address,
        to_chain: vector<u8>,
        to_contract: vector<u8>,
        to_who: vector<u8>,
        all_amount: u128,
        upload_gas_fee: u128,
        extra_data: vector<u8>
    )

1.1.1. Parameter Description

  1. sender: &signer - A reference to the signer of the message. Used to verify the sender’s identity and permissions, and to pay the gas fee.

  2. source_token: address - The address of the token to be bridged across chains.

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

  4. to_contract: vector<u8> - The target contract address on the destination chain, represented as a byte vector.

  5. to_who: vector<u8> - The recipient address on the destination chain, represented as a byte vector.

  6. all_amount: u128 - The total amount of tokens to be bridged, represented as an unsigned 128-bit integer.

  7. upload_gas_fee: u128 - The gas fee required to send the message, represented as an unsigned 128-bit integer.

  8. extra_data: vector<u8> - Additional data beyond the basic 128-bit structure, used for extensibility and advanced features. Represented as a byte vector.

1.2. The cross-chain proposal method and ABI on Sepolia, BSC, and Nile networks are as follows:

function bridgeToken(
        bytes32 source_token,
        Types.Chain memory to_chain,
        bytes32 to_who,
        bytes32 receiver,
        uint128 all_amount,
        uint128 upload_gas_fee
    ) public payable
​
function bridgeToken(
        bytes32 source_token,
        Types.Chain memory to_chain,
        bytes32 to_who,
        bytes32 receiver,
        uint128 all_amount,
        uint128 upload_gas_fee,
        bytes memory extra_data
    ) public payable
{
    "type": "function",
    "name": "bridgeToken",
    "inputs": [
      {
        "name": "source_token",
        "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": "to_who",
        "type": "bytes32",
        "internalType": "bytes32"
      },
      {
        "name": "receiver",
        "type": "bytes32",
        "internalType": "bytes32"
      },
      {
        "name": "all_amount",
        "type": "uint128",
        "internalType": "uint128"
      },
      {
        "name": "upload_gas_fee",
        "type": "uint128",
        "internalType": "uint128"
      }
    ],
    "outputs": [],
    "stateMutability": "payable"
  }

1.2.1. Parameter Description

  1. source_token:The token to be bridged across chains.

  2. to_chain:Information about the target chain.

  3. to_who:The recipient address on the target chain.

  4. receiver:The execution contract address on the target chain.

  5. all_amount:The amount of tokens to bridge.

  6. upload_gas_fee:

    • The gas fee required on the target chain (can be estimated before the cross-chain operation).

1.3. Cross-Chain Proposal Method Definition and IDL on Solana Chain

pub fn bridge_proposal(
    ctx: Context<Proposal>,
    to_chain: Chain,
    _to_token: [u8; 32],
    to_who: [u8; 32],
    all_amount: u64,
    upload_gas_fee: u64,
) -> Result<()>
{
      "name": "bridge_proposal",
      "discriminator": [
        158,
        136,
        135,
        169,
        41,
        252,
        48,
        232
      ],
      "accounts": [
        {
          "name": "sender",
          "writable": true,
          "signer": true
        },
        {
          "name": "token_mint",
          "writable": true
        },
        {
          "name": "sender_token",
          "writable": true
        },
        {
          "name": "fund_pool",
          "writable": true
        },
        {
          "name": "pool_account",
          "writable": true
        },
        {
          "name": "bridge_authority",
          "writable": true
        },
        {
          "name": "token_relation"
        },
        {
          "name": "chain_relation"
        },
        {
          "name": "to_chain_nonce_account",
          "writable": true
        },
        {
          "name": "message_fee",
          "writable": true
        },
        {
          "name": "bridge_config"
        },
        {
          "name": "bridge_core_program"
        },
        {
          "name": "program_id"
        },
        {
          "name": "token_program"
        },
        {
          "name": "associated_token_program"
        },
        {
          "name": "system_program"
        }
      ],
      "args": [
        {
          "name": "to_chain",
          "type": {
            "defined": {
              "name": "Chain"
            }
          }
        },
        {
          "name": "to_token",
          "type": {
            "array": [
              "u8",
              32
            ]
          }
        },
        {
          "name": "to_who",
          "type": {
            "array": [
              "u8",
              32
            ]
          }
        },
        {
          "name": "all_amount",
          "type": "u64"
        },
        {
          "name": "upload_gas_fee",
          "type": "u64"
        }
      ]
    }

1.3.1. Parameter Description

  1. ctx: Context<Proposal> The context object containing all information related to the current transaction, including account states and permissions. This parameter ensures that the function executes within the correct context.

  2. to_chain: Chain An enum type representing the destination chain. Specifies which blockchain network the proposal is being sent to (e.g., Ethereum, Binance Smart Chain, etc.).

  3. _to_token: [u8; 32] A 32-byte array representing the target token. This parameter defines the token type to be bridged on the destination chain.

  4. to_who: [u8; 32] A 32-byte array representing the recipient address on the target chain. This specifies the address that will receive the bridged assets.

  5. all_amount: u64 An unsigned 64-bit integer representing the total amount of tokens to bridge. Indicates the number of assets the user intends to transfer.

  6. upload_gas_fee: u64 An unsigned 64-bit integer representing the upload fee. This is the amount the sender must pay to submit the proposal, ensuring they have sufficient balance to proceed.

2. Cross-Chain Completion Contract Interface

2.1. The cross-chain completion interface is defined as follows on the Endless chain:

public entry fun bridge_finish(
        sender: &signer,
        msg_header: vector<u8>,
        msg_body: vector<u8>,
        multisig: vector<u8>,
        pks: vector<u64>
    )

2.1.1. Parameter Description

  1. sender:The on-chain sender, representing the originator of the message.

  2. msg_header:The message header, containing the header information of the message.

  3. msg_body:The message body, containing the main content of the message.

  4. multisig:The result of the BLS aggregated signature.

  5. pks:The indexes of public keys used to generate the aggregated signature.

2.2. The message consumption method and ABI on Sepolia, BSC, and Nile chains are defined as follows:

function processMsg(
        Types.Message memory message,
        bytes[] memory signature // 65bytes for one signature
    ) public returns (bool)
{
    "type": "function",
    "name": "processMsg",
    "inputs": [
      {
        "name": "message",
        "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. message:(Type: Types.Message) Structure

    • msg_header:Message header, of type 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:Destination chain information (Types.Chain)

      1. chain_type:Chain type (uint8)

      2. chain_id:Chain ID (uint64)

    • receiver:Receiver address (bytes32)

    • upload_gas_fee:Upload gas fee (uint128)

    • msg_body:Message body (bytes)

  2. signature:Array of message signatures (bytes[])

2.3. The cross-chain completion method definition and IDL on the Solana chain are as follows:

pub fn bridge_finish(
    ctx: Context<Consumption>,
    msg_header: MsgHeader,
    msg_body: MsgBody,
    accum_pk: Vec<u8>,
    signatures: Vec<[u8; 65]>,
) -> Result<()>
{
      "name": "bridge_finish",
      "discriminator": [
        99,
        177,
        36,
        34,
        56,
        39,
        63,
        99
      ],
      "accounts": [
        {
          "name": "sender",
          "writable": true,
          "signer": true
        },
        {
          "name": "token_mint",
          "writable": true
        },
        {
          "name": "receiver",
          "writable": true
        },
        {
          "name": "receiver_token_account",
          "writable": true
        },
        {
          "name": "bridge_authority"
        },
        {
          "name": "fund_pool",
          "writable": true
        },
        {
          "name": "pool_account",
          "writable": true
        },
        {
          "name": "token_relation"
        },
        {
          "name": "chain_relation"
        },
        {
          "name": "fee_token_relation"
        },
        {
          "name": "fee_token_mint",
          "writable": true
        },
        {
          "name": "fee_fund_pool",
          "writable": true
        },
        {
          "name": "fee_pool_account",
          "writable": true
        },
        {
          "name": "sender_fee_token_account",
          "writable": true
        },
        {
          "name": "from_chain_nonce_account",
          "writable": true
        },
        {
          "name": "message_fee",
          "writable": true
        },
        {
          "name": "bridge_config"
        },
        {
          "name": "bridge_core_program"
        },
        {
          "name": "program_id"
        },
        {
          "name": "token_program"
        },
        {
          "name": "associated_token_program"
        },
        {
          "name": "system_program"
        }
      ],
      "args": [
        {
          "name": "msg_header",
          "type": {
            "defined": {
              "name": "MsgHeader"
            }
          }
        },
        {
          "name": "msg_body",
          "type": {
            "defined": {
              "name": "MsgBody"
            }
          }
        },
        {
          "name": "accum_pk",
          "type": "bytes"
        },
        {
          "name": "signatures",
          "type": {
            "vec": {
              "array": [
                "u8",
                65
              ]
            }
          }
        }
      ]
    }

2.3.1. Parameter Description

  1. ctx: Context<Consumption> The context object containing all information related to the current transaction, including account states and permissions. This parameter ensures the function executes within the correct context.

  2. msg_header: MsgHeader The message header struct containing metadata about the message, such as sender address, timestamp, message type, etc. This provides the basic information of the message.

  3. msg_body: MsgBody The message body struct containing the actual data to be confirmed. This can be any type of data, e.g., transaction details or instructions.

  4. _accum_pk: Vec<u8> A byte vector representing the aggregated public keys, usually used to verify the message signature. This parameter may contain multiple public keys to ensure message authenticity.

  5. signatures: Vec<[u8; 65]> A vector of signature byte arrays, each 65 bytes long. This stores signatures for the message, used to verify the message’s origin and integrity.

PreviousMessage ContractNextServer-Side Integration

Last updated 9 days ago