HowTo VeChain Blockchain — Part 6

Putting data on the Blockchain

MiRei
3 min readAug 5, 2020

(Links to all parts at the bottom)

In parts 1–5, I covered the basic parts of the VeChain Blockchain and how to interact with it. This was always limited to simply transferring VET from one wallet to another (or to multiple wallets, using the VeChain MTT feature).

In the next parts, I will cover more advanced features of VeChain like data, gas calculation, contract interaction, MPP, VIP-191 etc. to show the true power of this blockchain.

Preparing the data

In this part, we will put data onto the VeChain Blockchain (for now, without smart contract interaction) and send it to ourself (sender and reciever are the same address). Data can only be send to the blockchain when it’s encoded in HEX. In this part, we will do this manually with an online ASCII to HEX converter but this can also be done with python directly.

As shown in part 5, a clause on the VeChain Blockchain consists of three parts:
to, value and data.

{'to': '0xbc1497fc775f5cbf42dfeca44d97efaba79462b7', 'value': 1000000000000000000, 'data': '0x'}

So it’s only logical, that data can be used to send actual data onto the blockchain. To do this, we simply have to put HEX encoded data into that field and set value to 0. For this demo, we will send “Hello, world!” onto the blockchain. As mentioned above, we will use the online converter to get the needed HEX code. When converted, “Hello, world!” will become “48656c6c6f2c20776f726c6421”, so the clause will look like this.

{'to': '0xbc1497fc775f5cbf42dfeca44d97efaba79462b7', 'value': 0, 'data': '0x48656c6c6f2c20776f726c6421'}

The gas-problem

As mentioned in part 4, the gas calculation for VET clauses is pretty easy to do in advance but with data involved this changes. Although “5000 (base-cost) + 16000 (for non-contract-creation clauses)” still applies, there will be some more gas needed to pay for the transport and storage of the data. For now, we will set the gas limit manually to 100.000 (calculation will be covered in a later part).

Since the program is now about 70 lines, I will not post it completely in the article but link it to my github. The program (6_putting_data_online.py) is modified to make the input of data more easy and other than that, it’s all the same. And thats pretty much it…

Python program to send data to the VeChain Testnet

When executed, the script will create a transaction, where no VET is transferred but data is send to the address specified in the script.

Successful transfer of data to VeChain Testnet

As you can see, this clause does not contain any VET but hast the data we wanted it to have.

VeChain clause with data

Mainnet example

With this script, I did a fellow Twitter friend a small favor. She wanted a picture of here stored on the blockchain. So I compressed and converted the picture to HEX and actually stored it with this script on the VeChain Mainnet and tweeted her the result.

If you feel like it, you can decode it yourself (sample for Linux Bash):

curl -sX GET "https://mainnet.veblocks.net/transactions/0xa773de8c74f63ab4044363167c914161a33307a231fc8552514f8eb6436c0886" | jq -r .clauses[].data | xxd -plain -revert > VeChainPicture.jpg

--

--