Developer Fundamentals

1. Building and Signing

Correctly sequence the steps required to build and sign a transaction on VeChainThor.

Prerequisites

The Anatomy of a Transaction

Ready to write some history? Every change on the blockchain requires a transaction.

Think of a transaction as an envelope. Inside this envelope, you wrap your instructions in the form of clauses. VeChain's unique model allows you to bundle multiple operations (clauses) into a single transaction—this is like sending three different letters in one envelope!.

This means first encoding your function call using a helper like buildTransactionBody:

const txBody = await thor.transactions.buildTransactionBody(clauses, gasResult.totalGas);
const txBody = await thor.transactions.buildTransactionBody(clauses, gasResult.totalGas);
const txBody = await thor.transactions.buildTransactionBody(clauses, gasResult.totalGas);

CLAUSES AND GAS?

buildTransactionBody(clauses, gasResult.totalGas)
Wait a sec! We don't have any of the input! 😱

Clause

A clause represent the action you want to do, it has this structure

{
  "to": "0xTarget",
  "value": "0xAmountOfVet",
  "data": "OxCallData"
}
{
  "to": "0xTarget",
  "value": "0xAmountOfVet",
  "data": "OxCallData"
}
{
  "to": "0xTarget",
  "value": "0xAmountOfVet",
  "data": "OxCallData"
}

For VET transfers, the only kind of clauses not involving contract interactions, you will have something like this

{
  "to": "0x123...",
  "value": "0x1",
  "data": "Ox"
}
// send 1 wei of VET to '0x123
{
  "to": "0x123...",
  "value": "0x1",
  "data": "Ox"
}
// send 1 wei of VET to '0x123
{
  "to": "0x123...",
  "value": "0x1",
  "data": "Ox"
}
// send 1 wei of VET to '0x123

Gas

You need energy (or gas). On VeChain, the gas token is VTHO. But we need to ask the network: "How much will this cost?".

const gasResult = await thor.gas.estimateGas(clauses);
const gasResult = await thor.gas.estimateGas(clauses);
const gasResult = await thor.gas.estimateGas(clauses);

Pitfalls: No gas est? Tx fails silently. Always estimate.


You’re getting it! Now we have the "Transaction Body" with those clauses and the gas limit.

Almost there! A transaction must be signed to prove you are the owner. This requires your Private Key or a signer instance. Greedy? Continue reading!