Smart Agents
Build autonomous agents that perform recurring, conditional transactions.
Traditional blockchains often require humans in the loop to execute transactions at the right time or under specific conditions. With Ritual’s scheduling system, we can create autonomous agents that live entirely on-chain and execute complex sets of actions based on the world around them.
In this tutorial, we will:
- Create a smart agent that autonomously executes transactions
- Use the
IScheduler
helper interface to manage agent actions - Configure scheduling parameters to control when and how your agent operates
Import IScheduler for your agent
The IScheduler
interface is Ritual’s convenience library that enables
your agent to schedule and execute autonomous actions.
Your agent can use simple configuration parameters through functions like <IScheduler>.schedule()
to set up its automated behaviors:
Program your agent's recurring actions
The following code shows how to program your agent to execute actions at predetermined intervals.
Your agent can schedule any function call with the appropriate selector and arguments, making it versatile for both simple and complex automated tasks.
With just these two steps, you can create an autonomous agent that executes scheduled transactions!
Your agent’s behavior can be customized through the <IScheduler>.schedule()
parameters:
Parameter | Description |
---|---|
fn | Function to invoke + optional calldata |
maxGasLimit | Max gas limit, in wei , per call |
maxGasPrice | Max gas price, in wei , to pay per call |
maxBlockNumber | Max block number after which subsequent calls are invalidated |
frequency | Number of blocks between each subsequent call |