Hooks-Toolkit
Set Hooks
The setHooksV3
function in the SDK is used to set hooks on the XRPL. It takes in a SetHookParams
object as a parameter, which includes the client, seed, and hooks to be set.
Setting Hooks with setHooksV3
To set a hook on the XRPL using the setHooksV3
function, you need to provide the following parameters:
client
: The XRPL client object.seed
: The seed of the account that will set the hook.hooks
: An array of hook objects to be set.
Each hook object in the hooks
array should have the following properties:
Hook
: The hook payload object.
Here is an example of setting a hook using the setHooksV3
function:
import {
setHooksV3,
createHookPayload,
SetHookFlags
} from '@transia/hooks-toolkit'
const hook = createHookPayload({
version: 0, // HookApiVersion
createFile: 'hook_on_tt', // filename in /build
namespace: 'hook_on_tt', // namespace (ascii)
flags: SetHookFlags.hsfOverride, // SetHookFlag
hookOnArray: ['Invoke'] // HookOn Transactions
})
await setHooksV3({
client: testContext.client,
seed: testContext.alice.seed,
hooks: [{ Hook: hook }],
} as SetHookParams)
In the example above, we create a hook payload using the createHookPayload
function and set the hook_on
field to trigger on the Invoke
transaction type. We then pass the hook payload as an object in the hooks
array to the setHooksV3
function.
Note that the setHooksV3
function is an asynchronous function and returns a Promise. You can use await
to wait for the function to complete.
For more information on creating hook payloads and the available transaction types, refer to the Hook Payload documentation.
Credit: Omar Khan: https://github.com/khancode