MAPO Developer Docs
  • MAPO Developer Docs
  • Base
    • MAPO Introduction
    • MAPO token
    • Omnichain DAPP
    • Differences Between Omnichain Applications and Single or Multi-Chain Applications
    • Differences Between Third-Party Trusted Cross-Chain and Peer-to-Peer Cross-Chain Solutions
    • BTC layer2
      • brc-201
    • Oracle
      • Supra: Decentralized Oracle on MAP Protocol
    • Account
    • Transactions
    • block
    • MPT tree
    • RLP
    • Gas fee
    • Cross Chain Message
    • light client
      • MAPO light client
    • MOS
      • MOS interface and functions
      • deploy MOS
      • Messenger
    • map-relay-chain(atlas)
      • atlas architecture
        • atlas architecture
        • atlas genesis
          • genesis config
          • genesis contract
            • ABI
              • Accounts
              • Election
              • EpochRewards
              • LockedGold
              • Validators
            • address
            • deploy
        • precompile-contract
        • protocol
          • Proof of Stake
          • consensus
          • election
          • rewards
          • governance
      • deploy atlas
        • run atlas
        • run atlas(archive)
        • run atlas(bootnodes)
        • run atlas(validator)
        • run atlas(RPC)
      • Marker tool
        • Genesis
        • Validator
        • Vote
        • Common
      • make private network(atlas)
      • public service
        • public network
      • example
        • how-to-vote
        • how-to-withdraw
        • how-to-become-a-new-validator
        • how-to-become-a-new-validator(advanced)
    • Compass(maintainer,messenger)
      • Compass - arch and model
      • Compass - config
      • Compass - deploy
      • Compass secondary development - define your own routing service based on compass
  • MAPO Stack
    • stack
      • Connected Chains and Corresponding Addresses
    • Compatible-EVM
      • Smart Contracts Language
      • Smart Contracts Anatomy
      • Smart Contracts Libraries
      • Smart Contracts Compile
      • Smart Contracts Testing
      • Smart Contracts Deploy
      • Smart Contracts Composability
      • Smart Contracts Security
      • Formal-Verification
      • Frameworks
      • dev-network
    • MAPO Implement Cross-chain Interoperability
      • integration of MAP with EVM-Compatible Chains
        • light client verify
        • light client update state
        • MOS
      • integration of MAP with TON Network
      • integration of MAP with Non-EVM-Compatible Chains
        • light client verify
        • light client update state
        • MOS
    • How to develop cross-chain applications
    • light client address
    • SDK/API
      • MOS interface
      • Light client interface
      • Atlas RPC
        • json-rpc
          • atlas json rpc
          • atlas consensus rpc
        • javaScript sdk
        • go-sdk
      • Backend API
        • SCAN API
  • Zero-Knowledge Proof
    • zk proof
Powered by GitBook
On this page
  • Ton Network message out
  • Message to Ton Network
  1. MAPO Stack
  2. MAPO Implement Cross-chain Interoperability

integration of MAP with TON Network

Ton Network message out

Call message out

slice bridge_addr = <bridge address>;
;; message out body
cell body = begin_cell()
    .store_uint(0x136a3529, 32) ;; op::message_out
    .store_uint(0, 64) ;; queryId
    .store_ref(
        begin_cell()
            .store_uint(0, 8) ;; relay, 0 or 1
            .store_uint(0, 8) ;; msgType, 0 for message or 1 for calldata
            .store_uint(56, 64) ;; toChain, eg. 56 for bnb
            .store_slice(begin_cell().store_uint(0x70997970c51812dc3a010c7d01b50e0d17dc79c8, 512).end_cell().begin_parse()) ;; targetAddress
            .store_ref(begin_cell().store_uint(1, 8).end_cell()) ;; payload, custom data
            .store_uint(200000000, 64) ;; gasLimit
            .end_cell()
    )
    .end_cell();

;; internal message
cell msg = begin_cell()
    .store_uint(0x18, 6)
    .store_slice(bridge_addr)
    .store_coins(50000000) ;; 0.05 TON for fees
    .store_uint(0, 1 + 4 + 4 + 64 + 32 + 1 + 1)
    .store_slice(body)
    .end_cell();
  • relay indicates whether message processing is required on MAP Relay Chain.

  • msgType indicates different message, MESSAGE or CALLDATA.

  • target is the contract address where the message will be executed upon reaching the target chain

  • payload is the data intended for cross-chain transmission.

  • gasLimit is the maximum gas limit allowed for execution on the target chain.

Message to Ton Network

Sending a omni-chain message to TON is the same as sending messages to other chains. You can directly encode the assembled MessageData and then call transferOut to send the omni-chain message. It is essential to ensure that the message data payload is a message that can be recognized by TON.

    bytes memory messageData = abi.encode(MessageData({}));
    
    function transferOut(
        uint256 toChain,
        bytes memory messageData,
        address feeToken
    ) external payable returns (bytes32);

Here, toChain is the TON Network chain id:

  • mainnet: 1360104473493505

  • testnet: 1360104473493506

Execute on Ton Network

On ton network, will send an execute message to the target contract.

begin_cell()
    .store_op(op::mapo_execute)
    .store_query_id(query_id)
    .store_uint(1, 64) ;; from chain id
    .store_uint(56, 64) ;; to chain id
    .store_slice(sender_address) ;; sender address
    .store_uint(2, 256) ;; order id
    .store_ref(begin_cell().end_cell()) ;; message
    .end_cell()
Previousintegration of MAP with EVM-Compatible ChainsNextintegration of MAP with Non-EVM-Compatible Chains

Last updated 7 months ago