Task
Learn more about publishing an OVM Task.
Introduction
A task is a computation unit that leverages OVM's access high-performance compute resources for completing complex computations like AI training, scientific simulations, or any other compute-intensive tasks that are not feasible on an EVM blockchain.
Think of it as a dApp that knows the computation to be executed, the environment in which it should run, and the requirements for the execution. Once a new compute task is published by a user, the OVM gateway contract routes the task to the optimal executor to execute the task.
Getting Started
Let's see how you can get started with building and deploying smart contracts on OVM to deploy a task.
Prerequisites
Before you start building, make sure you have the following prerequisites:
Installation
You should use foundry to create a new project.
- You can use
forge
to install the dependencies (recommended):
- Otherwise you can use NPM to install the dependencies, there are two packages required:
Modify the foundry.toml
to include node_modules
directory:
Development
You may refer to the OVM Cal PI repository for a sample smart contract that calculates the value of PI on-chain.
Initialization
The constructor initializes the smart contract with the specification of the task to be executed. For more details, refer to the OVM Contract Specification.
Additionally, admin
address is also defined in the constructor for collecting royalty fees.
Send Request
Here is an example of how to send a request to calculate the value of PI with a given number of digits:
This function sends a request to the OVM gateway contract, which then allocates the optimal executor to execute the task.
You can define a function with any params, just remember to encode all these params to a bytes
type.
Set Response
The interface function setResponse(bytes32 requestId, bytes calldata data)
must be implemented in order to receive the returned response of task execution.
Similarly, you need to decode the response here.
Conclusion
In this guide, we demonstrated how to publish an OVM task by building a smart contract that specifies the computation to be executed, the environment in which it should run, and the requirements for the execution.
You can now develop your smart contract with OVM to access high-performance compute resources for complex computations, AI training, and scientific simulations.