# Callback

Callback is used to make a function call to an external contract. The external contract can perform an arbitrary logic using the bytes `data` and payable `value` provided by the call arguments.

One key usage for the callback is to make a token swap from a DEX contract outside of INIT.

{% hint style="info" %}
The external contract must implement `coreCallback payable` function.
{% endhint %}

{% hint style="info" %}
It is recommended to check that `msg.sender` of `coreCallback` is `INIT_CORE` to avoid unintended external calls from other users.
{% endhint %}

```solidity
// Example external contract that uses InitCore's callback
contract ExternalContract {
    function coreCallback(address sender, bytes calldata data) external payable returns (bytes memory result) {
        // check msg.sender is InitCore
        require(msg.sender == INIT_CORE, 'sender not allowed');

        // perform a swap on a DEX
        
        // returns bytes result
    }
    
    function executeCallback(bytes calldata data) payable {
        IInitCore(INIT_CORE).callback{value: msg.value}(msg.sender, data);
    }
}
```


---

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

```
GET https://dev.init.capital/guides/advanced-interaction/callback.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
