VeChain Docs
  • Welcome to VeChain
  • Blockchain Basics
    • Introduction to blockchain
    • Introduction to digital property
    • The evolution of the internet
  • Introduction to VeChain
    • About the VeChain blockchain
      • Consensus Deep Dive
      • Governance
    • Dual-Token Economic Model
      • VeChain (VET)
      • VeThor (VTHO)
    • Acquire VeChain Assets
    • Sustainability
  • Core Concepts
    • Networks
      • Thor Solo Node
      • Testnet
      • Mainnet
    • Nodes
      • Node Rewards Programme
    • Blocks
      • Block Model
    • Transactions
      • Transaction Model
      • Transaction Fees
      • Transaction Calculation
      • Meta Transaction Features
        • Transaction Uniqueness
        • Controllable Transaction Lifecycle
        • Clauses (Multi-Task Transaction)
        • Fee Delegation
          • Multi-Party Payment (MPP)
          • Designated Gas Payer (VIP-191)
        • Transaction Dependency
    • Block Explorers
    • Wallets
      • VeWorld
        • User Guide
          • Setup
          • Wallet
          • Signing
          • Activities
          • Settings
        • FAQ
      • Sync2
        • User Guide
          • Setup
          • Wallet
          • Signing
          • Activities
          • Settings
        • FAQ
      • Sync
        • User Guide
          • Wallet
          • Ledger Device
          • Browser dApps and web
          • Interact with dApps
          • Activities
          • Settings
          • Report an Issue
          • Contributing
        • FAQ
    • EVM Compatibility
      • VeChain Modifications
      • Methodology
      • Test Coverage
        • Gas model
        • Raw transaction
        • hardhat specific
          • Ganache failures
          • evm_increaseTime
        • Failures in constructor
        • eth_sign
        • Contract address prediction
        • BadBeacon proxy address at 0x1
      • How to Recreate
      • Additional Information
        • Using Governance Contracts
        • ERC1820/ERC777 Testnet
        • Delegate Options
    • Account Abstraction
      • UserOperation
      • Bundler
      • EntryPoint Contract
      • Account Factory Contract
      • Paymaster Contract
    • Token Bound Accounts
  • How to run a node
    • Nodes
    • How to run a Thor Solo Node
    • Custom Network
    • Connect Sync2 to a Thor Solo Node
  • Developer Resources
    • Getting Started
    • How to build on VeChain
      • Connect to the Network
      • Read Data
        • Read Blocks
        • Read Transactions
        • Read Accounts
        • States & Views
        • Events & Logs
        • VET Transfers
      • Write Data
        • Transactions
        • Fee Delegation
      • Listen to Changes
        • Events
        • VET Transfers
        • Transactions
        • Blocks
        • Beats
      • Build with Hardhat
      • Utilities
        • BigInt and Unit-Handling
        • Name Service Lookups
    • Example dApps
      • Buy me a Coffee
      • Token Bound Accounts
      • PWA with Privy and Account Abstraction
    • EVM Compatibility for Developers
      • Key Architectural Differences and Optimizations
      • Practical Implications for Developers: Key Considerations
      • RPC Methods (Detailed Breakdown)
      • Frequently Asked Questions (FAQs)
      • VeChain Blockchain Specifications
      • Key Differences Between VeChain and Ethereum (Summary)
      • Best Practices for Developing on VeChainThor
    • How to verify Address-Ownership
      • Next.js Session Verification
    • Debug Reverted Transactions
    • Account Abstraction
    • VIP-191: Designated Gas Payer
      • How to Integrate VIP-191 (I)
      • How to Integrate VIP-191 (II)
      • How to Integrate VIP-191 (III)
    • Index with Graph Node
      • Setup with Docker
      • Index with OpenZeppelin
        • Create Subgraph Project
        • Configure Contracts
        • Deploy Subgraph and start Indexing
        • Track Subgraph Indexing
        • Access Subgraph
        • Update Subgraph
    • SDKs & Providers
      • SDK
        • Architecture
        • Accounts
        • Bloom Filter
        • Certificates
        • Contracts
        • Cryptography
        • Debug
        • Encoding
        • Polls
        • Subscriptions
        • Thor Client
        • Transactions
      • Thor DevKit
        • Installation
        • Usage
          • Cryptography
          • Accounts
          • Encoding
          • Transactions
          • Certificates
          • Bloom Filter
      • DApp Kit
        • v2
          • Installation
          • React
            • Installation
            • Usage
          • Vanilla JS
            • Installation
            • Usage
          • Core
            • Installation
            • Usage
          • Theme Variables
          • i18n
        • v1
          • Installation
          • React
            • Installation
            • Usage
          • Vanilla JS
            • Installation
            • Usage
          • Core
            • Installation
            • Usage
          • Theme Variables
          • i18n
          • Node Polyfills
          • V0 to V1
        • v0
          • Installation
          • Usage
          • React
            • Installation
            • Usage
          • Vanilla (UI)
            • Installation
            • Usage
          • Styles (UI)
          • i18n
      • DevPal
      • Web3-Providers-Connex
        • Installation
        • Usage
      • Connex
        • Installation
        • API Specification
    • Frameworks & IDEs
      • Hardhat
      • Remix
    • Built-in Contracts
    • VORJ
    • Useful Links
  • How to contribute
