sdk-triggerx 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/.eslintrc.json +16 -0
  2. package/README.md +249 -0
  3. package/dist/api/jobs.d.ts +15 -0
  4. package/dist/api/jobs.js +138 -0
  5. package/dist/api/tasks.d.ts +4 -0
  6. package/dist/api/tasks.js +13 -0
  7. package/dist/client.d.ts +7 -0
  8. package/dist/client.js +27 -0
  9. package/dist/config.d.ts +6 -0
  10. package/dist/config.js +15 -0
  11. package/dist/contracts/JobRegistry.d.ts +12 -0
  12. package/dist/contracts/JobRegistry.js +26 -0
  13. package/dist/contracts/TriggerXContract.d.ts +6 -0
  14. package/dist/contracts/TriggerXContract.js +14 -0
  15. package/dist/contracts/abi/JobRegistry.json +1554 -0
  16. package/dist/contracts/index.d.ts +1 -0
  17. package/dist/contracts/index.js +17 -0
  18. package/dist/index.d.ts +8 -0
  19. package/dist/index.js +26 -0
  20. package/dist/src/api/checkTgBalance.d.ts +2 -0
  21. package/dist/src/api/checkTgBalance.js +35 -0
  22. package/dist/src/api/deleteJob.d.ts +2 -0
  23. package/dist/src/api/deleteJob.js +20 -0
  24. package/dist/src/api/getJobDataById.d.ts +3 -0
  25. package/dist/src/api/getJobDataById.js +21 -0
  26. package/dist/src/api/getUserData.d.ts +3 -0
  27. package/dist/src/api/getUserData.js +21 -0
  28. package/dist/src/api/getjob.d.ts +8 -0
  29. package/dist/src/api/getjob.js +23 -0
  30. package/dist/src/api/jobs.d.ts +18 -0
  31. package/dist/src/api/jobs.js +270 -0
  32. package/dist/src/api/tasks.d.ts +4 -0
  33. package/dist/src/api/tasks.js +13 -0
  34. package/dist/src/api/topupTg.d.ts +2 -0
  35. package/dist/src/api/topupTg.js +19 -0
  36. package/dist/src/api/withdrawTg.d.ts +8 -0
  37. package/dist/src/api/withdrawTg.js +27 -0
  38. package/dist/src/client.d.ts +10 -0
  39. package/dist/src/client.js +37 -0
  40. package/dist/src/config.d.ts +6 -0
  41. package/dist/src/config.js +15 -0
  42. package/dist/src/contracts/JobRegistry.d.ts +12 -0
  43. package/dist/src/contracts/JobRegistry.js +24 -0
  44. package/dist/src/contracts/TriggerXContract.d.ts +6 -0
  45. package/dist/src/contracts/TriggerXContract.js +14 -0
  46. package/dist/src/contracts/abi/GasRegistry.json +607 -0
  47. package/dist/src/contracts/abi/JobRegistry.json +1554 -0
  48. package/dist/src/contracts/index.d.ts +1 -0
  49. package/dist/src/contracts/index.js +17 -0
  50. package/dist/src/index.d.ts +7 -0
  51. package/dist/src/index.js +25 -0
  52. package/dist/src/types.d.ts +246 -0
  53. package/dist/src/types.js +15 -0
  54. package/dist/src/utils/errors.d.ts +4 -0
  55. package/dist/src/utils/errors.js +17 -0
  56. package/dist/test/createJobExample.d.ts +1 -0
  57. package/dist/test/createJobExample.js +77 -0
  58. package/dist/test/deleteJob.test.d.ts +1 -0
  59. package/dist/test/deleteJob.test.js +22 -0
  60. package/dist/test/example.test.d.ts +1 -0
  61. package/dist/test/example.test.js +11 -0
  62. package/dist/test/getJobDataById.test.d.ts +1 -0
  63. package/dist/test/getJobDataById.test.js +23 -0
  64. package/dist/test/getUserData.test.d.ts +1 -0
  65. package/dist/test/getUserData.test.js +22 -0
  66. package/dist/test/getjob.test.d.ts +1 -0
  67. package/dist/test/getjob.test.js +21 -0
  68. package/dist/test/testTgFunctions.d.ts +1 -0
  69. package/dist/test/testTgFunctions.js +56 -0
  70. package/dist/types.d.ts +134 -0
  71. package/dist/types.js +15 -0
  72. package/dist/utils/errors.d.ts +4 -0
  73. package/dist/utils/errors.js +17 -0
  74. package/jest.config.js +7 -0
  75. package/package.json +32 -0
  76. package/scripts/deploy.ts +9 -0
  77. package/src/api/checkTgBalance.ts +27 -0
  78. package/src/api/deleteJob.ts +22 -0
  79. package/src/api/getJobDataById.ts +24 -0
  80. package/src/api/getUserData.ts +24 -0
  81. package/src/api/getjob.ts +26 -0
  82. package/src/api/jobs.ts +303 -0
  83. package/src/api/topupTg.ts +17 -0
  84. package/src/api/withdrawTg.ts +25 -0
  85. package/src/client.ts +38 -0
  86. package/src/config.ts +16 -0
  87. package/src/contracts/JobRegistry.ts +45 -0
  88. package/src/contracts/TriggerXContract.ts +14 -0
  89. package/src/contracts/abi/.gitkeep +1 -0
  90. package/src/contracts/abi/GasRegistry.json +607 -0
  91. package/src/contracts/abi/JobRegistry.json +1554 -0
  92. package/src/contracts/index.ts +1 -0
  93. package/src/index.ts +7 -0
  94. package/src/types.ts +262 -0
  95. package/src/utils/errors.ts +13 -0
  96. package/test/createJobExample.ts +84 -0
  97. package/test/deleteJob.test.ts +25 -0
  98. package/test/example.test.d.ts +1 -0
  99. package/test/example.test.js +11 -0
  100. package/test/example.test.ts +10 -0
  101. package/test/getJobDataById.test.ts +27 -0
  102. package/test/getUserData.test.ts +25 -0
  103. package/test/getjob.test.ts +23 -0
  104. package/test/testTgFunctions.ts +56 -0
  105. package/tsconfig.json +16 -0
