How to Send Transactions on VeChain

Every meaningful change on a blockchain, whether it’s sending VET, minting NFTs, or updating a smart contract’s state, happens through a transaction. On VeChain, this process is efficient, EVM-compatible, and now easier than ever thanks to the VeChain SDK.

In this article, we’ll walk through the step-by-step flow for building, signing, and submitting a transaction on VeChainThor.

Step 1: Encode Your Function Call

To write data, you’ll need to prepare one or more clauses, each representing an action on the blockchain. Use clauseBuilder to encode a function call:

const clauses = [
  clauseBuilder.functionInteraction(
    '0xYourContractAddress',
    'increment()'
  ),
];

You can also include a VET value transfer inside the same clause.

Step 2: Estimate Gas (VTHO)

Before broadcasting, estimate how much the transaction will cost in VTHO:

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

Step 3: Build the Transaction Object

Now, wrap the encoded clauses and gas into a transaction body:

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

You can also configure fee delegation, priority, or expiration here if needed. Stay tuned for more about fee delegation in an upcoming tutorial.

Step 4: Sign the Transaction

Signing involves 3 components:

  • The internal wallet

  • A VeChainProvider

  • A signer instance

Example:

const wallet = new ProviderInternalBaseWallet([{ privateKey, address }]);
const provider = new VeChainProvider(
// Thor client used by the provider
thorClient,
// Internal wallet used by the provider (needed to call the getSigner() method)
wallet,
// Enable fee delegation
false
);
);
const signer = await provider.getSigner(address);
// Sign the transaction
const rawSignedTx = await signer.signTransaction(txBody, privateKey);

Step 5: Submit & Track

Once signed, send it to the network:

const sendTransactionResult = await thor.transactions.sendTransaction(signedTx);

And track the result with:

const txReceipt = await thor.transactions.waitForTransaction(sendTransactionResult.id);

The txReceipt will confirm execution and include logs or errors if anything went wrong.