Skip to content

Commit b9d4a7b

Browse files
feat(docs): add call hash code snippet
1 parent 5719404 commit b9d4a7b

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

docs/smart-accounts/3-custom-instruction.mdx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,20 @@ To produce the custom instructions calldata, we first ABI encode the array of th
8686
We then take the `keccak256` hash of that value, and drop the last byte.
8787
That is the call hash that is provided as the payment reference for the custom action, and the ID under which the custom instructions are stored in the `MasterAccountController` contract.
8888

89+
```Solidity
90+
uint256(keccak256(abi.encode(_customInstruction))) >> 8;
91+
```
92+
93+
The call hash can also be obtained through the `encodeCustomInstruction` helper function of the `MasterAccountController` contract.
94+
95+
```Solidity
96+
function encodeCustomInstruction(
97+
CustomInstruction[] memory _customInstruction
98+
) public pure returns (uint256) {
99+
return uint256(keccak256(abi.encode(_customInstruction))) >> 8;
100+
}
101+
```
102+
89103
## 0. Register custom instructions
90104

91105
We register a custom instruction by calling the `registerCustomInstruction` function on the `MasterAccountController` contract.

0 commit comments

Comments
 (0)