Multichain
  • Getting Started
    • Introduction
      • Supported Chains
      • Supported Tokens
    • How it works
      • Cross-Chain Bridge
      • Cross-Chain Router
    • Governance Token
      • VeMulti
      • How to Convert ANY to MULTI
    • Security
      • Security model
      • Bug bounty (Immunefi)
      • Bug bounty (alternative)
    • How to Use
      • Fees
    • Road Map
    • FAQ
    • Careers
      • Front-end developer
      • Back-end developer
      • Test Engineer
      • Test Development Engineer
      • Security Engineer (Code Auditing)
      • Blockchain Development Engineer
      • Senior Content Editor
      • Event Manager
  • Listing and Integration
    • Token Listing
      • ERC20 Cross-chain Options
      • Difference between V2&V3
    • Chain Integration
      • EVM Networks Integration
      • Non-EVM Networks Integration
    • FAQ
  • Developer Guide
    • How to Integrate Front-end Router
    • Bridge API (Token list/Tx Status)
    • Scan API (Tx Status/Account History)
    • Token Router Testnet
    • anyCall V7
      • How to integrate anyCall V7?
      • API/Explorer
      • Quickstart (Cross-chain text example)
      • Estimate Fee/Pay Fees on destination chain
    • anyCall V6
      • How to integrate anyCall V6?
      • anyFallback
      • anyCall V6 Testnet Environments
      • Fees Paid on Source Chain
      • Context (Verify msg.sender)
    • $USDC CCTP X anyCall
      • Contract Addresses and example
    • anyCall NFT Bridge
    • Permissionless Token bridging
    • How to develop under Anyswap ERC20 standards
    • Bridge funds and anyCall (Router V7)
      • Mainnet
      • Testnet (Quick Start Example)
    • How to Integrate Front-end Bridges
Powered by GitBook
On this page
  • Sending the message
  • anyCall Interfaces
  • Receiving the message
  1. Developer Guide
  2. anyCall V7

Quickstart (Cross-chain text example)

This part goes over a simple example as well as how to send and receive message using anyCall.

PreviousAPI/ExplorerNextEstimate Fee/Pay Fees on destination chain

Last updated 2 years ago

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.

  1. Fork the provided repository and install the dependencies using either yarn or npm

    (yarn || npm install).

  2. 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.

  3. 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

  4. 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

Sending the message

The function below is an example. This sends a simple text message to the destination chain by using the anyCall funciton.

function step1_initiateAnyCallSimple_srcfee(string calldata _msg) payable external {
        emit NewMsg(_msg);
        if (msg.sender == owneraddress){
        CallProxy(anycallcontract).anyCall{value: msg.value}(
            receivercontract, //Destination Contract Address
            
            abi.encode(_msg), //encoded string as bytes
            destchain, //destination chain id
            
            0, // Using 0 flag to pay fee on the source chain
            "" //extra data used for advanced use cases
            );
            
        }

    }

Here's a more detailed breakdown of the parameters.

anyCall Interfaces

anyCall (Called by Dapps)

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.

Parameters

Param
Type
Description

_to

address

The target contract to interact with on _toChainID

_data

bytes

The calldata supplied for the interaction with _to

anyExecute will be run with this _data on the receiver contract you deployed.

_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

Receiving the message

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 memory _data) external returns (bool success, bytes memory result){
        (string memory _msg) = abi.decode(_data, (string)); 
        
        emit NewMsg(_msg);

        success=true;
        result='';

    }

anyExecute Parameters (This exact format needs to be implemented in your dapp, what would be called on the destination chain)

function anyExecute(bytes calldata data) external override onlyExecutor returns (bool success, bytes memory result)

Parameters

Param
Type
Description

data

bytes

The calldata supplied for the interaction with subsequent contracts

Returned Values

success

bool

The address to call on _fromChainID if the cross chain interaction fails

result

bytes

The originating chain id

GitHub - bscethbot/anyCall-V7-Simple-Message-Sender-ExampleGitHub
Logo