Rango Docs
API SwaggerWidget PlaygroundAppWebsite
  • 👋Welcome to Rango
  • 🏠Introduction
  • 💁How It Works
  • ✅Integrations
  • ⚖️Rango vs. Competitors
  • 🔐Security
  • 🛣️Roadmap
  • 🦎Tokenomics
  • 💰Airdrop
  • ❓FAQ
  • 🐞Bug Bounty
  • API Integration
    • 🔡Terminology
    • 🚄API Key & Rate Limits
    • 🤝Choosing the Right API
    • 🦄Basic API - Single Step
      • 🛝API Flow
      • ⚙️API Reference
        • Get Blockchains & Tokens
        • Get Quote
        • Create Transaction (Swap)
        • Check Transaction Status
        • Check Approve Transaction Status
        • Get Address Assets & Balances
        • Get Token Balance
        • Report Transaction Failure
        • Get Direct Tokens
        • Get Custom Token
        • Message Passing
      • 🎓Tutorial
        • 🍰SDK Example
      • 💰Monetization
      • 🎹Sample Transactions
      • ✅Integration Checklist
    • 🦎Main API - Multi Step
      • 🛝API Flow
      • ⚙️API Reference
        • Get Blockchains & Tokens
        • Get Best Route
        • Get All Possible Routes
        • Confirm Route
        • Create Transaction
        • Check Transaction Status
        • Check Approve Transaction Status
        • Report Transaction Failure
        • Get Custom Token
        • Get Address Token Balance
      • 🎓Tutorial
        • 🍰SDK Example
      • 💰Monetization
      • 🎹Sample Transactions
  • ℹ️API Troubleshooting
  • Technical Docs
    • 🍔Swap Aggregation
    • 💰Monetization
    • ⛽Fee Structure
    • ⛽Network Fees and Gas Estimates
    • ⌛Stuck Transactions
  • Widget Integration
    • 🧩Overview
    • 🎇Quick Start
    • ⚙️Customization
    • 💰Monetization
    • 🛣️React Router
    • 🎵Events
    • 💳External Wallets
  • Smart Contracts
    • 👩‍💼Architecture
    • 🔎Audit Reports
    • 🏗️Deployment Addresses
    • 📩Message Passing
  • Ask for Integration
    • 🙋‍♂️DEXs & DEX Aggregators
    • 📱Rango Mobile SDK
  • Useful Links
    • Twitter
    • Discord Server
    • TG Announcements
    • TG Group
  • Terms of Use
  • Privacy policy
Powered by GitBook
On this page

Was this helpful?

  1. API Integration
  2. Basic API - Single Step
  3. API Reference

Message Passing

How to relay message in a cross-chain swap?

When transferring tokens using Rango cross-chain API, you could pass a random message from the source chain to the destination and call your contract on the destination. In order to do so, you need to pass your contracts on source & destination chains plus an arbitrary hex message. Here is a brief guide on what you need to do in terms of SDK usage and the smart contract side.

SDK Usage

You should specify sourceContract, destinationContract and imMessage arguments in both quote and swap methods if you want to pass a message from the source contract to the destination.

const quoteResponse = await rango.quote({
  from: {
    "blockchain": "OPTIMISM",
    "symbol": "ETH",
    "address": null
  },
  to: {
    "blockchain": "ARBITRUM",
    "symbol": "ETH",
    "address": null
  },
  amount: "100000000000000000000",
  messagingProtocols: ['LAYER_ZERO'],
  sourceContract: "<source contract address>",
  destinationContract: "<destination contract address>",
  imMessage: "0x00000000000000000000000000000000000000000000000000000000000000010000000000000000000000007E8A8b130272430008eCa062419ACD8B423d339D" 
})
const swapResponse = await rango.swap({
  from: {
    "blockchain": "OPTIMISM",
    "symbol": "ETH",
    "address": null
  },
  to: {
    "blockchain": "ARBITRUM",
    "symbol": "ETH",
    "address": null
  },
  amount: "100000000000000000000",
  fromAddress: fromAddress,
  toAddress: fromAddress,
  disableEstimate: false,
  referrerAddress: null,
  referrerFee: null,
  slippage: '1.0',
  messagingProtocols: ['LAYER_ZERO'],
  sourceContract: "<source contract address>",
  destinationContract: "<destination contract address>",
  imMessage: "0x00000000000000000000000000000000000000000000000000000000000000010000000000000000000000007E8A8b130272430008eCa062419ACD8B423d339D"
})

if (!!swapResponse && !swapResponse.error && swapResponse.resultType === "OK" && swapResponse.tx?.type === TransactionType.EVM) {
  const evmTx = swapResponse.tx as EvmTransaction
  const {value, txData} = evmTx
  console.log({value, txData})
  // pass value and txData to your own contract
}

You could also limit messagingProtocols used to a custom list like ['LAYER_ZERO']. (Please note that as the message is relayed alongside with token in a single transaction if you limit messaging protocols toLAYER_ZERO, we use the same bridge for transferring tokens.

Make sure to check out Message Passing in order to implement proper interface in your smart contracts to receive messages from Rango contracts.

PreviousGet Custom TokenNextTutorial

Last updated 10 months ago

Was this helpful?

🦄
⚙️