HowTo VeChain Blockchain — Part 4

What is a clause on the VeChain blockchain?

A clause is part of a transaction. One transaction can have multiple clauses. A clause carries the actual data that should be written to the blockchain. The VeChain transaction model says “an array of Clause objects each of which contains fields To, Value and Data to enable a single transaction to carry multiple tasks issued by the transaction sender”. This unique feature is called Multi-Task-Transaction or MTT.

Create a multi-clause-transaction

The transaction body to this is almost the same as in Part 3.

body = {
"chainTag": 39,
"blockRef": '0x0063603cdce346e6',
"expiration": 720,
"clauses": [
{
"to": '0x0000000000000000000000000000000000000000',
"value": 1000000000000000000,
"data": '0x'
},
{
"to": '0x0000000000000000000000000000000000000009'
"value": 1000000000000000000,
"data": '0x'
}
],
"gasPriceCoef": 0,
"gas": 37000,
"dependsOn": None,
"nonce": 12345678
}
from thor_devkit import cry, transaction
import requests
body = {
"chainTag": 39,
"blockRef": '0x006360a563534115',
"expiration": 720,
"clauses": [
{
"to": '0x0000000000000000000000000000000000000000',
"value": 1000000000000000000,
"data": '0x'
},
{
"to": '0x0000000000000000000000000000000000000009',
"value": 1000000000000000000,
"data": '0x'
}
],
"gasPriceCoef": 0,
"gas": 37000,
"dependsOn": None,
"nonce": 12345678
}
# Construct an unsigned transaction.
tx = transaction.Transaction(body)
# Sign the transaction with a private key.
priv_key = bytes.fromhex('61faba91ef7516969e885d197f59feeb2007ea2c6057908d1696d6f056ca69d4')
message_hash = tx.get_signing_hash()
signature = cry.secp256k1.sign(message_hash, priv_key)
# Set the signature on the transaction.
tx.set_signature(signature)
print('Created a transaction from ' + tx.get_origin() + ' to 0x0000000000000000000000000000000000000000 with TXID: ' + tx.get_id() + '.')
print('')
encoded_bytes = tx.encode()# pretty print the encoded bytes.
print('The transaction "0x' + encoded_bytes.hex() + '" will be send to the testnet node now.')
tx_headers = {'Content-Type': 'application/json', 'accept': 'application/json'}tx_data = {'raw': '0x' + encoded_bytes.hex()}send_transaction = requests.post('https://testnet.veblocks.net/transactions', json=tx_data, headers=tx_headers)print('Response from Server: ' + str(send_transaction.content))
Transaction with two clauses on Vechain Testnet
Transaction with two clauses on Vechain Testnet
Details of two clauses on VeChain Testnet

Are clauses the same as transactions?

Technically, obviously not. It’s just a part of a transaction that can not stand alone. But from a senders side, it pretty much eleminates the need for a second transaction. It’s fair to say that you can refer to the activity of the VeChain blockchain by observing the clauses and not just the transactions.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store