Xahau smart contracts (Hooks) need transaction & destination specific fees. You can easily get the required fee from the `fee` RPC command.
While libraries may deal with fee determination for you (see Transaction Signing), when building your own integrations with the Xahauy ledger, you may have to implement dynamic fee determination based on the transaction, source & destination account.
As the sender of a transaction will have to pay for the fees required for the invoked Hooks for the specific transaction type, where Hooks can live both on the source & destination account, you can send a TX Blob (signed with a dummy account) to the fee
command, after which Xahau will return the specific fees required for the specific transaction.
Transaction fees on a ledger with the Hooks Amendment enabled become non-trivial to compute for end-users and/or wallet applications. This is because strong hooks must be paid for by the originator of a transaction, and there may be as many as 4 strong hooks on the sending account and 4 on the receiving account, as well as any other strong transactional stakeholders involved (as can be the case with some exotic transaction types). Further, if the transaction is a SetHook then the size of the parameters, the size of the code and whether it is a create operation or an install operation all determine the size of the fee.
Therefore it is highly recommended that all transactions be run through the updated fee RPC call before they are submitted to the ledger.
Open a websocket connection to the Hooks node you will be working with.
Compose the serialized transaction you wish to know the fee for with the following:
Fee: 0
SigningPubKey: ""
(That is: 0 byte VL of type 0x73. In hex:0x7300
.)
Do not sign the transaction.
Submit it as a hex blob to the RPC as follows:
For HTTP POST RPC submit it as follows:
The response should look something like
Take the base fee and set it as the Fee
field in the transaction. Now sign and submit it as per the normal transaction submission process.
If there is an invalid value for tx_blob
or tx_blob
is missing, a regular JSON result will be returned with a base_fee
of 10.
As Hooks-enabled networks require specific transaction fields & offer more transaction types, not all clients will work out of the box. `xrpl-accountlib`
Hooks-enabled networks allow getting network definitions dynamically. Allowing clients to adapt available transaction types, ledger objects, properties, and value types. When implemented correctly, signing and encoding libraries don't have to be updated when the network adds transaction/object types/properties. The libraries below implement this and will handle this for you.
Hooks-enabled networks require a NetworkID with every transaction to prevent transaction replay on another chain. The NetworkID will also be returned by a server_info
RPC command in the network_id
field (e.g. 21338
for Hooks V3 testnet)
Transactions on a Hooks-enabled network may need higher fees to deliver a transaction to another account, based on the Hooks that will be executed sending out of the sending account and receiving on the destination account. A reasonable fee to satisfy the Hooks execution can be dynamically fetched from a node by issuing the fee
command while providing a transaction as tx_blob
. The libraries below implement this and will handle this for you.
The npm package xrpl-accountlib
can sign transactions for Hooks-enabled networks, as it offers full dynamic network feature support fetching network definitions at runtime.
The npm package xrpl-client
integrates nicely with xrpl-accountlib
(and comes as a dependency) to dynamically fetch the aforementioned network definitions and account values, helping submit the transaction.