@@ -0,0 +1 @@
1
+ export * from './TriggerXContract';
package/src/index.ts ADDED
@@ -0,0 +1,7 @@
1
+ export * from './client';
2
+ export * from './config';
3
+ export * from './types';
4
+ export * from './api/jobs';
5
+ export { createJobOnChain } from './contracts/JobRegistry';
6
+ export * from './contracts';
7
+ export * from './utils/errors';
package/src/types.ts ADDED
@@ -0,0 +1,262 @@
1
+ export interface Task {
2
+ id: string;
3
+ name: string;
4
+ status: 'pending' | 'completed' | 'failed';
5
+ createdAt: string;
6
+ }
7
+
8
+ export interface ApiResponse<T> {
9
+ data: T;
10
+ error?: string;
11
+ }
12
+
13
+ // Enums for job type and argument type
14
+ export enum JobType {
15
+ Time = 'time',
16
+ Event = 'event',
17
+ Condition = 'condition',
18
+ }
19
+
20
+ export enum ArgType {
21
+ Static = 'static',
22
+ Dynamic = 'dynamic',
23
+ }
24
+
25
+ // Discriminated union for job input
26
+ export type CreateJobInput =
27
+ | (TimeBasedJobInput & { jobType: JobType.Time; argType: ArgType.Static | ArgType.Dynamic })
28
+ | (EventBasedJobInput & { jobType: JobType.Event; argType: ArgType.Static | ArgType.Dynamic })
29
+ | (ConditionBasedJobInput & { jobType: JobType.Condition; argType: ArgType.Static | ArgType.Dynamic });
30
+
31
+ // User-facing input types (without jobType/argType)
32
+ export interface TimeBasedJobInput {
33
+ userAddress: string;
34
+ etherBalance: BigInt | number;
35
+ tokenBalance: BigInt | number;
36
+ jobTitle: string;
37
+ timeFrame: number;
38
+ scheduleType: 'cron' | 'specific' | 'interval';
39
+ timeInterval?: number;
40
+ cronExpression?: string;
41
+ specificSchedule?: string;
42
+ timezone: string;
43
+ recurring?: boolean;
44
+ jobCostPrediction: number;
45
+ createdChainId: string;
46
+ targetChainId: string;
47
+ targetContractAddress: string;
48
+ targetFunction: string;
49
+ abi: string;
50
+ isImua?: boolean;
51
+ arguments?: string[];
52
+ dynamicArgumentsScriptUrl?: string;
53
+ autotopupTG?: boolean;
54
+ }
55
+
56
+ export interface EventBasedJobInput {
57
+ userAddress: string;
58
+ etherBalance: BigInt | number;
59
+ tokenBalance: BigInt | number;
60
+ jobTitle: string;
61
+ timeFrame: number;
62
+ triggerChainId: string;
63
+ triggerContractAddress: string;
64
+ triggerEvent: string;
65
+ timezone: string;
66
+ recurring?: boolean;
67
+ jobCostPrediction: number;
68
+ createdChainId: string;
69
+ targetChainId: string;
70
+ targetContractAddress: string;
71
+ targetFunction: string;
72
+ abi: string;
73
+ isImua?: boolean;
74
+ arguments?: string[];
75
+ dynamicArgumentsScriptUrl?: string;
76
+ autotopupTG?: boolean;
77
+ }
78
+
79
+ export interface ConditionBasedJobInput {
80
+ userAddress: string;
81
+ etherBalance: BigInt | number;
82
+ tokenBalance: BigInt | number;
83
+ jobTitle: string;
84
+ timeFrame: number;
85
+ conditionType: string;
86
+ upperLimit: number;
87
+ lowerLimit: number;
88
+ valueSourceType: string;
89
+ valueSourceUrl: string;
90
+ timezone: string;
91
+ recurring?: boolean;
92
+ jobCostPrediction: number;
93
+ createdChainId: string;
94
+ targetChainId: string;
95
+ targetContractAddress: string;
96
+ targetFunction: string;
97
+ abi: string;
98
+ isImua?: boolean;
99
+ arguments?: string[];
100
+ dynamicArgumentsScriptUrl?: string;
101
+ autotopupTG?: boolean;
102
+ }
103
+
104
+ // Internal type matching backend struct
105
+ export interface CreateJobData {
106
+ job_id: string;
107
+ user_address: string;
108
+ ether_balance: BigInt | number;
109
+ token_balance: BigInt | number;
110
+ job_title: string;
111
+ task_definition_id: number;
112
+ custom: boolean;
113
+ time_frame: number;
114
+ recurring: boolean;
115
+ job_cost_prediction: number;
116
+ timezone: string;
117
+ created_chain_id: string;
118
+ schedule_type?: string;
119
+ time_interval?: number;
120
+ cron_expression?: string;
121
+ specific_schedule?: string;
122
+ trigger_chain_id?: string;
123
+ trigger_contract_address?: string;
124
+ trigger_event?: string;
125
+ condition_type?: string;
126
+ upper_limit?: number;
127
+ lower_limit?: number;
128
+ value_source_type?: string;
129
+ value_source_url?: string;
130
+ target_chain_id: string;
131
+ target_contract_address: string;
132
+ target_function: string;
133
+ abi: string;
134
+ arg_type: number;
135
+ arguments?: string[];
136
+ dynamic_arguments_script_url?: string;
137
+ is_imua: boolean;
138
+ }
139
+
140
+ export interface JobResponse {
141
+ success: boolean;
142
+ data?: any;
143
+ error?: string;
144
+ }
145
+
146
+ // Types matching backend JobResponseAPI
147
+ export interface JobDataAPI {
148
+ job_id: string; // Assuming BigIntString is represented as a string in TypeScript
149
+ job_title: string;
150
+ task_definition_id: number;
151
+ user_id: number; // Assuming int64 is represented as number
152
+ link_job_id: string; // Assuming BigIntString is represented as a string
153
+ chain_status: number;
154
+ custom: boolean;
155
+ time_frame: number; // Assuming int64 is represented as number
156
+ recurring: boolean;
157
+ status: string;
158
+ job_cost_prediction: number;
159
+ job_cost_actual: number;
160
+ task_ids: number[]; // Assuming []int64 is represented as number[]
161
+ created_at: Date; // Assuming time.Time is represented as Date
162
+ updated_at: Date; // Assuming time.Time is represented as Date
163
+ last_executed_at: Date; // Assuming time.Time is represented as Date
164
+ timezone: string;
165
+ is_imua: boolean;
166
+ created_chain_id: string;
167
+ }
168
+
169
+ export interface TimeJobData {
170
+ job_id: string; // Assuming *big.Int is represented as string
171
+ task_definition_id: number;
172
+ expiration_time: Date; // Assuming time.Time is represented as Date
173
+ created_at: Date; // Assuming time.Time is represented as Date
174
+ updated_at: Date; // Assuming time.Time is represented as Date
175
+ time_interval: number; // Assuming int64 is represented as number
176
+ schedule_type: string;
177
+ cron_expression: string;
178
+ specific_schedule: string;
179
+ timezone: string;
180
+ next_execution_timestamp: Date; // Assuming time.Time is represented as Date
181
+ target_chain_id: string;
182
+ target_contract_address: string;
183
+ target_function: string;
184
+ abi: string;
185
+ arg_type: number;
186
+ arguments: string[];
187
+ dynamic_arguments_script_url: string;
188
+ is_completed: boolean;
189
+ is_active: boolean;
190
+ }
191
+
192
+ export interface EventJobData {
193
+ job_id: string; // Assuming *big.Int is represented as string
194
+ task_definition_id: number;
195
+ expiration_time: Date; // Assuming time.Time is represented as Date
196
+ created_at: Date; // Assuming time.Time is represented as Date
197
+ updated_at: Date; // Assuming time.Time is represented as Date
198
+ recurring: boolean;
199
+ trigger_chain_id: string;
200
+ trigger_contract_address: string;
201
+ trigger_event: string;
202
+ target_chain_id: string;
203
+ target_contract_address: string;
204
+ target_function: string;
205
+ abi: string;
206
+ arg_type: number;
207
+ arguments: string[];
208
+ dynamic_arguments_script_url: string;
209
+ is_completed: boolean;
210
+ is_active: boolean;
211
+ }
212
+
213
+ export interface ConditionJobData {
214
+ job_id: string; // Assuming *big.Int is represented as string
215
+ task_definition_id: number;
216
+ expiration_time: Date; // Assuming time.Time is represented as Date
217
+ created_at: Date; // Assuming time.Time is represented as Date
218
+ updated_at: Date; // Assuming time.Time is represented as Date
219
+ recurring: boolean;
220
+ condition_type: string;
221
+ upper_limit: number; // Assuming float64 is represented as number
222
+ lower_limit: number; // Assuming float64 is represented as number
223
+ value_source_type: string;
224
+ value_source_url: string;
225
+ target_chain_id: string;
226
+ target_contract_address: string;
227
+ target_function: string;
228
+ abi: string;
229
+ arg_type: number;
230
+ arguments: string[];
231
+ dynamic_arguments_script_url: string;
232
+ is_completed: boolean;
233
+ is_active: boolean;
234
+ }
235
+
236
+ export interface JobResponseUser {
237
+ success: boolean;
238
+ error?: string;
239
+ jobs?: JobResponseAPI
240
+ }
241
+
242
+ export interface JobResponseAPI {
243
+ job_data?: JobDataAPI;
244
+ time_job_data?: TimeJobData;
245
+ event_job_data?: EventJobData;
246
+ condition_job_data?: ConditionJobData;
247
+ }
248
+
249
+ // New interface for user data response
250
+ export interface UserData {
251
+ user_id: number; // Assuming int64 is represented as number
252
+ user_address: string;
253
+ job_ids: string[]; // Assuming job IDs are represented as strings
254
+ ether_balance: BigInt | number;
255
+ token_balance: BigInt | number;
256
+ user_points: number;
257
+ total_jobs: number; // Assuming int64 is represented as number
258
+ total_tasks: number; // Assuming int64 is represented as number
259
+ created_at: Date; // Assuming time.Time is represented as Date
260
+ last_updated_at: Date; // Assuming time.Time is represented as Date
261
+ email: string; // Assuming email_id is represented as string
262
+ }
@@ -0,0 +1,13 @@
1
+ export class TriggerXError extends Error {
2
+ constructor(message: string) {
3
+ super(message);
4
+ this.name = 'TriggerXError';
5
+ }
6
+ }
7
+
8
+ export function wrapError(error: unknown): TriggerXError {
9
+ if (error instanceof Error) {
10
+ return new TriggerXError(error.message);
11
+ }
12
+ return new TriggerXError('Unknown error');
13
+ }
@@ -0,0 +1,84 @@
1
+ import { TriggerXClient, createJob } from '../src';
2
+ import { JobType, ArgType, CreateJobInput } from '../src/types';
3
+ import { ethers } from 'ethers';
4
+
5
+ async function main() {
6
+
7
+ const apiKey = 'TGRX-ece02db8-f676-4a9f-a4f8-a95f59e755d8';
8
+ const client = new TriggerXClient(apiKey);
9
+
10
+ // Example: Time-based static job
11
+ const jobInput: CreateJobInput = {
12
+ jobType: JobType.Time,
13
+ argType: ArgType.Static,
14
+ userAddress: '0x7Db951c0E6D8906687B459427eA3F3F2b456473B',
15
+ etherBalance: 50000000000000000,
16
+ tokenBalance: 50000000000000000000,
17
+ jobTitle: 'SDK Test Time Job',
18
+ timeFrame: 36,
19
+ scheduleType: 'interval',
20
+ timeInterval: 33,
21
+ cronExpression: '0 0 * * *',
22
+ specificSchedule: '2025-01-01 00:00:00',
23
+ timezone: 'Asia/Calcutta',
24
+ recurring: false,
25
+ jobCostPrediction: 0.1,
26
+ createdChainId: '11155420',
27
+ targetChainId: '11155420',
28
+ targetContractAddress: '0x49a81A591afdDEF973e6e49aaEa7d76943ef234C',
29
+ targetFunction: 'incrementBy',
30
+ abi: '[{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"previousValue","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newValue","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"incrementAmount","type":"uint256"}],"name":"CounterIncremented","type":"event"},{"inputs":[],"name":"getCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"increment","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"incrementBy","outputs":[],"stateMutability":"nonpayable","type":"function"}]',
31
+ isImua: true,
32
+ arguments: ['3'],
33
+ dynamicArgumentsScriptUrl: '',
34
+ };
35
+
36
+ // // Example: Condition-based static job
37
+ // const jobInput: CreateJobInput = {
38
+ // jobType: JobType.Condition,
39
+ // argType: ArgType.Static,
40
+ // userAddress: '0x7Db951c0E6D8906687B459427eA3F3F2b456473B',
41
+ // etherBalance: 50000000000000000,
42
+ // tokenBalance: 50000000000000000000,
43
+ // jobTitle: 'SDK Test Condition Job',
44
+ // timeFrame: 48,
45
+ // conditionType: 'greaterThan',
46
+ // upperLimit: 100,
47
+ // lowerLimit: 10,
48
+ // valueSourceType: 'http',
49
+ // valueSourceUrl: 'https://api.example.com/value',
50
+ // timezone: 'Asia/Calcutta',
51
+ // recurring: false,
52
+ // jobCostPrediction: 0.1,
53
+ // createdChainId: '11155420',
54
+ // targetChainId: '11155420',
55
+ // targetContractAddress: '0x49a81A591afdDEF973e6e49aaEa7d76943ef234C',
56
+ // targetFunction: 'incrementBy',
57
+ // abi: '[{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"previousValue","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newValue","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"incrementAmount","type":"uint256"}],"name":"CounterIncremented","type":"event"},{"inputs":[],"name":"getCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"increment","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"incrementBy","outputs":[],"stateMutability":"nonpayable","type":"function"}]',
58
+ // isImua: true,
59
+ // arguments: ['5'],
60
+ // dynamicArgumentsScriptUrl: '',
61
+ // };
62
+
63
+ // To test, you can call createJob with this input as well:
64
+ // const conditionResult = await createJob(client, {
65
+ // jobInput: conditionJobInput,
66
+ // signer,
67
+ // });
68
+ // console.log('Condition Job creation result:', conditionResult);
69
+
70
+ // These would typically come from env/config/user input
71
+ const privateKey = '3bd66a68dcde6ede3b38ced6de79489a447e0fac1648b749a5001b0aa167d089';
72
+ const providerUrl = 'https://opt-sepolia.g.alchemy.com/v2/m7cIDXzatSUYoiuE1xSY_TnUrK5j9-1W';
73
+ const provider = new ethers.JsonRpcProvider(providerUrl);
74
+ const signer = new ethers.Wallet(privateKey, provider);
75
+
76
+
77
+ const result = await createJob(client, {
78
+ jobInput,
79
+ signer,
80
+ });
81
+ console.log('Job creation result:', result);
82
+ }
83
+
84
+ main().catch(console.error);
@@ -0,0 +1,25 @@
1
+ // sdk-triggerx/test/deleteJob.test.ts
2
+
3
+ import { TriggerXClient } from '../src/client';
4
+ import { deleteJob } from '../src/api/deleteJob';
5
+
6
+ async function main() {
7
+ // The user should provide their actual API key here
8
+ const apiKey = 'TGRX-ece02db8-f676-4a9f-a4f8-a95f59e755d8';
9
+
10
+ // Create the client with the API key
11
+ const client = new TriggerXClient(apiKey);
12
+
13
+ // Specify the job ID to delete
14
+ const jobId = 'YOUR_JOB_ID'; // Replace with an actual job ID for testing
15
+
16
+ try {
17
+ // Call the SDK function to delete the job
18
+ await deleteJob(client, jobId);
19
+ console.log(`Job with ID ${jobId} deleted successfully.`);
20
+ } catch (error) {
21
+ console.error('Error deleting job:', error);
22
+ }
23
+ }
24
+
25
+ main().catch(console.error);
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const errors_1 = require("../src/utils/errors");
4
+ describe('wrapError', () => {
5
+ it('should wrap a standard error', () => {
6
+ const err = new Error('fail');
7
+ const wrapped = (0, errors_1.wrapError)(err);
8
+ expect(wrapped).toBeInstanceOf(Error);
9
+ expect(wrapped.message).toBe('fail');
10
+ });
11
+ });
@@ -0,0 +1,10 @@
1
+ import { wrapError } from '../src/utils/errors';
2
+
3
+ describe('wrapError', () => {
4
+ it('should wrap a standard error', () => {
5
+ const err = new Error('fail');
6
+ const wrapped = wrapError(err);
7
+ expect(wrapped).toBeInstanceOf(Error);
8
+ expect(wrapped.message).toBe('fail');
9
+ });
10
+ });
@@ -0,0 +1,27 @@
1
+ // sdk-triggerx/test/getJobDataById.test.ts
2
+
3
+ import { TriggerXClient } from '../src/client';
4
+ import { getJobDataById } from '../src/api/getJobDataById';
5
+
6
+ async function main() {
7
+ // The user should provide their actual API key here
8
+ const apiKey = 'TGRX-ece02db8-f676-4a9f-a4f8-a95f59e755d8'; // Use a mock API key
9
+
10
+ // Create the client with the API key
11
+ const client = new TriggerXClient(apiKey);
12
+
13
+ // Define a job ID for testing
14
+ const jobId = 'YOUR_JOB_ID'; // Replace with a valid job ID for testing
15
+
16
+ try {
17
+ // Call the SDK function to get job data
18
+ const response = await getJobDataById(client, jobId);
19
+
20
+ // Log the response
21
+ console.log('Job Data:', response);
22
+ } catch (error) {
23
+ console.error('Error fetching job data:', error);
24
+ }
25
+ }
26
+
27
+ main().catch(console.error);
@@ -0,0 +1,25 @@
1
+ // sdk-triggerx/test/getUserData.test.ts
2
+
3
+ import { TriggerXClient } from '../src/client';
4
+ import { getUserData } from '../src/api/getUserData';
5
+
6
+ async function main() {
7
+ // The user should provide their actual API key here
8
+ const apiKey = 'TGRX-ece02db8-f676-4a9f-a4f8-a95f59e755d8';
9
+
10
+ // Create the client with the API key
11
+ const client = new TriggerXClient(apiKey);
12
+
13
+ // Specify the user address to fetch data for
14
+ const userAddress = 'YOUR_USER_ADDRESS'; // Replace with an actual user address for testing
15
+
16
+ try {
17
+ // Call the SDK function to get user data
18
+ const userData = await getUserData(client, userAddress);
19
+ console.log('User Data:', userData);
20
+ } catch (error) {
21
+ console.error('Error fetching user data:', error);
22
+ }
23
+ }
24
+
25
+ main().catch(console.error);
@@ -0,0 +1,23 @@
1
+ import { TriggerXClient } from '../src/client';
2
+ import { getJobData } from '../src/api/getjob';
3
+
4
+ async function main() {
5
+ // The user should provide their actual API key here
6
+ const apiKey = 'TGRX-ece02db8-f676-4a9f-a4f8-a95f59e755d8';
7
+
8
+ // Create the client with the API key
9
+ const client = new TriggerXClient(apiKey);
10
+
11
+ // Call the SDK function to get job data
12
+ const response = await getJobData(client);
13
+
14
+ if (response.success) {
15
+ // Access job_data from the response
16
+ const jobData = response.jobs; // Use optional chaining in case job_data is undefined
17
+ console.log('Job Data:', jobData);
18
+ } else {
19
+ console.error('Error fetching jobs:', response.error);
20
+ }
21
+ }
22
+
23
+ main().catch(console.error);
@@ -0,0 +1,56 @@
1
+ import { ethers } from 'ethers';
2
+ import { topupTg } from '../src/api/topupTg';
3
+ import { checkTgBalance } from '../src/api/checkTgBalance';
4
+ import { withdrawTg } from '../src/api/withdrawTg';
5
+
6
+ async function main() {
7
+ // Replace with your actual provider URL and private key
8
+ const providerUrl = 'https://opt-sepolia.g.alchemy.com/v2/m7cIDXzatSUYoiuE1xSY_TnUrK5j9-1W';
9
+ const privateKey = ''; // Replace with your private key
10
+ const provider = new ethers.JsonRpcProvider(providerUrl);
11
+ const signer = new ethers.Wallet(privateKey, provider);
12
+
13
+ // Test the checkTgBalance function
14
+ try {
15
+ const balance = await checkTgBalance(signer);
16
+ console.log('TG Balance:', balance);
17
+ } catch (error) {
18
+ console.error('Error checking TG balance:', error);
19
+ }
20
+
21
+ // Test the topupTg function
22
+ const tgAmountToTopup = 1; // Amount of TG to purchase
23
+ try {
24
+ const txTopup = await topupTg(tgAmountToTopup, signer);
25
+ console.log('Topup Transaction:', txTopup);
26
+ } catch (error) {
27
+ console.error('Error during topup:', error);
28
+ }
29
+
30
+ // Test the checkTgBalance function
31
+ try {
32
+ const balance = await checkTgBalance(signer);
33
+ console.log('TG Balance:', balance);
34
+ } catch (error) {
35
+ console.error('Error checking TG balance:', error);
36
+ }
37
+
38
+ // Test the withdrawTg function
39
+ const tgAmountToWithdraw = '1'; // Amount of TG to withdraw
40
+ try {
41
+ const txWithdraw = await withdrawTg(signer, tgAmountToWithdraw);
42
+ console.log('Withdraw Transaction:', txWithdraw);
43
+ } catch (error) {
44
+ console.error('Error during withdrawal:', error);
45
+ }
46
+
47
+ // Test the checkTgBalance function
48
+ try {
49
+ const balance = await checkTgBalance(signer);
50
+ console.log('TG Balance:', balance);
51
+ } catch (error) {
52
+ console.error('Error checking TG balance:', error);
53
+ }
54
+ }
55
+
56
+ main().catch(console.error);
package/tsconfig.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "commonjs",
5
+ "outDir": "dist",
6
+ "rootDir": ".",
7
+ "strict": true,
8
+ "esModuleInterop": true,
9
+ "forceConsistentCasingInFileNames": true,
10
+ "skipLibCheck": true,
11
+ "declaration": true,
12
+ "resolveJsonModule": true
13
+ },
14
+ "include": ["src", "test"],
15
+ "exclude": ["node_modules", "dist"]
16
+ }