OmniDictionary

Brief Description

The OmniDictionary is a simple dApp demo that demonstrates how cross-chain contract interaction is processed through mapo omnichain service contract. It basically allows user to send request to adding a new entry in a dictionary(a simple mapping) on a foreign chain with a simple key and its corresponding value.

Tech Details

In order to achieve inter-blockchain contract execution, developers first needs to process their execution logic in a logic contract and then send the generated calldata from the source chain through the 'TransferOut' method through mapo omnichain service contract.

In our example, 'TransferOut' method is called as following and calldata is also generated in the middle process:

    function sendDictionaryInput(uint256 _tochainId,bytes memory _target,string memory _key,string memory _val) external payable {

    bytes memory data = encodeDictionaryInput(_key,_val);

    IMOSV3.MessageData memory mData = IMOSV3.MessageData(false,IMOSV3.MessageType.CALLDATA,_target,data,500000,0);

    bytes memory mDataBytes = abi.encode(mData);

    (uint256 amount,address receiverAddress) = IMOSV3(mos).getMessageFee(_tochainId,address(0),500000);

    require(
        IMOSV3(mos).transferOut{value:amount}(
            _tochainId,
            mDataBytes,
            address(0)
        ),
        "send request failed"
    );

    emit sendEntry(_tochainId, _target, _key, _val);
}

secondly, the messenger picks up the event generated by the above transaction and constructed a corresponding proof, then it packs them together and send it to the mapo omnichain service contract on MAP Relay Chain:

And finally, the above process will be repeated by messenger and send it all the data to the destination chain by a 'TransferIn' method which will also execute the user input calldata:

and the destination dictionary is finally set by

All the above code can be found in our github repo.

Last updated

Was this helpful?