Developer Fundamentals

4. Clauses and Fuel Calc

Build multi-clause tx and estimate VTHO gas precisely.

Prerequisites

Crafting Clauses & Gas

Instructions inside the envelope? Clauses! 📬 VeChain bundles multiples for efficiency.

Ok, so…

You weren't expecting to code manually each clause, right? Fortunatelly we have a Clause builder.

Encode clauses:

import { Clause, ABIFunction } from '@vechain/sdk-core';

const clauses = [
  Clause.callFunction('0x8384738c...', 
  new ABIFunction({ name: 'increment', type: 'function' })),
  // Add more clauses!
];
import { Clause, ABIFunction } from '@vechain/sdk-core';

const clauses = [
  Clause.callFunction('0x8384738c...', 
  new ABIFunction({ name: 'increment', type: 'function' })),
  // Add more clauses!
];
import { Clause, ABIFunction } from '@vechain/sdk-core';

const clauses = [
  Clause.callFunction('0x8384738c...', 
  new ABIFunction({ name: 'increment', type: 'function' })),
  // Add more clauses!
];

The other part you know, you estimate gas and get the transaction body:

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

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

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

Multi-power activated!​

Note for nerds!

In the example we've used ABIFunction, which requires to know the properties of the contract function we wish to use. The alternative is to load the ABI:

import Abi from './abi.json' assert { type: 'json' };
// contract ABI is same as in example above
const vtho = thor.contracts.load(
    '0x8384738c...',
    Abi
)

const clauses = [
  vtho.clause.increment().clause,
  // Add more clauses!
]
import Abi from './abi.json' assert { type: 'json' };
// contract ABI is same as in example above
const vtho = thor.contracts.load(
    '0x8384738c...',
    Abi
)

const clauses = [
  vtho.clause.increment().clause,
  // Add more clauses!
]
import Abi from './abi.json' assert { type: 'json' };
// contract ABI is same as in example above
const vtho = thor.contracts.load(
    '0x8384738c...',
    Abi
)

const clauses = [
  vtho.clause.increment().clause,
  // Add more clauses!
]

Signing seals it!