Clique Docs
  • What Is Clique
    • TEE Network
    • Compute Coordination Network
  • Build with Clique
    • Clique Application Structure
    • Clique CLI
      • Installation
      • Develop Task
      • Build Task
      • Test Task
      • Deploy Task
    • Clique Client SDK
    • Smart Contract SDK
      • Smart Contract Integration
      • Clique Official Tasks
  • References
    • Clique Manifest
    • Clique Query
    • Verification
  • Sample Task Tutorials
    • Data Attestation
    • Social Verification
      • Github
      • Twitter
    • Making Arbitrary TLS Calls (TLS Oracle)
    • Custom Executor
  • Toolchain
    • Clique Pipelines SDK
    • Clique Attestation SDK
      • Attestation Protocols
      • Reading Attestations On-chain
      • Reading Attestations Off-Chain
      • What are Attestors ?
        • Data Sources
    • Clique Browser Extension
  • FAQ
  • Glossaries
  • Socials
Powered by GitBook
On this page
  • Example
  • On-Chain Verification
  1. Build with Clique
  2. Smart Contract SDK

Smart Contract Integration

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

Example

/// 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
        );
    }
}

Let's break down the example.

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:

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, callbackwill be invoked with response bytes. Program execution resumes afterward.

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

Asynchronous programming in Solidity

On-Chain Verification

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.

PreviousSmart Contract SDKNextClique Official Tasks

Last updated 8 months ago

For details on the standard verification process, refer to the 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.

For more information, please refer to .

Verification
On-Chain Verification