B4J Tutorial Another Blockchain example

Here is a port of the code presented as a tutorial here: https://medium.com/programmers-bloc...chain-java-tutorial-from-scratch-6eeed3cb03fa

It includes examples of blockchain, transactions, wallets and mining.

I would suggest in the first instance that you follow the tutorial and try to convert the java code your self as there are a few stages that make important points. If you are not sure on the use of Javaobject or the classes it accesses, all the code required is in the attached example so get it from there. There are not many comments in the code, it is all explained in the tutorial. If you are just curious, that's OK too.

It also requires the BouncyCastle jar from here: https://www.b4x.com/android/forum/threads/share-encrypted-data-with-b4a.35482/. Copy it into your additional libraries folder, if you haven't already.

It probably took me about 4 hours to pull everything together and get it working, I was pleasantly surprised how straightforward the coding is. I've learnt a lot about the concepts and technology from doing this and I must say, I was expecting something far more complicated.

I hope you find it useful.

Update to fix bug alwaysBusy found in post# 5

30
 

Attachments

  • BlockChainTest.zip
    7.8 KB · Views: 416
Last edited:

tufanv

Expert
Licensed User
Longtime User
Here is a port of the code presented as a tutorial here: https://medium.com/programmers-bloc...chain-java-tutorial-from-scratch-6eeed3cb03fa

It includes examples of blockchain, transactions, wallets and mining.

I would suggest in the first instance that you follow the tutorial and try to convert the java code your self as there are a few stages that make important points. If you are not sure on the use of Javaobject or the classes it accesses, all the code required is in the attached example so get it from there. There are not many comments in the code, it is all explained in the tutorial. If you are just curious, that's OK too.

It also requires the BouncyCastle jar from here: https://www.b4x.com/android/forum/threads/share-encrypted-data-with-b4a.35482/. Copy it into your additional libraries folder, if you haven't already.

It probably took me about 4 hours to pull everything together and get it working, I was pleasantly surprised how straightforward the coding is. I've learnt a lot about the concepts and technology from doing this and I must say, I was expecting something far more complicated.

I hope you find it useful.

Thanks Steve . This is what i was looking for. One of the most important feature of blockchain is the broadcasting between all the nodes as you know. Are you planning to add this to tutorial somehow ?
 

stevel05

Expert
Licensed User
Longtime User
I think that is going to be part of the next tutorial from the site above. When it's added, I'll look at porting it too.
 

alwaysbusy

Expert
Licensed User
Longtime User
I think there may be a typo in your code:

In StringUtil.java in the getMerkleRoot() method:
B4X:
for(int i=1; i < previousTreeLayer.size(); i+=2) { // <---------- is step 2

In BCUtils:
B4X:
For i = 1 To PreviousTreeLayer.Size - 1

should be:
B4X:
For i = 1 To PreviousTreeLayer.Size - 1 step 2
 

stevel05

Expert
Licensed User
Longtime User
Thank you, you are correct. Updated in post # 1.
 

Swissmade

Well-Known Member
Licensed User
Longtime User
Hi Is there anyone who is still working on this?
 

stevel05

Expert
Licensed User
Longtime User
Not as far as I know. For me, it was just an interesting exercise.
 
Top