Infernet
SDK
Reference
Consumers
CallbackConsumer

CallbackConsumer

Git Source (opens in a new tab)

Inherits: BaseConsumer

Allows creating one-time requests for off-chain container compute, delivered via callback

Inherits BaseConsumer to inherit functions to receive container compute responses and emit container inputs

State Variables

subscriptionInputs

subscriptionId => callback input data

Could be restricted to private visibility but kept internal for better testing/downstream modification support

mapping(uint32 => bytes) internal subscriptionInputs;

Functions

constructor

Initialize new CallbackConsumer

constructor(address registry) BaseConsumer(registry);

Parameters

NameTypeDescription
registryaddressregistry address

_requestCompute

Creates a one-time request for off-chain container compute via callback

Under the hood, creates a new subscription at the Infernet coordinator, with period == 0 and frequency == 1, effectively initializing a subscription valid immediately and only for 1 interval

function _requestCompute(
    string memory containerId,
    bytes memory inputs,
    uint16 redundancy,
    address paymentToken,
    uint256 paymentAmount,
    address wallet,
    address verifier
) internal returns (uint32);

Parameters

NameTypeDescription
containerIdstringcompute container identifier(s) used by off-chain Infernet node
inputsbytesoptional container inputs
redundancyuint16number of unique responding Infernet nodes
paymentTokenaddressIf providing payment for compute, payment token address (address(0) for ETH, else ERC20 contract address)
paymentAmountuint256If providing payment for compute, payment in paymentToken per compute request fulfillment
walletaddressIf providing payment for compute, Infernet Wallet address; this contract must be approved spender of Wallet
verifieraddressoptional verifier contract to restrict payment based on response proof verification

Returns

NameTypeDescription
<none>uint32subscription ID of newly-created one-time subscription

getContainerInputs

View function to broadcast dynamic container inputs to off-chain Infernet nodes

Modified from BaseConsumer to expose callback input data, indexed by subscriptionId

function getContainerInputs(uint32 subscriptionId, uint32 interval, uint32 timestamp, address caller)
    external
    view
    override
    returns (bytes memory);

Parameters

NameTypeDescription
subscriptionIduint32subscription ID to collect container inputs for
intervaluint32subscription interval to collect container inputs for
timestampuint32timestamp at which container inputs are collected
calleraddresscalling address