1. Reading Data on VeChainThor
Before building the AI agent, you need to understand how to interact with VeChainThor blockchain.
1.1 Setting Up the VeChain SDK
VeChain SDK provides all the tools needed to interact with VeChainThor.
Install the SDK packages:
1.2 Connect To the Network
VeChain has two networks: mainnet (for real transactions) and testnet (for development and testing). For this tutorial, we'll connect to mainnet, since we will use AI Agents to fetch data.
1.3 Reading Account Information
An account can be classified as either an externally owned account or a smart contract.
Externally owned account - consists of private keys generated in wallets.
Smart contracts - they are deployed with specific program codes.
The difference between the two can be made by examining an account's hasCode flag. If it's true, it indicates that a smart contract is deployed at that address. For smart contracts, the bytecode can also be retrieved.
An account has three key attributes:
hasCode - indicates a smart contract at the address
balance - shows the VET balance
energy - shows the VTHO balance
This is how querying Account Information looks like:
And here’s an example response:
1.4 How To Read Transactions
Transactions are changes on the blockchain, which can be a transfer of VET or the execution of the contract’s function.
A transaction on VeChain consists of two parts:
Transaction Body
Transaction Receipt
Reading both will give you a full understanding of the transaction.
Transaction Body
Transaction body contains:
id - Unique transaction identifier.
chainTag - Identifier of the Blockchain.
blockRef - Block on which the call was made.
expiration - The transaction must be added within this many blocks, or it will fail.
origin - Sender of the transaction.
clauses - Instructions that need to be executed, including recipients, value, and data.
meta - Block metadata (BlockID, BlockNumber, and BlockTimestamp).
This is how you query transaction information:
Transaction Receipt
The transaction receipt shows the outcome and blockchain changes.
It contains:
reverted - Indicates if the transaction failed.
gasUsed - The amount of gas that was used to complete the transaction.
outputs - Events that have been triggered as a result of the transaction.
contractAddress - Address of a newly deployed contract (if there are any).
To request a transaction’s receipt, you can call the getTransactionReceipt() method instead. Just replace your `getTransaction()` call with this snippet:
Example of a Successful Transaction:
Join our Telegram