Sorry! We're working on this page!
We have deloyed the LilypadOnChainJobCreator contract which you can use to trigger running jobs on the lilypad network from other smart contracts.
It works in tandem with the lilypad jobcreator
on-chain which will watch the on-chain contract and manage jobs on behalf of contracts that submit them.
You will need to know the contract address for the on-chain job creator so we can submit transactions to it.
The production controller address is 0x8e136587e3e5266d5244f6aa896E5CAf8E969946
and you can ask it for the address of the on-chain job creator getJobCreatorAddress()
Running a job involves 2 phases:
calling approve
on the ERC-20 contract to allow the solver to spend your tokens
trigger the job via the on chain job manager
Now we know the address of the on-chain job controller - we can ask it for 3 things:
the address of the ERC-20 token contract - getTokenAddress()
how much the required deposit it - getRequiredDeposit()
the address of the solver that will handle running the job for us - getControllerAddress()
Knowing these 3 things means we can call the standard ERC-20 approve
to allow the solver to spend our tokens on our behalf.
Now - we can call the runJob
method of the on chain controller from another contract. This will cause the job-creator service to kick in and do the following things:
check that funds have been approved for the solver
transfer those funds to it's wallet
run the job on lilypad
call the submitResults
method on the on-chain job creator
the on-chain job creator will call the submitResults
of the original calling contract
The following is an example on-chain smart contract:
Here is an example of a script that brings all of this together:
After the job is completed, a job result ID will be displayed in your terminal. The job result can be accessed through the following URL:
Please note that the IPFS link might take some time to display the result.
The Lilypad Hardhat template demonstrates how to use Lilypad within the Hardhat development environment for onchain interactions. It provides the tools and structure needed to deploy smart contracts that interact with Lilypad nodes onchain.
This template includes an example of running a job using the cowsay
module. The cowsay
module is a simple program that generates an ASCII picture of a cow with a message.
You can run this template directly in Gitpod.
The environment will automatically run a preinstall script that checks if Lilypad and Bacalhau are installed. If they are not already present on the user's machine, the script will install them.
Open the Gitpod environment
Run Lilypad:
This script builds Docker services, starts necessary components (Bacalhau, geth), funds the accounts used, deploys the contracts, and sequentially launches Lilypad related services in the background.
This will execute cowsay onchain using Lilypad, with the specified input message.
In a separate terminal, run this command to execute cowsay onchain:
To view the results of the job, refer to this section.
To update the smart contract, you can modify ExampleClient
in contracts/ExampleClient.sol
. Once you've made the changes, run npm run deploy
.