> For the complete documentation index, see [llms.txt](https://docs.multichain.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.multichain.org/developer-guide/anycall-v6/fees-paid-on-source-chain.md).

# Fees Paid on Source Chain

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

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`**` ``)`

{% hint style="info" %}
This allows guaranteed execution on the destination chain and also allows dapps to charge gas fees from users.
{% endhint %}

### 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:

{% hint style="info" %}
\_appID can simply be 0 as it's only used for specific dapps with special setting.
{% endhint %}

```
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)&#x20;

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

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


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.multichain.org/developer-guide/anycall-v6/fees-paid-on-source-chain.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
