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: docs/smart-accounts/guides/02-custom-instructions.mdx
+19-19Lines changed: 19 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,15 +17,15 @@ keywords:
17
17
unlisted: false
18
18
---
19
19
20
-
{/* NOTE:(Nik) This article has been placed right after the introduction into Flare Smart Accounts instead of at the end, so that readers don't get bored of reading before they reach it. */}
20
+
{/* NOTE:(Nik) This article has been placed right after the introduction into Flare Smart Accounts instead of at the end, so that readers don't get bored with reading before they reach it. */}
21
21
22
22
importThemedImagefrom"@theme/ThemedImage";
23
23
importuseBaseUrlfrom"@docusaurus/useBaseUrl";
24
24
25
25
The Flare Smart Accounts allow XRPL users to make custom function calls on Flare through instructions sent on XRPL.
26
-
In this guide we will look at how the custom instructions can be developed using a mock version of the `MasterAccountController` contract.
26
+
In this guide, we will look at how the custom instructions can be developed using a mock version of the `MasterAccountController` contract.
27
27
28
-
In a typical workflow the users sends instructions as memo data on XRPL.
28
+
In a typical workflow, the user sends instructions as memo data on XRPL.
29
29
Those then have to be verified by the FDC on the Flare chain.
30
30
That process requires waiting, which is less than ideal in a development environment.
31
31
@@ -36,22 +36,22 @@ It implements two additional functions:
36
36
-`executeCustomInstructionDevelopment`
37
37
38
38
The `createFundPersonalAccount` function creates a new `PersonalAccount` for the user.
39
-
It accepts as its argument a string `_xrplAddress`, which represents and address on XRPL.
39
+
It accepts as its argument a string `_xrplAddress`, which represents an address on XRPL.
40
40
The string is then concatenated with the `msg.sender` value;
41
41
the `PersonalAccount` is created for this address.
42
42
43
43
Thus, a developer can create multiple XRPL "addresses".
44
44
This allows them to more easily test the interactions between different personal accounts.
45
-
The "address" is combined with their Flare address, so that they can give meaningful names to their "addresses" without a danger of multiple developers' addresses crashing.
45
+
The "address" is combined with their Flare address, so that they can give meaningful names to their "addresses" without the danger of multiple developers' addresses crashing.
46
46
47
47
The `createFundPersonalAccount` function is a payable function.
48
-
And funds sent with the transaction are deposited to the newly created personal account.
48
+
And funds sent with the transaction are deposited into the newly created personal account.
49
49
That way, the personal account can interact with payable functions from the get-go.
50
50
51
51
The `executeCustomInstructionDevelopment` function sidesteps the XRP transaction and the FDC `Payment` verification process.
52
52
It allows developers to send an array of custom instructions to the `MasterAccountController` contract directly.
53
53
54
-
The two parameters this function takes are the `_xrplAddress` string, and an array of `IMasterAccountController.CustomInstruction` structs.
54
+
The two parameters this function takes are the `_xrplAddress` string and an array of `IMasterAccountController.CustomInstruction` structs.
55
55
It first concatenates the input string with the `msg.sender` value, the same way the `createFundPersonalAccount` function does.
56
56
Then, it retrieves the `PersonalAccount` representing that address, and calls its `custom` function with the array of custom instructions it received as input.
57
57
@@ -61,37 +61,37 @@ Then, it retrieves the `PersonalAccount` representing that address, and calls it
61
61
62
62
We will now use the Flare Smart Accounts CLI to interact with a simple contract.
63
63
The contract `Foo` has a single payable function `bar`.
64
-
The `bar` function accepts a `uint256` value as input, and add the fee paid with the transaction to a mapping.
64
+
The `bar` function accepts a `uint256` value as input, and adds the fee paid with the transaction to a mapping.
65
65
66
66
```Solidity
67
67
// SPDX-License-Identifier: MIT
68
68
pragma solidity ^0.8.25;
69
69
70
70
contract Foo {
71
-
mapping(uint256 => uint256) public map;
71
+
mapping(uint256 => uint256) public map;
72
72
73
-
function bar(uint256 a) public payable {
74
-
map[a] = map[a] + msg.value;
75
-
}
73
+
function bar(uint256 a) public payable {
74
+
map[a] = map[a] + msg.value;
75
+
}
76
76
}
77
77
```
78
78
79
-
We want to send `1 FLR` to the contract, and save it under number `42`.
79
+
We want to send `1 FLR` to the contract, and save it under the number `42`.
80
80
The address of the `Foo` contract is `0x296432C15504Ed465fAce11E54Ce4aac50cCd8A3`.
81
-
Using an online ABI-encoding tool, we get that the following hash for the `bar` function, with `42` as input: `0x0423a132000000000000000000000000000000000000000000000000000000000000002a`.
81
+
Using an online ABI-encoding tool, we get the following hash for the `bar` function, with `42` as input: `0x0423a132000000000000000000000000000000000000000000000000000000000000002a`.
82
82
83
83
:::warning
84
-
Encoding calldata by hand is errorprone.
84
+
Encoding calldata by hand is error-prone.
85
85
It is recommended to use established libraries, or an [online tool](https://abi.hashex.org/) (if you want to quickly check something).
86
86
:::
87
87
88
88
There are two ways we can go about developing the custom instructions.
89
-
We will start with an approach, which is what the production code would take.
90
-
Afterwards, we will use the the mock functions to speed up the development.
89
+
We will start with an approach that is what the production code would take.
90
+
Afterwards, we will use the mock functions to speed up the development.
91
91
92
92
### Normal approach
93
93
94
-
Before we can execute the above instructions we need to top up the smart account that will perform the function call.
94
+
Before we can execute the above instructions, we need to top up the smart account that will perform the function call.
95
95
We run the following command, which fails because our account lacks funds on Flare.
96
96
It is necessary to send some instructions, because that is what creates an account for us in the first place.
97
97
@@ -129,7 +129,7 @@ This will only work if our Flare address has sufficient funds.
0 commit comments