-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcreate-task-with-resolver.ts
49 lines (44 loc) · 1.62 KB
/
create-task-with-resolver.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { AutomateSDK, isAutomateSupported, TaskTransaction, TriggerType } from "@gelatonetwork/automate-sdk";
import { Contract } from "ethers";
import hre from "hardhat";
import { COUNTER_ADDRESSES } from "../constants";
import counterAbi from "../contracts/abis/CounterTest.json";
async function main() {
const chainId = hre.network.config.chainId as number;
if (!isAutomateSupported(chainId)) {
console.log(`Gelato Automate network not supported (${chainId})`);
return;
}
// Init AutomateSDK
const [signer] = await hre.ethers.getSigners();
const automate = new AutomateSDK(chainId, signer);
// Prepare Task data to automate
const counter = new Contract(COUNTER_ADDRESSES[chainId], counterAbi, signer);
const selector = counter.interface.getSighash("increaseCount(uint256)");
const resolverData = counter.interface.getSighash("checker()");
// Create task
console.log("Creating Task...");
const { taskId, tx }: TaskTransaction = await automate.createTask({
execAddress: counter.address,
execSelector: selector,
execAbi: JSON.stringify(counterAbi),
resolverAddress: counter.address,
resolverData: resolverData,
resolverAbi: JSON.stringify(counterAbi),
name: "Automated counter with resolver",
dedicatedMsgSender: true,
trigger: {
interval: 60 * 1000,
type: TriggerType.TIME,
},
});
await tx.wait();
console.log(`Task created, taskId: ${taskId} (tx hash: ${tx.hash})`);
console.log(`> https://app.gelato.network/task/${taskId}?chainId=${chainId}`);
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});