#tim
The Infernet SDK is a set of smart contracts from Ritual that enable on-chain smart contracts to subscribe to off-chain compute workloads.
Developers can inherit one of two simple interfaces, CallbackConsumer
or SubscriptionConsumer
in their smart contracts, and consume one-time or recurring computation.
Important
Smart contract architecture, quick-start guides, and in-depth documentation can be found on the Ritual documentation website
Warning
These smart contracts are being provided as is. No guarantee, representation or warranty is being made, express or implied, as to the safety or correctness of the smart contracts.
First, ensure you have Foundry installed locally. A simple way to install is to run the following command:
# Install foundryup, follow instructions
curl -L https://foundry.paradigm.xyz | bash
To build, run, or execute other commands, you can reference the Makefile.
The default target (make
) will:
- Install all dependencies
- Clean existing build outputs
- Format code
- Build code and copy compiled artifacts
- Run test suite
To import Infernet as a library, you can install the code in your repo with forge:
forge install https://github.com/ritual-net/infernet-sdk
To integrate with the contracts, the available interfaces can be imported from ./src/consumer:
import {CallbackConsumer} from "infernet/consumer/Callback.sol";
contract MyContract is CallbackConsumer {
function requestSomeComputeResponse() {
// This will create a new one-time callback request for off-chain compute
_requestCompute(...);
}
function _receiveCompute(...) internal override {
// Here you will receive the off-chain compute response
}
}
import {SubscriptionConsumer} from "infernet/consumer/Subscription.sol";
contract MyContract is SubscriptionConsumer {
function scheduleComputeResponse() {
// This will create a new recurring request for off-chain compute
_createComputeSubscription(...);
}
function cancelScheduledComputeResponse() {
// This will allow you to cancel scheduled requests
_cancelComputeSubscription(...);
}
function _receiveCompute(...) internal override {
// Here you will receive the off-chain compute output
}
}
.
├── .env.sample # Sample env variables
├── .gas-snapshot # Function execution gas snapshot
├── Makefile
├── README.md
├── STYLE.md
├── compiled # Pre-compiled artifacts (via solc)
│ └── Verifier.sol
│ ├── Halo2Verifier.json
│ └── Verifier.sol
├── foundry.toml # Foundry setup
├── remappings.txt
├── scripts
│ └── Deploy.sol # EIP712Coordinator deploy script
├── src # Contracts
│ ├── Coordinator.sol # Base coordinator
│ ├── EIP712Coordinator.sol # EIP-712 typed message supporting coordinator
│ ├── Manager.sol # Node manager
│ ├── consumer # Consumers inherited by developers
│ │ ├── Base.sol
│ │ ├── Callback.sol # CallbackConsumer
│ │ └── Subscription.sol # SubscriptionConsumer
│ └── pattern # Useful developer patterns
│ └── Delegator.sol # EIP-712 delegator
└── test # Tests
├── Coordinator.t.sol
├── E2E.t.sol
├── EIP712Coordinator.t.sol
├── Manager.t.sol
├── ezkl # E2E tests w/ EZKL-generated proofs
│ ├── BalanceScale.sol
│ └── DataAttestor.sol
├── lib # Useful libraries
│ ├── LibSign.sol # EIP-712 signing
│ └── LibStruct.sol # Struct parsing
└── mocks
├── MockManager.sol
├── MockNode.sol # Mock Infernet node
└── consumer
├── Base.sol
├── Callback.sol
├── DelegatorCallback.sol
└── Subscription.sol