Developer Fundamentals

2. Decoding Transactions

Differentiate between a transaction object and a transaction receipt to understand execution results.

Prerequisites

Intent vs. Result (Transactions)

A transaction is a request for change! It could be sending VET or calling a smart contract.

VeChain transactions are special: they can contain multiple instructions called Clauses. This is like sending one envelope with three different letters inside!

But wait! There’s a big difference between what you tried to do and what actually happened.

  • Transaction Object: This is your intent (what was sent).

  • Transaction Receipt: This is the result (what the blockchain did).

In JavaScript, this means...

you need to check the reverted flag in the receipt to see if your transaction failed!

// Check the result
const txReceipt = await thor.transactions.getTransactionReceipt(txId);
if (txReceipt.reverted) {
    console.log("Oh no, the transaction failed!");
}
// Check the result
const txReceipt = await thor.transactions.getTransactionReceipt(txId);
if (txReceipt.reverted) {
    console.log("Oh no, the transaction failed!");
}
// Check the result
const txReceipt = await thor.transactions.getTransactionReceipt(txId);
if (txReceipt.reverted) {
    console.log("Oh no, the transaction failed!");
}

Nice! The receipt also includes outputs, which show you events emitted by contracts and any VET transfers that occurred.