# Message Passing

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.

{% tabs %}
{% tab title="Quote Sample" %}

```typescript
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" 
})
```

{% endtab %}

{% tab title="Swap Sample" %}

```typescript
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
}
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
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 to`LAYER_ZERO`, we use the same bridge for transferring tokens.&#x20;
{% endhint %}

Make sure to check out [Message Passing](/smart-contracts/message-passing.md) in order to implement proper interface in your smart contracts to receive messages from Rango contracts.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.rango.exchange/api-integration/basic-api-single-step/api-reference/message-passing.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
