Using a Smart Contract
Last updated
Last updated
You can create a task that uses Web3 Function from your smart contract as well.
If your project involves complex interactions and you need the task creation to be a part of an on-chain transaction, you would directly interact with a smart contract.
Web3 Function secrets are not available for smart contract created tasks.
To create a Web3 Function task with your smart contract, you can inherit which has helper functions to easily create your task.
Pass the Module.PROXY
& Module.WEB3_FUNCTION
as modules in ModuleData
Use _web3FunctionModuleArg
to encode arguments for WEB3_FUNCTION
module.
Here is how you can encode your Web3Function arguments to get web3FunctionArgsHex.
In this example, the Web3Function has 2 arguments, counterW3fAddress
& count
.
In your contract, you would encode the arguments according to the sequence defined in schema.json
.
Tasks created via this route cannot be named
Smart Contracts can also create and cancel tasks.
Here are the functions exposed by AutomateTaskCreator
which you can use when setting up your smart contract.
_createTask()
Interacts and creates a task on the Gelato Automate smart contract.
execAddress
- Address of the contract which Gelato will call.
execDataOrSelector
- Signature of function which Gelato will call / execution data (If Resolver Module is not used. More about modules below)
moduleData
- Modules that are enabled for the task. (More about ModuleData below)
feeToken
- Use address(0)
if using Gelato 1balance. Use 0xeeeeee... for ETH or native tokens.
Modules are conditions / specifications about your task. These are the current available Modules.
RESOLVER
- Define dynamic conditions and execution data.
TIME
- Repeated execution at a specific time and interval. (in ms)
PROXY
- Your function will be called by a dedicated msg.sender
.
SINGLE_EXEC
- Task is cancelled after one execution.
WEB3_FUNCTION
- Define a Typescript function to get off-chain execution data.
TRIGGER
- Define your execution trigger (Time interval, Event, every block, ...)
Each Module would require additional arguments which is an encoded data.
You can use these helper functions to get the arguments for each Module.
Crafting ModuleData
will look like this if we want to create a task which utilise RESOLVER
,PROXY
& SINGLE_EXEC
Module.
Module[]
must follow the order RESOLVER
, PROXY
, SINGLE_EXEC,
WEB3_FUNCTION, TRIGGER
_cancelTask()
Cancels a task owned by the smart contract.
onlyDedicatedMsgSender
Function modifier to restrict msg.sender
to only task executions created by taskCreator
(defined in constructor). Learn more about it at Security Considerations
_depositFunds1Balance()
Deposit funds into the Gelato 1balance contract.
The full code can be found .
You can find a list of example smart contracts .
If you want to have Gelato call your function only once. If so, you can Include SingleExec
module in ModuleData.modules
. Check out the full code .