SolidML Library
SolidML is a comprehensive framework for building the next generation of AI-enabled on-chain applications. Examples include AMMs that use dynamic fee models, lending pools that use models for risk calculation, or on-chain agents to name a few. SolidML allows developers to securely execute ML and LLM models through a simple function call - all executed as part of an atomic transaction. Additional capabilities include model scheduling, price feeds and data preprocessing. Any model uploaded to the Model Hub is available to use through SolidML.
Demonstrated through a simple example:
function runSolidML(ModelInput calldata modelInput) {
// running on-chain inference
ModelOutput memory ouput = OGInference.runModelInference(
ModelInferenceRequest(
// using ZKML for verifiable inference
ModelInferenceMode.ZK,
// model CID from Model Hub
"QmbbzDwqSxZSgkz1EbsNHp2mb67rYeUYHYWJ4wECE24S7A",
// requested model input
modelInput
));
// extract model output
TensorLib.MultiDimensionalNumberTensor[] prediction = output.numbers[0];
TensorLib.Number fee_parameter = prediction[0];
// use fee parameter...
}
NOTE
The OpenGradient Network is an EVM chain compatible with most existing EVM frameworks and tools. In addition to the standard EVM capabilities, we support native AI inference directly from smart contracts. To learn more about how on-chain inference works, go to Onchain Inference
Any model uploaded to the Model Hub can be used through SolidML. Models are referenced through their unique CID.
Benefits of SolidML onchain inference
The main benefits of running inference through SolidML include:
- Atomic execution: inferences are atomically executed as part of the EVM transaction that triggers it; this makes it easier to ensure state consistency
- Simple interface: inferences can be run through a simple function call without the need for callback functions and handlers
- Composability: through the use of smart contract transactions, multiple models can be chained together using arbitrarily complex logic - supporting advanced real-world use cases
- Native verification: inference validity proofs (e.g., ZKML and TEE) are natively validated by the underlying OpenGradient network protocol. This means that smart contracts can trust the results without explicit verification.
Installation
SolidML can be installed by running:
npm i opengradient-solidml
SolidML Components
Check the following guides for specific components:
- ML and LLM Inference: Interfaces and precompiles that allow any smart contract to use natively inference ML and LLM models from the Model Hub
- Data Preprocessing: Interfaces and precompiles that allow for data preprocessing from smart contracts (min, max, mean, etc.)
- Price Feed: Allows the retrieval of latest asset prices through an oracle as well as historical price feeds for running inference.