Quickstart (Cross-chain text example)
This part goes over a simple example as well as how to send and receive message using anyCall.
Last updated
This part goes over a simple example as well as how to send and receive message using anyCall.
Last updated
Please fork the repo above and follow the readme.
This repo would deploy a solidity contract on two chains and send a text message from chain A to chain B. This is purposed to showcase anyCall V7 cross-chain messaging capability.
Fork the provided repository and install the dependencies using either yarn or npm
(yarn || npm install
).
Add your private key and Etherscan API keys (if you want to verify the contract on Etherscan) to the .env.example file. Rename the file to .env.
Deploy the example contract on the ftm and bnb testnets by running the following commands:
yarn hardhat deploy --network ftmtest
yarn hardhat deploy --network bnbtest
To test the flow, run the following command and change the customMessage in 1testanycall.js to send a different message:
yarn hardhat run ./scripts/1testanycall.js --network ftmtest
Code Breakdown
The function below is an example. This sends a simple text message to the destination chain by using the anyCall funciton.
Here's a more detailed breakdown of the parameters.
function anyCall( address _to, bytes calldata _data, uint256 _toChainID, uint256 _flags, bytes calldata )
The destination chain would call anyExecute
function on the _to
address with _data
passed in the function. And you can customize what you do with such _data
.
Param | Type | Description |
---|---|---|
_to | address | The target contract to interact with on |
_data | bytes | The calldata supplied for the interaction with
|
_toChainID | uint256 | The target chain id to interact with |
_flags | uint256 | How dapps are paying gas fee of tx execution: 2: Gas fee paid on destination chain. 4: Allow fallback |
The following function named anyExecute would process the data sent. In this case, it'd simply decode the data and emit an event. The function must be called anyExecute.
function anyExecute(bytes calldata data) external override onlyExecutor returns (bool success, bytes memory result)
Param | Type | Description |
---|---|---|
data | bytes | The calldata supplied for the interaction with subsequent contracts |
Returned Values | ||
|
| The address to call on |
|
| The originating chain id |