You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: Guide to using the iExec result callback to push an off-chain iApp task result directly into a smart contract (price feeds, automation, triggers, proofs, scoring, etc.).
3
+
description:
4
+
Guide to using the iExec result callback to push an off-chain iApp task result
5
+
directly into a smart contract (price feeds, automation, triggers, proofs,
6
+
scoring, etc.).
4
7
---
5
8
6
9
# Result Callback
7
10
8
-
This guide explains how to securely push an iExec task result into a smart contract using the callback mechanism.
9
-
Oracles are only one of many possible use cases.
10
-
11
-
## When to Use a Callback
12
-
11
+
This guide explains how to securely push an iExec task result into a smart
12
+
contract using the callback mechanism.
13
13
Use a callback when a smart contract should:
14
14
15
-
- Ingest off-chain computed data (API aggregation, ML inference, analytics) and persist it on-chain
15
+
- Ingest off-chain computed data (API aggregation, ML inference, analytics) and
16
+
persist it on-chain
16
17
- React to an execution outcome (conditional trigger, state transition)
17
18
- Store a timestamped record (price feed, score, KPI, proof hash)
18
19
- Act as a logic bridge between external systems and on-chain logic
19
20
20
21
## 🧩 High-Level Flow
21
22
22
23
1. A requester executes an iApp on iExec.
23
-
2. The iApp writes `${IEXEC_OUT}/computed.json` with a `callback-data` field containing ABI‑encoded calldata.
24
-
3. The iExec protocol, once the task is completed, invokes the specified callback contract with that data.
24
+
2. The iApp writes `${IEXEC_OUT}/computed.json` with a `callback-data` field
25
+
containing ABI‑encoded calldata.
26
+
3. The iExec protocol, once the task is completed, invokes the specified
27
+
callback contract with that data.
25
28
4. Your callback smart contract (receiver) ingests the data.
26
29
27
30
## Step-by-Step Implementation
28
31
29
32
### Step 1: Write the iApp
30
33
31
-
The iApp MUST write a file named `computed.json` in the directory pointed to by `IEXEC_OUT`.
32
-
Required key: `callback-data` (raw ABI‑encoded bytes you want passed to your contract).
34
+
The iApp MUST write a file named `computed.json` in the directory pointed to by
35
+
`IEXEC_OUT`.
36
+
Required key: `callback-data` (raw ABI‑encoded bytes you want passed to your
37
+
contract).
33
38
34
39
Replaced Web3.js example with ethers v6:
35
40
36
-
```js
37
-
// ethers v6 example producing ABI-encoded callback data
38
-
41
+
```ts twoslash
39
42
import { writeFileSync } from'node:fs';
40
43
import { AbiCoder } from'ethers';
41
44
42
-
// Placeholder: replace with real price retrieval / aggregation logic
0 commit comments