⏩Using a Smart Contract
Using a Smart contract
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 AutomateTaskCreator
which has helper functions to easily create your task.
Pass the
Module.PROXY
&Module.WEB3_FUNCTION
as modules inModuleData
Use
_web3FunctionModuleArg
to encode arguments forWEB3_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
.
The full code can be found here.
Additional Info
Tasks created via this route cannot be named
Smart Contracts can also create and cancel tasks.
You can find a list of example smart contracts here.
Here are the functions exposed by AutomateTaskCreator
which you can use when setting up your smart contract.
_createTask()
_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
- Useaddress(0)
if using Gelato 1balance. Use 0xeeeeee... for ETH or native tokens.
ModuleData
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.PROXY
- Your function will be called by a dedicatedmsg.sender
.Dedicated msg.senderSINGLE_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.
Including Module.Proxy
in moduleData
is mandatory, otherwise task creation will fail.
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()
_cancelTask()
Cancels a task owned by the smart contract.
onlyDedicatedMsgSender
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()
_depositFunds1Balance()
Deposit funds into the Gelato 1balance contract.
The _depositFunds1Balance
method is only available on Polygon
Single Execution Task
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 here.
Last updated