Developer Fundamentals
-- Write Transactions II
Learn how to encode function calls into clauses, estimate gas costs using VTHO, and build complete transaction objects for VeChainThor.
Clauses, Gas Estimation, Transaction Objects
Clauses encode the function calls into data calls. The instructions for executing a function on the blockchain must be encoded in a specific way. There are various functions available to help create the correct format. One is the clauseBuilder that will, in this example, call increment() on the given address:
A clause can also send VET in the same action.
Estimate Gas Costs
While reading on the blockchain is free, writing requires so-called gas fees. Gas is paid in VTHO, the secondary token on VeChain, which is generated by holding VET.
To calculate the right amount of gas for your transaction, you can use estimateGas.
If you expect your contracts to have different results based on the sender, you can also pass in the sender address as an optional second parameter.
Build Transaction Object
Once you have instructions + costs, you'll wrap them together into a transaction object with buildTransactionBody.
There are several options that can optionally be passed as a third argument to enable fee delegation, dependency on other transactions, priority, and expiration. You will learn more about them in the Fee Delegation section.
Join our Telegram