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
@@ -164,6 +164,16 @@ As described in the general [Custom Instruction guide](/smart-accounts/custom-in
164
164
Behind the scenes, each custom instruction call translates to sending a payment transaction to the `targetContract` address of `value` FLR with attached `data`.
165
165
:::
166
166
167
+
We define the `CustomInstruction` type:
168
+
169
+
```typescript
170
+
exporttypeCustomInstruction= {
171
+
targetContract:Address;
172
+
value:bigint;
173
+
data:`0x${string}`;
174
+
};
175
+
```
176
+
167
177
The `targetContract` and `value` do not need additional processing, but how can we generate the calldata?
168
178
For that, we will use the `encodeFunctionData` function from the Viem library.
169
179
It calculates the encoding for a function from its contract's ABI, the function name, and the arguments used.
@@ -236,7 +246,6 @@ Then we call the `writeContract` Viem function, and actually register the instru
236
246
237
247
If the instruction has already been registered, a `CustomInstructionAlreadyRegistered` event is emitted.
238
248
Otherwise, the instruction is registered, and a `CustomInstructionRegistered` event is emitted instead.
239
-
In either case, the 32-byte encoding of the custom instruction, called the `callHash`, is returned.
240
249
241
250
```typescript
242
251
exportasyncfunction registerCustomInstruction(
@@ -251,35 +260,43 @@ export async function registerCustomInstruction(
251
260
});
252
261
console.log("request:", request, "\n");
253
262
254
-
constregisterCustomInstructionResult=
263
+
constregisterCustomInstructionTransaction=
255
264
awaitwalletClient.writeContract(request);
256
265
console.log(
257
-
"registerCustomInstructionResult:",
258
-
registerCustomInstructionResult,
266
+
"Register custom instruction transaction:",
267
+
registerCustomInstructionTransaction,
259
268
"\n",
260
269
);
261
270
262
-
returnregisterCustomInstructionResult;
271
+
returnregisterCustomInstructionTransaction;
263
272
}
264
273
```
265
274
266
275
## Encoding an instruction
267
276
268
277
Before the custom instruction can be sent on the XRPL, it must be properly encoded.
269
-
The 32-byte `callHash` that the `registerCustomInstruction` function returns is not yet a proper instruction encoding.
278
+
We call the `encodeCustomInstruction` read function of the `MasterAccountController` contract with the instruction as parameter.
279
+
It returns a 32-byte `callHash`, which is not yet a proper instruction encoding.
270
280
We need to replace the first two bytes with the following values:
271
281
272
282
- 1st byte: custom instruction command ID `0xff`
273
283
- 2nd byte: wallet identifier `walletId` described above
0 commit comments