Building with Solidity

Transactions on VeChain

This lesson covers VeChain transactions - token transfers, smart contract interactions, and the difference between free read operations and write operations that require signatures and gas.

Transactions Are a Record of Actions

On VeChain, a transaction refers to an action or event that involves the transfer or modification of data within the blockchain.

By executing a transaction a blockchain can: transfer a digital token from one address to another; deploy a smart contract on the blockchain or trigger the execution of a smart contract.

A transaction is a signed request to change something on the blockchain. That change could be:

  • Transferring tokens (VET or VTHO)

  • Calling a smart contract function 

    • Write: mintNFT(), submitProof()

    • Read: checkStatus()

  • Deploying a smart contract

Once confirmed, it becomes part of VeChain’s immutable ledger and can be queried by users, apps, explorers, and indexers.

Interacting with Transactions as a Developer

When building dApps on VeChain, you interact with smart contracts in two primary ways:

1. Read Operations (View / Pure Functions)

These functions:

  • Do not change blockchain state

  • Don’t require a transaction

  • Can be called directly from the frontend

  • Cost no gas

Example:

function getStudent(address wallet) public view returns (Student memory) {
  return students[wallet];
}

In your frontend, you can use VeChain’s SDK to call this function directly without signing anything.

2. Write Operations (State-Changing Functions)

These functions modify the blockchain state and:

  • Require the user to sign and send a transaction

  • Consume gas (VTHO)

  • Trigger event logs and permanent on-chain records

Example:

    function addStudent(string memory _name, string memory _familyName) public payable {
        require(msg.value == 1 ether, "You must pay 1 VET to register.");
        // Make sure the student isn't already registered
        require(!students[msg.sender].registered, "You are already registered.");
        // Create a new student record
        students[msg.sender] = Student({
            wallet: msg.sender,
            name: _name,
            familyName: _familyName,
            registered: true,
            graduated: false,
            certificate: 0
        });
    }

To call this from a frontend:

  • You generate a write transaction

  • The user signs the transaction (e.g., via VeWorld or WalletConnect)

  • The transaction is submitted to VeChainThor and processed