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
  • Import
  • How is fee paid?
  1. Developer Guide
  2. anyCall V6

Fees Paid on Source Chain

anyCall V6 allows execution gas fees to be paid on the source chain instead of the destination chain.

If you want to pay fees on the source chain, simply set _flags as 2 in the anyCall function.

function anyCall( address _to, bytes calldata _data, address _fallback, uint256 _toChainID, uint256 _flags )

This allows guaranteed execution on the destination chain and also allows dapps to charge gas fees from users.

Import

Firstly, anyCall needs to be imported as a payable function as below:

interface CallProxy{
    function anyCall(
        address _to,
        bytes calldata _data,
        address _fallback,
        uint256 _toChainID,
        uint256 _flags

    ) payable external;
}

The specific fees can be calculated with this helper function in the anyCall contract:

_appID can simply be 0 as it's only used for specific dapps with special setting.

function calcSrcFees(
    string calldata _appID,
    uint256 _toChainID,
    uint256 _dataLength
) external view returns (uint256) {
    return _calcSrcFees(_appID, _toChainID, _dataLength);
}
function _calcSrcFees(
        string memory _appID,
        uint256 _toChainID,
        uint256 _dataLength
    ) internal view returns (uint256) {
        SrcFeeConfig memory customFees = srcCustomFees[_appID][_toChainID];
        uint256 customBaseFees = customFees.baseFees;
        uint256 customFeesPerBytes = customFees.feesPerByte;

        if (isUseCustomSrcFees(_appID, _toChainID)) {
            return customBaseFees + _dataLength * customFeesPerBytes;
        }

        SrcFeeConfig memory defaultFees = srcDefaultFees[_toChainID];
        uint256 defaultBaseFees = defaultFees.baseFees;
        uint256 defaultFeesPerBytes = defaultFees.feesPerByte;

        uint256 baseFees = (customBaseFees > defaultBaseFees) ? customBaseFees : defaultBaseFees;
        uint256 feesPerByte = (customFeesPerBytes > defaultFeesPerBytes) ? customFeesPerBytes : defaultFeesPerBytes;

        return baseFees + _dataLength * feesPerByte;
    }
}

The formula is a default fee + fee per byte in the calldata: baseFees + _dataLength * feesPerByte

How is fee paid?

After calculating the correct amount of fees to paid with the helped function, the fee should be paid as msg.value (The native gas token)

Then anyCall can be called with {value:msg.value} to pay fee on source chain.

CallProxy(anycallcontract).anyCall{value: msg.value}

PreviousanyCall V6 Testnet EnvironmentsNextContext (Verify msg.sender)

Last updated 2 years ago