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
@@ -107,12 +107,28 @@ export async function getOperatorXrplAddresses() {
107
107
}
108
108
```
109
109
110
-
Because the Flare smart accounts are still in development, the `MasterAccountController` contract has not yet been added to the `FlareContractRegistry` contract.
111
-
That is the reason why the address of the `MasterAccountController` has been hardcoded in the example repository.
110
+
We define a helper functionfor retrieving the address of the `MasterAccountController` contract from the `FlareContractsRegistry`.
Copy file name to clipboardExpand all lines: docs/smart-accounts/guides/typescript-viem/03-custom-instruction.mdx
+19-28Lines changed: 19 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -40,8 +40,6 @@ The full code showcased in this guide is available on [GitHub](https://github.co
40
40
41
41
## Contracts
42
42
43
-
{/* TODO:(Nik) fix contract addresses and links */}
44
-
45
43
The first contract is a `Checkpoint` that counts how many times each user has called its `passCheckpoint` function.
46
44
It is useless as anything other than an example.
47
45
The first call of our custom instruction will be to call the `passCheckpoint` function of this contract, deploy at the address [`0xEE6D54382aA623f4D16e856193f5f8384E487002`](https://coston2-explorer.flare.network/address/0xEE6D54382aA623f4D16e856193f5f8384E487002?tab=contract).
@@ -212,8 +210,6 @@ const customInstructions = [
212
210
213
211
## Registering an instruction
214
212
215
-
{/* TODO:(Nik) fix the code for this when the contract gets fixed to not revert if the instruction has already been registered */}
216
-
217
213
Next, we need to register the custom instruction with the `MasterAccountController` contract.
218
214
In order to read from the Flare chain, we first need to create a [Viem public client](https://viem.sh/docs/clients/public).
{/* TODO:(Nik) Update once MasterAccountController gets added to the FlareContractRegistry */}
231
-
232
-
We also need the address of the `MasterAccountController` contract.
233
-
Since the Flare smart accounts are still in development, we cannot query the `FlareContractRegistry` for the `MasterAccountController` address.
234
-
Instead, we need to hardcode it.
235
-
236
-
```typescript
237
-
exportconst MASTER_ACCOUNT_CONTROLLER_ADDRESS =
238
-
"0x32F662C63c1E24bB59B908249962F00B61C6638f";
239
-
```
240
-
241
-
{/* TODO:(Nik) Check that the following is still relevant - how the register function works */}
242
226
To register a custom instruction, we call the `registerCustomInstruction` function on the `MasterAccountController` contract and provide the custom instruction array as the argument.
243
227
As recommended by the [Viem documentation](https://viem.sh/docs/contract/writeContract#writecontract), we first use the `simulateContract` function to prepare the request.
244
228
Then we call the `writeContract` Viem function, and actually register the instruction.
245
229
246
230
If the instruction has already been registered, a `CustomInstructionAlreadyRegistered` event is emitted.
247
231
Otherwise, the instruction is registered, and a `CustomInstructionRegistered` event is emitted instead.
248
232
233
+
We also need the address of the `MasterAccountController` contract, which we can look up by name using `getContractAddressByName` from the Flare Contract Registry.
Lastly, we need to wait for the operator to bridge the instruction from XRPL to Flare, and for the instruction to be executed.
373
363
Once it does, our personal account executes the instruction, and the `CustomInstructionExecuted` event is emitted by the `MasterAccountController` contract.
374
364
We watch for such events with the [`watchContractEvent`](https://viem.sh/docs/contract/watchContractEvent#watchcontractevent) Viem function.
@@ -383,7 +373,7 @@ If the value is `false`, we wait for `10` seconds, then check again.
383
373
Once the value has been found, we stop observing the contract and return the event.
0 commit comments