Build a simple task
This guide provides step-by-step instructions on how to build and deploy a task to automate a blockchain operation using Mimic Protocol.
Before you begin, ensure you have installed both Mimic’s lib and CLI:
Workflow overview
The process consists of the following steps:
Define the manifest: Specify task inputs, triggers, and metadata in a manifest file.
Write the task logic: Implement your task logic.
Build: Validate the manifest, generate supporting artifacts, and compile the task logic.
Deploy: Upload your build output to a task registry, making it available for relayers to execute.
Manifest definition
The manifest file provides the configuration for your task, including:
Metadata: Name, description, and version of the task.
Triggers: When the task should run (e.g., cron schedules or event-based triggers).
Inputs: Parameters required by the task logic.
ABIs: Smart contract ABIs to generate type-safe interfaces for the task.
Save this configuration in a manifest.yaml
file:
This manifest file defines different inputs that will be accessible from the task logic code thanks to the types generation process that will be explained in the next section.
Additionally, it defines a trigger option using a cron schedule. For now, only cron schedule configurations are allowed, later on event triggered tasks will be supported too.
Finally it declares the path for the ERC20 ABI required by the task logic. Similar to the inputs list, the ABIs will be processed to generate the proper types to access them from the codebase.
Generate types
This steps allows you to validate the manifest definitions and generate the corresponding code to access both your declared inputs and the contract objects for your declared ABIs.
To do this you can run the codegen
command using the CLI:
This command will output the generated types to the types
directory by default. It will also assume your manifest file is called manifest.yaml
. However, you can specify a different manifest or output paths using the following parameters:
Writing the task logic
The task logic is implemented in AssemblyScript and must export:
Input type: The generated
TaskInput
type from the previous step.Main function: The core task logic, which receives the inputs as an argument.
Create a file ./src/task.ts
and implement the logic:
As you can see, the generated contract objects can be accessed from your task code.
For now Mimic tasks allows creating three types of intents:
Transfers
Single-chain swaps
Cross-chain swaps
Build process
The build process converts your task logic and manifest into deployable artifacts:
task.wasm
: The compiled WebAssembly binary of your task.manifest.yaml
: The validated manifest.inputs.json
: A list of required dependencies for relayers.
Run the build command:
By default, outputs are saved in the build
directory. You can customize the paths:
Here is an example of the output produced by this command:
Deploy your task
This is where you upload your task artifacts to the network so others can discover it. To do this you can run the deploy
command using the CLI:
You can generate a deployment key from the explorer app, where you can login using your wallet.
This command will deploy the generated artifacts from the build
directory by default. However, you can specify a path using the following parameter:
This command will basically upload your artifacts to IPFS and pin the resultant CID into the off-chain tasks registry so it can be discovered by others.
Add your task to your project
Once you’ve deployed the task, the next step is to associate it with a project. A project is a container in the Mimic explorer where you can manage multiple tasks, configs, and access controls. In order to create a project simply:
Go to the Mimic explorer.
Sign in with your wallet.
Create a new project or choose an existing one.
Finally, link your deployed task by running:
Replace [PROJECT_KEY]
with the key of your newly created project, and [DEPLOYMENT_KEY]
with your account’s deployment key from the explorer.
Config your task
After linking, you need to configure your task to tell which config relayers should use to run your task. This means defining the parameters declared in your manifest.yml
file. This configuration is typically done in the explorer UI where you will be requested to sign your config with your wallet.
Open your project in the explorer and locate the task you just linked under the tasks section.
Add or edit your config parameters
Sign the new config
This signature ensures relayers know the config is authorized by the task owner.
You can update or deprecate this config at any point in time to reflect changes, without needing to redeploy the task code again. Just sign the new config in the explorer, and relayers will pick up the latest version.
Next steps
Learn about available APIs for creating intents and interacting with contracts.
Discover advanced CLI commands for testing, validating, and managing tasks.
Build more complex use cases Expand your automation to include cross-chain swaps, event triggers, and more.
Last updated