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
Copy file name to clipboardExpand all lines: src/guides/build-iapp/advanced/result-callback.md
+57-29Lines changed: 57 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,57 +1,77 @@
1
1
---
2
2
title: Result Callback Guide
3
-
description: Practical guide to using the iExec Result Callback mechanism to push an off-chain task result (iApp) directly into a smart contract—Oracles, automation, triggers, proofs, and more.
3
+
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.).
4
4
---
5
5
6
6
# Result Callback
7
7
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 the possible use cases.
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
10
11
11
## When to Use a Callback
12
12
13
-
Use a callback whenever a smart contract should:
13
+
Use a callback when a smart contract should:
14
14
15
-
-Consume off-chain computed data (API aggregation, ML inference, analytics) and store it on-chain
16
-
- React on-chain to an execution outcome (conditional trigger, state transition)
17
-
- Store a timestamped record (price feed, score, KPI, proof hash) on-chain
15
+
-Ingest off-chain computed data (API aggregation, ML inference, analytics) and persist it on-chain
16
+
- React to an execution outcome (conditional trigger, state transition)
17
+
- Store a timestamped record (price feed, score, KPI, proof hash)
18
18
- Act as a logic bridge between external systems and on-chain logic
19
19
20
20
## 🧩 High-Level Flow
21
21
22
22
1. A requester executes an iApp on iExec.
23
-
2. The iApp writes in the file `${IEXEC_OUT}/computed.json`under the filed `callback-data`the necessary calldata to make on-chain call.
24
-
3. iExec decentralized Protocol trigger corresponding on-chain contract based on the deal & task result `callback-data` field.
25
-
4. Your smart contract (receiver) callback data, verifies, and ingests it.
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.
25
+
4. Your callback smart contract (receiver) ingests the data.
26
26
27
27
## Step-by-Step Implementation
28
28
29
29
### Step 1: Write the iApp
30
30
31
-
Your iApp must write a JSON file named `computed.json` in the directory pointed to by the environment variable `IEXEC_OUT`. This file must contain at least the key `callback-data`, which holds the ABI-encoded data you want to send to your smart contract.
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).
33
+
34
+
Replaced Web3.js example with ethers v6:
32
35
33
36
```js
34
-
importfsfrom'node:fs';
35
-
importWeb3from'web3';
36
-
constweb3=newWeb3();
37
+
// ethers v6 example producing ABI-encoded callback data
38
+
39
+
import { writeFileSync } from'node:fs';
40
+
import { AbiCoder } from'ethers';
41
+
42
+
// Placeholder: replace with real price retrieval / aggregation logic
When running the iApp, specify the callback contract address in the deal parameters. The iExec protocol will automatically call the specified contract with the `callback-data` once the task is completed.
110
+
When requesting the execution, set the callback contract address in the deal (or order) parameters.
111
+
After completion, the protocol calls your contract passing the `callback-data` bytes.
112
+
113
+
Checklist:
114
+
115
+
- Ensure the contract adheres to the expected callback function signature.
116
+
- Guard against replay (e.g. track processed task IDs).
117
+
- Validate business invariants (timestamps, ranges, freshness).
0 commit comments