Submit Tx

The Xrpld.submit function in the SDK is used to submit a transaction to the XRPL. It takes in a SubmitTxParams object as a parameter, which includes the client, wallet, and transaction to be submitted.

Submitting a Transaction with submitTx

To submit a transaction to the XRPL using the Xrpld.submit function, you need to provide the following parameters:

  • client: The XRPL client object.
  • wallet: The wallet object that holds the account information for the transaction.
  • tx: The transaction object to be submitted.

Here is an example of submitting a transaction using the Xrpld.submit function:

import {
  Xrpld,
  createHookPayload,
  setHooksV3,
  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)

const aliceWallet = testContext.alice
const bobWallet = testContext.bob
const builtTx: Invoke = {
  TransactionType: 'Invoke',
  Account: bobWallet.classicAddress,
  Destination: aliceWallet.classicAddress,
}

const result = Xrpld.submit(testContext.client, {
  wallet: bobWallet,
  tx: builtTx,
} as SubmitTxParams)

In the example above, we first create a hook payload using the createHookPayload function and set the hook_on field to trigger on the Invoke transaction type. We then use the setHooksV3 function to set the hook on the XRPL.

Next, we define the builtTx object, which represents the transaction to be submitted. In this case, it is an Invoke transaction with the Account set to Bob's address and the Destination set to Alice's address.

Finally, we pass the client, wallet, and tx objects to the Xrpld.submit function to submit the transaction to the XRPL.

Note that the Xrpld.submit function is an asynchronous function and returns a Promise. You can use await to wait for the function to complete.


Credit: Omar Khan: https://github.com/khancode

Was this page helpful?