This document provides a comprehensive guide on constructing contract transactions using the VeChain SDK, specifically focusing on deploying smart contracts and calling contract functions. The aim is to furnish developers with the knowledge to seamlessly integrate these transactions into their blockchain applications on vechain.

Deploying a Smart Contract


Deploying a smart contract is a foundational step in leveraging the VeChain blockchain for decentralized applications. This section delves into the process of creating a deployment clause, which is essential for initiating a smart contract on the network.

// 1 - Init contract bytecode to deploy

const contractBytecode =

// 2 - Create a clause to deploy the contract
const clause = clauseBuilder.deployContract(contractBytecode);

Process Breakdown

  1. Clause Construction: The deployment of a smart contract begins with the construction of a deployment clause. The VeChain SDK offers a dedicated function, clauseBuilder.deployContract, found within the @vechain/sdk-core package, for this purpose.

  2. Smart Contract Bytecode: The bytecode of the smart contract, contained within the contractBytecode variable, encapsulates the compiled contract code that will be deployed to the blockchain.

  3. Invocation: By invoking the clauseBuilder.deployContract function with the contract's bytecode, a clause object is generated. This clause object is a structured representation of the deployment request, ready to be broadcast to the VeChain network.


The deployment example elucidates the utilization of the VeChain SDK to construct a deployment clause, a crucial component for deploying smart contracts on the VeChain blockchain.

Calling a Contract Function


After deploying a smart contract, interacting with its functions is the next step. This section guides you through the creation of a clause tailored for calling a specific function within a deployed smart contract.

// 1 - Init a simple contract ABI
const contractABI = stringifyData([
        constant: false,
        inputs: [
                name: 'value',
                type: 'uint256'
        name: 'setValue',
        outputs: [],
        payable: false,
        stateMutability: 'nonpayable',
        type: 'function'
        constant: true,
        inputs: [],
        name: 'getValue',
        outputs: [
                name: '',
                type: 'uint256'
        payable: false,
        stateMutability: 'view',
        type: 'function'

// 2 - Create a clause to call setValue(123)
const clause = clauseBuilder.functionInteraction(
    '0x7567d83b7b8d80addcb281a71d54fc7b3364ffed', // just a sample deployed contract address
        .getFunction('setValue') as FunctionFragment,

Process Breakdown

  1. Understanding the ABI: The ABI (Application Binary Interface) of the smart contract, usually defined in JSON format, describes the contract's functions and their respective parameters. This interface is pivotal for ensuring proper interaction with the contract's functions.

  2. Clause Creation for Function Calls: Utilizing the clauseBuilder.functionInteraction function from the @vechain/sdk-core package, a clause is crafted for the specific purpose of invoking a function on the smart contract.

  3. Function Invocation: In this example, the function setValue within the smart contract is invoked with a parameter of 123. This action demonstrates how to interact with a function, altering the state within the smart contract based on the function's logic.


This section highlights the methodology for constructing a clause that facilitates interaction with a deployed smart contract's functions on the VeChain network, thereby enabling developers to manipulate and query smart contract states efficiently.

This document, designed to be both informative and practical, equips developers with the necessary tools and knowledge to effectively interact with smart contracts on the VeChain blockchain, from deployment to function invocation.

Delegating a Contract Call


VeChain allows for the delegation of contract calls, enabling developers to execute contract functions in which the fees are payed by the delegator.

Here is an example of how to delegate a contract call:

const thorSoloClient = ThorClient.fromUrl(_soloUrl);
const provider = new VeChainProvider(
    new ProviderInternalBaseWallet([deployerAccount], {
        delegator: {
            delegatorPrivateKey: delegatorAccount.privateKey
const signer = (await provider.getSigner(
)) as VeChainSigner;

// Defining a function for deploying the ERC20 contract
const setupERC20Contract = async (): Promise<Contract<typeof VIP180_ABI>> => {
    const contractFactory = thorSoloClient.contracts.createContractFactory(

    // Deploying the contract
    await contractFactory.startDeployment();

    // Waiting for the contract to be deployed
    return await contractFactory.waitForDeployment();

// Setting up the ERC20 contract and getting its address
const contract = await setupERC20Contract();

// Transferring 10000 tokens to another address with a delegated transaction
const transferResult = await contract.transact.transfer(

// Wait for the transfer transaction to complete and obtain its receipt
const transactionReceiptTransfer =
    (await transferResult.wait()) as TransactionReceipt;

// Asserting that the transaction has not been reverted

Multi-Clause Contract Interaction

Multiple clauses read

VeChain supports the execution of multiple clauses in a single transaction, allowing developers to interact with multiple contracts or perform multiple operations within a single transaction.

Here is an example of how to interact with multiple read clauses in a single transaction:

// Reading data from multiple clauses in a single call
const multipleClausesResult =
    await thorSoloClient.contracts.executeMultipleClausesCall([

expect(multipleClausesResult[0]).toEqual([unitsUtils.parseUnits('1', 24)]);

Multi-Clause Event filtering


VeChain allows developers to filter multiple events from diffent contracts in a single call, enabling efficient event monitoring and processing.

To do so, developers needs the contract address and the event signature.

Here is an example of how to filter multiple events from different contracts:

const contractEventExample = await setupEventExampleContract();

await (await contractEventExample.transact.setValue(3000n)).wait();

const transferCriteria = contractErc20.criteria.Transfer(

const valueCriteria = contractEventExample.criteria.ValueSet();

const events = await thorSoloClient.logs.filterEventLogs({
    criteriaSet: [transferCriteria, valueCriteria]

// Asserting that I'm filtering a previous transfer event and the new value set event
expect(events[0].map((x) => x.decodedData)).toEqual([

expect(events[1].map((x) => x.decodedData)).toEqual([
    ['0xF02f557c753edf5fcdCbfE4c1c3a448B3cC84D54', 3000n]

Last updated