Skip to content

Commit da8b29a

Browse files
committed
refactor: clarify and streamline the Result Callback guide for better understanding
1 parent eb1e100 commit da8b29a

File tree

1 file changed

+28
-24
lines changed

1 file changed

+28
-24
lines changed

src/guides/build-iapp/advanced/result-callback.md

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,41 @@
11
---
22
title: Result Callback Guide
33
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+
Use the iExec result callback to have the protocol invoke a function on your
5+
smart contract at the end of an (optionally confidential TEE) task execution.
76
---
87

98
# Result Callback
109

11-
This guide explains how to securely push an iExec task result into a smart
12-
contract using the callback mechanism.
10+
This guide explains how to trigger a callback function at the end of a
11+
successful task on your smart contract.
12+
1313
Use a callback when a smart contract should:
1414

1515
- Ingest off-chain computed data (API aggregation, ML inference, analytics) and
16-
persist it on-chain
16+
persist it
1717
- React to an execution outcome (conditional trigger, state transition)
1818
- Store a timestamped record (price feed, score, KPI, proof hash)
19-
- Act as a logic bridge between external systems and on-chain logic
19+
- Bridge logic between external systems and on-chain state
2020

2121
## 🧩 High-Level Flow
2222

23-
1. A requester executes an iApp on iExec.
23+
1. A requester executes an iApp.
2424
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.
28-
4. Your callback smart contract (receiver) ingests the data.
25+
(ABI‑encoded bytes you crafted).
26+
3. Once the task is completed and validated, the iExec protocol invokes your
27+
contract’s `receiveResult(bytes32,bytes)`.
28+
4. Your contract decodes and processes those bytes if callback data have been
29+
pushed.
2930

3031
## Step-by-Step Implementation
3132

32-
### Step 1: Write the iApp
33-
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+
### Step 1: Prepare the Callback Payload in the iApp
3834

39-
Replaced Web3.js example with ethers v6:
35+
You only need to write `computed.json` containing the key `callback-data`.
36+
That value must be the ABI‑encoded bytes your contract knows how to decode.
37+
Example schema we’ll use: (uint256 timestamp, string pairAndPrecision, uint256
38+
scaledValue).
4039

4140
```ts twoslash
4241
import { writeFileSync } from 'node:fs';
@@ -53,7 +52,7 @@ async function main() {
5352
const abiCoder = new AbiCoder();
5453
const abiPayload = abiCoder.encode(
5554
['uint256', 'string', 'uint256'],
56-
[timestamp, `${pair}`, scaled]
55+
[timestamp, pair, scaled]
5756
);
5857

5958
writeFileSync(
@@ -65,11 +64,16 @@ async function main() {
6564
}
6665
```
6766

68-
### Step 2: Deploy the Callback Contract
67+
### Step 2: Implement the Callback Contract
68+
69+
Your contract must expose `receiveResult(bytes32,bytes)` (ERC1154). The protocol
70+
calls it with:
71+
72+
- `_callID`: the task / call identifier.
73+
- `callback`: exactly the bytes you encoded as `callback-data`.
6974

70-
The callback contract receives and processes the off-chain result. Your contract
71-
must implement `receiveResult(bytes32,bytes)`interface from
72-
[ERC1154](https://github.com/iExecBlockchainComputing/iexec-solidity/blob/master/contracts/ERC1154/IERC1154.sol)
75+
You decode using the same tuple. Add (optional) protections: authorized caller
76+
check (the iExec hub / proxy address), replay guard, bounds checks.
7377

7478
```solidity
7579
contract IExecCallbackReceiver {

0 commit comments

Comments
 (0)