> For the complete documentation index, see [llms.txt](https://docs.clique.tech/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.clique.tech/build-with-clique/smart-contract-sdk/smart-contract-integration.md).

# Smart Contract Integration

This overview explains how Clique can be integrated with your smart contracts.

### Example

{% code lineNumbers="true" %}

```solidity
/// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import {ICliqueTaskManger} from "clique-contracts/ICliqueTaskManger.sol";

struct Response {
    bytes16 data;
}

struct EchoParams {
    bytes data;
}

contract MockClient {
    address public immutable _manager;

    event CallbackInvoked();

    constructor(address manager) {
        _manager = manager;
    }

    function callback(bytes calldata _response) external {
        Response memory response = abi.decode(_response, (Response));
        require(response.data == bytes16("hello, clique"), "Invalid response");
        emit CallbackInvoked();
    }

    function run() public {
        ICliqueTaskManager.Task memory task = ICliqueTaskManager.Task(
            0,
            "echo",
            abi.encode(EchoParams("hello, clique"))
        );
        ICliqueTaskManager(_manager).createNewTask{value: 0.05 ether}(
            abi.encode(task),
            this.callback.selector
        );
    }
}
```

{% endcode %}

Let's break down the example.

```solidity
import {ICliqueTaskManger} from "clique-contracts/ICliqueTaskManger.sol";
```

Import the Clique Contract SDK here.

`run()` is the entry point where we initialize a query struct and call the `createNewTask` function with a callback selector:

```solidity
function run() public {
    ICliqueTaskManager.Task memory task = ICliqueTaskManager.Task(
        0,
        "echo",
        abi.encode(EchoParams("hello, clique"))
    );
    ICliqueTaskManager(_manager).createNewTask{value: 0.05 ether}(
        abi.encode(task),
        this.callback.selector
    );
}
```

Once the task is fulfilled, `callback`will be invoked with response bytes. Program execution resumes afterward.

```solidity
function callback(bytes calldata _response) external {
    Response memory response = abi.decode(_response, (Response));
    require(response.data == bytes16("hello, clique"), "Invalid response");
    emit CallbackInvoked();
}
```

{% hint style="info" %}
Asynchronous programming in Solidity
{% endhint %}

### On-Chain Verification

{% hint style="info" %}
For details on the standard verification process, refer to the [Verification](/references/verification.md) section. This process mirrors the one used during setup. To minimize gas costs, subsequent verifications employ an ECDSA-based solution, as outlined in this section.
{% endhint %}

To use ECDSA-based verification, `CliqueTaskManager` maintains a trusted public key. And a **Trust Setup** process is required when a kernel initially fulfills tasks. It must submit a triple tuple consisting of a response, attestation, and signature.  If the attestation is valid, the public key recovered from this `signature, CUID` pair will be trusted. The ephemeral key must be regenerated each time the kernel restarts. Once **Trust Setup** done, the `attestation` could be empty when the kernel fulfills subsequent tasks.&#x20;

For more information, please refer to [Verification](/references/verification.md#on-chain-verification).


---

# 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.clique.tech/build-with-clique/smart-contract-sdk/smart-contract-integration.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.