Powered by GitBook
On this page
  • Failing to submit with insufficient energy
  • Transaction Reverts with Out of Gas
  • Decode Revert Reason
  • Example Snippet

Was this helpful?

  1. Developer Resources

Debug Reverted Transactions

Failing to submit with insufficient energy

The message indicates that the gas payer does not have enough VTHO to cover the gas fees defined for the transaction.

Add VTHO to the transaction gas payer's VTHO balance or, if possible, reduce the amount of gas you are paying for the transaction.

Transaction Reverts with Out of Gas

The message indicates that the transaction attempted execution but failed due to insufficient gas provided.

Increase the amount of gas you're willing to pay for the transaction. You can use transactionUtils.intrinsicGas(clauses) and add a buffer.

The buffer might become relevant because if your contract undergoes changes between the gas calculation and transaction execution, it can increase the gas cost for your transaction. If you approve a higher gas price, you will only be charged the actual costs.

Decode Revert Reason

Once your transaction is submitted and it shows a "reverted" flag, debugging the reasons can be challenging. Having a contract that throws meaningful errors can greatly aid in debugging.

The initial step to identify the error is to run the transaction through a simulation to find the revert reason.

This can be accomplished by loading the original transaction and extracting data for the simulation:

const transaction = await thor.transactions.getTransaction(txId)
const simulation = await thor.transactions.simulateTransaction(
  transaction.clauses,
  {
    revision: transaction.meta.blockID,
    gas: transaction.gas,
    caller: transaction.origin,
    gasPayer: transaction.delegator ?? transaction.origin,
    expiration: transaction.expiration,
    blockRef: transaction.blockRef,
  }
);

The simulation will return a result for each clause until the first clause fails. For successful simulations, the length of the simulation list will equal the number of clauses.

You can loop through the results to find the first clause that reverted:

simulation.forEach((clause, clauseIndex) => {
  if (!clause.reverted) {
    return console.log(`Clause #${clauseIndex} was successful`);
  }

  console.log(`Clause #${clauseIndex} reverted (${clause.vmError})`);
});

The error is contained in the data attribute, which you can decode using your ABI, for example:

import { ThorClient } from '@vechain/sdk-network';
import { coder } from '@vechain/sdk-core';

const contractInterface = coder.createInterface(['Error(string)']);

//.. simulate

simulation.forEach((clause, clauseIndex) => {
  if (!clause.reverted) {
    return console.log(`Clause #${clauseIndex} was successful`);
  }

  const revertReason = contractInterface.parseError(clause.data);

  console.log(`Clause #${clauseIndex} reverted with`);
  console.log(' VM Error:', clause.vmError);
  console.log(' Revert Reason:', revertReason.args);
});

The example interface Error(string) is typically used when throwing a regular error. It functions well in most standard situations.

Example Snippet

PreviousNext.js Session VerificationNextAccount Abstraction

Last updated 9 months ago

Was this helpful?

LogoVechain-energy - Example Snippets - StackBlitzStackBlitz