> For the complete documentation index, see [llms.txt](https://docs.butternetwork.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.butternetwork.io/butter-omnichain-messaging-integration/butter-omnichain-service-explain/calldata-type.md).

# CALLDATA

Example Requirement: You need to obtain the value corresponding to a key from the `dictionaryList` on chain A, and then pass the key and its corresponding value to chain B for storage, so that chain B can also retrieve the value corresponding to the key.

Necessary Conditions:

1. Encode the call data before initiating the cross-chain request.
2. On the source chain, the Omni service interface and contract address are needed to initiate a cross-chain event.
3. On the target chain, the Omni service contract must be granted permission to execute the call method.

We initiate a cross-chain event on source chain A.

```
"@butternetwork/omniservice/contracts/interface/IMOSV3.sol";

contract A {
    //The contract address of OmniService on chain A
    IMOSV3 public imosv3;
    
    mapping(string => string) public dictionaryList;
    
    mapping(address => bool) public whitelist;
    
    function setDictionaryEntry(
    	string memory _key, 
    	string memory _val
    ) external {
    
    }
    
   	function sendDictionaryCalldata(
        uint256 _tochainId, //The chain ID of the target chain.
        bytes memory _target, //The contract address on the target chain.
        string memory _key //The message key on chain A.
    ) external payable {
    	//Encode the message that needs to be cross-chain.
        bytes memory data = abi.encodeWithSelector(A.setDictionaryEntry.selector,_key,dictionaryList[_key]);
                		
        IMOSV3.MessageData memory mData = IMOSV3.MessageData(
            false,
            IMOSV3.MessageType.CALLDATA, ///Select CALLDATA for cross-chain transmission.
            _target,
            data,
            500000,
            0
        );
		
        //Encode the MessageData structure for cross-chain transmission.
        bytes memory mDataBytes = abi.encode(mData);
        
        //Retrieve the amount of fee required for cross-chain transaction.
        (uint256 amount, ) = imosv3.getMessageFee(_tochainId, address(0), 500000);
        
        //Initiate the cross-chain request using OmniChain Service
        imosv3.transferOut{value: amount}(_tochainId, mDataBytes, address(0));
    }
}
```

After `messager` detects the cross-chain log, it will execute the cross-chain message on chain B.

We implement `mapoExecute` on chain B to finalize the cross-chain message execution.

```
"@butternetwork/omniservice/contracts/interface/IMOSV3.sol";

contract B is IMapoExecutor {
    //The contract address of OmniService on chain B
    IMOSV3 public imosv3;
    
	mapping(bytes32 => bool) orderList;
	
	//In a simple example, here's a mapping used to store cross-chain data 
	//(this can be any other type, this is just a simple example)
	mapping(string => string) public dictionary;
	
	function setDictionaryEntry(
    	string memory _key, 
    	string memory _val
    ) external {
        require(whitelist[msg.sender], "access denied");
        dictionary[_key] = _val;
        emit setEntry(_key, _val);
        return true;
    }
	//Grant or revoke permission for the contract address on the source chain. 
	//True indicates permission granted, and false indicates no permission.
	function addRemoteCaller(
		uint256 _fromChain, 
		bytes memory _fromAddress, 
		bool _tag
	) external {
        imosv3.addRemoteCaller(_fromChain, _fromAddress, _tag);
    }
}
```

Advantages of `CALLDATA`:

* Cross-chain data is predetermined.
* The target chain does not require extensive contract checks; granting Omni service execution permission is sufficient.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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.butternetwork.io/butter-omnichain-messaging-integration/butter-omnichain-service-explain/calldata-type.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.
