# Interoperability between Ethereum and MultiversX ecosystems

Integrating the Ethereum stack, including the VM and RPC, into the chain provides users with new opportunities. So far, this new realm was isolated from MultiversX. To ensure seamless interoperability between these ecosystems, additional features were developed.&#x20;

***

## Cross-VM Communication

The communication between EVM and SpaceVM requires special handling due to their different data encoding standards. To simplify the conversion process, our team has developed some user-friendly built-in functions:

```
EthereumToMultiversXEncodingWithMultiversXSignature
EthereumToMultiversXEncodingWithEthereumSignature
MultiversXToEthereumEncodingWithMultiversXSignature
MultiversXToEthereumEncodingWithEthereumSignature
```

To utilize these methods, append an ABI signature followed by one or more arguments.

Additionally, we have created master contracts for Solidity and Rust that can be inherited to facilitate cross-VM calls. Please refer to the documents attached below for further details.

The contracts manage, in a similar manner, ABI signatures for input and output parameters. An ABI signature is a comma-separated list of platform-agnostic ABI types. For a list of available ABI types, please refer to the dedicated documentation:

* For Ethereum: [Ethereum ABI Specification](https://docs.soliditylang.org/en/latest/abi-spec.html). Example of a complex ABI signature: “address,uint56,bytes24,bool,(uint256,uint256),(uint256\[],bool,bytes,address),…”
* For MultiversX: [MultiversX ABI Specification](https://docs.multiversx.com/developers/data/abi/). Example of a complex ABI signature: “Address,BigInt,bytes,bool,tuple\<u64,i32>,tuple\<List\<u64>,…”

Developers must ensure that the input and output arguments match the parameters of the target execution environment. Use the conversion tables below to identify which data types should be used in the source environment, based on the ABI data types in the target environment.

### ABI type mappings

Refer to the mappings below when calling an EVM contract:

{% file src="<https://1190176482-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FovGx4KpCzuXudyptCp3p%2Fuploads%2FkjCJ38igx6sz5sAr5DjJ%2FEthereum%20-%20MultiversX%20conversions.pdf?alt=media&token=bcdc8e34-0c40-40f3-80c4-b09955306731>" %}

Refer to the mappings below when calling a SpaceVM contract:

{% file src="<https://1190176482-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FovGx4KpCzuXudyptCp3p%2Fuploads%2FVA6K0GnclXTQagBmc8PQ%2FMultiversX%20-%20Ethereum%20conversions.pdf?alt=media&token=bb0cb98c-3f91-48f1-997c-410c1decd553>" %}

### Solidity master contract

When creating smart contracts in Solidity, you may inherit the connector provided below for doing cross-VM calls:&#x20;

{% file src="<https://1190176482-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FovGx4KpCzuXudyptCp3p%2Fuploads%2FXyzPcttWXWg5abGeFX4X%2FSpaceVMConnector.sol?alt=media&token=fd255d84-554b-41d6-8277-fa7a22455b29>" %}

Review the example below for a better understanding:

```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "./SpaceVMConnector.sol";

contract SpaceVMConnectorExample is SpaceVMConnector {

    address private spaceVMContractAddress;

    function setSpaceVMContractAddress(address contractAddress) external {
        spaceVMContractAddress = contractAddress;
    }

    function pingSpaceVM(uint32 value) public returns (bool, uint32) {
        require(spaceVMContractAddress != address(0));

        (bool success, bytes memory output) = callSpaceVM(spaceVMContractAddress, "ping", "u32", "u32", abi.encode(value));
        if (!success) {
            return (false, 0);
        }
        return (true, abi.decode(output, (uint32)));
    }

}
```

In the example provided, the `ping` method is invoked on a SpaceVM contract. The `u32` parameters for the destination contract convert to `uint32` in Solidity due to the predefined ABI data types mapping inserted in the previous [subsection](#abi-type-mappings). Through utilizing Solidity's `abi` encoding and decoding functions, the caller ensures arguments are passed using Ethereum's encoding standard.

***

## Cross-Ecosystem Transfers

OneFinity enables ETH-to-MVX and MVX-to-ETH transfers utilizing a system-level smart contract. Unlike traditional tools, which only support address-to-address transfers within the same format, our solution offers enhanced flexibility.

The contract's details are:

* Address: `one1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq9lllsjtkurw`.
* Expected payload: `crossAddressTransfer@`**`hexAddress`**`@`**`addressIdentifier`**. The **`hexAddress`** parameter represents the target address, in hex format (whether it is an Ethereum or a MultiversX one). The **`addressIdentifier`** parameter represents the type of the **`hexAddress`**  and should have one of the following values: **`0001`** (for MultiversX addresses) or **`0002`** (for Ethereum addresses).

Explore the ***Cross-Ecosystem Transfers dApp*** for more details (choose the appropriate environment [here](https://docs.onefinity.network/technical-documentation/environments)). Users can log in using either Metamask or OneFinity's [Lite Wallet](https://docs.onefinity.network/tools-and-sdks-for-developers#lite-wallet).
