Pages:
Author

Topic: How to create Blockchain? Build your own chain (Easy-Peasy Guide) (Read 606 times)

legendary
Activity: 1918
Merit: 1759
legendary
Activity: 1918
Merit: 1759
you rock webtricks, can this be run to a localserver or do I need to have a cloudserver one, I would like to see if this will run to a local invironment, and try what can be achieved,

Hey buddy,
Yes, you can run this on localserver without any connection to internet. It will work perfectly. Do tell me if you get any other problem. Smiley
sr. member
Activity: 1106
Merit: 310
you rock webtricks, can this be run to a localserver or do I need to have a cloudserver one, I would like to see if this will run to a local invironment, and try what can be achieved,
legendary
Activity: 1932
Merit: 4602
legendary
Activity: 3472
Merit: 10611
I'm thinking to create series of threads in Beginners & Help related to technical aspects of Bitcoin. It will include everything: how addresses are created, what is elliptic curve, etc. Being from financial background, I self-learnt everything about bitcoin from web sources. Although, there are valuable resources already available like bitcoin.it but things are still complicated for newcomers. I have created alternative to all codes in JavaScript which is lot easier than other programming languages. What do you say, should I go ahead?

i am also self-taught and have learned everything from pretty basic things such as using wallets down to highly technical matters such as elliptic curve cryptography on my own from documentations alone. i wanted to create something similar some time ago but i'm afraid i am not good at  simplifying things and could have made things worse so i never made the effort.
kudos to you, this was a good post and you should keep it up.

ps. as for language i think most people find python to be the easiest although i don't understand either one since i prefer c# Smiley
legendary
Activity: 1918
Merit: 1759
<--snip-->

Nice additions, especially the Proof of Work part. I wanted to include the proper Proof of Work implementation in the guide but things were becoming very complicated. However, you explained it very easily. Kudos to you.  Wink

But as I said in post #3 that this is just a dummy version of blockchain and in no way related to Bitcoin. Also we are not saving transactions in blockchain for now so merkle root is irrelevant.

I'm thinking to create series of threads in Beginners & Help related to technical aspects of Bitcoin. It will include everything: how addresses are created, what is elliptic curve, etc. Being from financial background, I self-learnt everything about bitcoin from web sources. Although, there are valuable resources already available like bitcoin.it but things are still complicated for newcomers. I have created alternative to all codes in JavaScript which is lot easier than other programming languages. What do you say, should I go ahead?
legendary
Activity: 3472
Merit: 10611
good job, just some points for the sake of completion:
part 1(a):
a block doesn't have to store its own hash (or get it in constructor) instead it takes everything else (timestamp, nonce,...) and compute its own hash.

additionally this part is skipping an important matter: merkle root
a block is a container that is supposed to store transactions. in order to make sure transactions inside that block can't be changed, a hash that is generated from all transactions is also used and stored in creation of a block header. but instead of hashing all at once we create a merkle tree and only store the root hash in header.
you could skip timestamp like you skipped block version but merkle root is important.

part 1(c):
you may want to use a nested loop, the outer one changing time and  the inner one changing nonce.
additionally you may want to use another hash algorithm instead of SHA for higher speed since you don't want security in here. something like MD5.
an important distinction
PoW has nothing to do with "number of starting zeros", it is all about comparing integers.
first of all you have to flip the endianness of the digest meaning reversing the hash bytes:
block hash bytes: { xx, xx, 00, 00 }
reverse block hash bytes: { 00, 00, xx, xx }
then convert it to an integer and compare it with the target (another integer). example (all in big-endian):
target = 260 = 0x000104 (3 bytes)
hash1 = 261 = 0x000105              -> has 1 starting zero but 261 > 260 => reject
hash2 = 259 = 0x000103              -> has 1 starting zero and 259 < 260 => accept

Part 1(d)
just a reminder: bitcoin's hash is SHA256 of SHA256 (in other words double hash) but it doesn't matter here since it is just for learning i just wanted to remind and as i said you can use another faster hash like MD5.
hero member
Activity: 2268
Merit: 669
Bitcoin Casino Est. 2013
Thanks for the guide this gives me an idea on how to create one, as crypto enthusiast we need to be knowlegdeable in this kind of stuff. But I am not very good with this stuff it is too complex for me, this programming, etc. But this is really a good tutorial for a developer aspirants.
It is not just a guide but also helping newbies understand how blockchain works by knowing how blockchain is created. It would be very helpful for both developers and also for newbies who wants to learn and understand how blockchain is and also how to create one.
legendary
Activity: 1918
Merit: 1759
legendary
Activity: 1918
Merit: 1759
~~
~~
i will read detail per part maybe 10times  Cheesy, i can't fully understand wiwth read twice, maybe i will repost in local indonesian section due to make people in mycountry learning bitcoin by coding

Great!
Let me give you an additional feature for the above chain. This one line will convert timestamp from milliseconds to proper date and timing:
Code:
        timestamp = new Date(timestamp).toLocaleString();

Add this line in the createBlock() function at the place mentioned below:
Code:
static createBlock(previousBlock, data) {
        let hash, timestamp, nonce=0;
        const lastHash = previousBlock.hash;
        do {
            timestamp = Date.now();
            nonce++;
            hash = hashGenerator(timestamp, lastHash, data, nonce);
        } while (hash.substr(0,4) !== '0'.repeat(4));
       
        //add this code here
        timestamp = new Date(timestamp).toLocaleString();

        return new this(timestamp, lastHash, hash, data, nonce);
    }
hero member
Activity: 644
Merit: 509


Yeah, sure.
I have uploaded complete code in order here:
https://webtricks.website/blockchainCode.html

Do tell me if you get any other error. I will be happy to clear it. Smiley

working perfectly Smiley
result :
Code:
xxx@ubuntu  ~/Desktop/javascript challenge  node blockchain
[
  Block {
    timestamp: '17/01/2020',
    lastHash: 'dummy-last-hash',
    hash: 'dummy-hash',
    data: 'data in genesis block',
    nonce: 0
  },
  Block {
    timestamp: 1579446587014,
    lastHash: 'dummy-hash',
    hash: '0000ef84be4441c614dd4c19a15b8470ac3b2bcbf36a2300f105f56906962c62',
    data: 'This dummy data is saved in the second block of the webbyChain',
    nonce: 113386
  },
  Block {
    timestamp: 1579446587835,
    lastHash: '0000ef84be4441c614dd4c19a15b8470ac3b2bcbf36a2300f105f56906962c62',
    hash: '00009f5354bbfe4ee07e918e708a641a811f8dfe2d1a0ce74e9f9eef434309f1',
    data: 'This immutable data is saved in the third block',
    nonce: 91432
  },
  Block {
    timestamp: 1579446588321,
    lastHash: '00009f5354bbfe4ee07e918e708a641a811f8dfe2d1a0ce74e9f9eef434309f1',
    hash: '0000a44bd43f873587da1cb34c467dfd9a94916017dfc5878d67ebed04928df1',
    data: 'Adding top secret in the fourth block',
    nonce: 55393
  }
]

i will read detail per part maybe 10times  Cheesy, i can't fully understand wiwth read twice, maybe i will repost in local indonesian section due to make people in mycountry learning bitcoin by coding
legendary
Activity: 1918
Merit: 1759
can you share the source code?
i just copy all the code above in 1 files and get this errror


Code:
/home/xx/Desktop/javascript challenge/blockchain.js:10
static createGenesis() {
       ^^^^^^^^^^^^^

SyntaxError: Unexpected identifier
    at Module._compile (internal/modules/cjs/loader.js:892:18)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)
    at Module.load (internal/modules/cjs/loader.js:812:32)
    at Function.Module._load (internal/modules/cjs/loader.js:724:14)
    at Function.Module.runMain (internal/modules/cjs/loader.js:1025:10)
    at internal/main/run_main_module.js:17:11



Yeah, sure.
I have uploaded complete code in order here:
https://webtricks.website/blockchainCode.html

Do tell me if you get any other error. I will be happy to clear it. Smiley

+2
that's a great tutorial, simple and easy to understand, next time or next tutorial, i recomended to use bitcoinlib.js , to create address , raw transaction, sing message etc.
im use bitcoinlib.js + WVvalidator js for my last project i combine with vue js , its simple to newbie than native js.

Great. I am currently using some other library to create keys and signatures. I will try bitcoinlib.js and if I find it relatively easier than will use it in my tutorial.
Thanks for suggestion.
hero member
Activity: 644
Merit: 509
can you share the source code?
i just copy all the code above in 1 files and get this errror


Code:
/home/xx/Desktop/javascript challenge/blockchain.js:10
static createGenesis() {
       ^^^^^^^^^^^^^

SyntaxError: Unexpected identifier
    at Module._compile (internal/modules/cjs/loader.js:892:18)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)
    at Module.load (internal/modules/cjs/loader.js:812:32)
    at Function.Module._load (internal/modules/cjs/loader.js:724:14)
    at Function.Module.runMain (internal/modules/cjs/loader.js:1025:10)
    at internal/main/run_main_module.js:17:11

full member
Activity: 1176
Merit: 162
Thanks for the guide this gives me an idea on how to create one, as crypto enthusiast we need to be knowlegdeable in this kind of stuff. But I am not very good with this stuff it is too complex for me, this programming, etc. But this is really a good tutorial for a developer aspirants.
hero member
Activity: 700
Merit: 501
+2
that's a great tutorial, simple and easy to understand, next time or next tutorial, i recomended to use bitcoinlib.js , to create address , raw transaction, sing message etc.
im use bitcoinlib.js + WVvalidator js for my last project i combine with vue js , its simple to newbie than native js.
legendary
Activity: 1918
Merit: 1759
As it looks so easy to start blockchain coding, what coding language can be used as different languages have always different structures .

You can use any programming language. It is possible to create blockchain with Python, Java and C++. In fact, Bitcoin Core is written in C++. But the easiest is Javascript (which is actually front-end language but could be used in back-end with Node.js).

I would also like to ask if this blockchain structure remains the same with all apps we used to know? I mean is it the same with Ethereum (using Solidity) or Beam (using MimbleWimble) or any other independent blockchain?

Am not a programmer, neither thinking to start coding with blockchain programming languages. But those questions came into my mind after reading this great easy topic .

Basic structure of all blockchains is same. You may notice that we created 5 properties of our Block class: timestamp, lastHash, hash, data and nonce. Among these, you will always find timestamp, lastHash, hash and nonce in any blockchain. Since, Bitcoin and Ethereum store transactional data, therefore, data field in these blockchains is detailed. To save transactions in the block, such blockchains use many other properties like in case of Bitcoin we have: merkle root, version, nBits, size, weight, etc.
hero member
Activity: 2338
Merit: 757
Top-tier crypto casino and sportsbook
Excellent work (y)
Even i consider myself as a veteran user, i find your guide so much helpful for me to correctly understand different elements in the blockchain .

As it looks so easy to start blockchain coding, what coding language can be used as different languages have always different structures .

I would also like to ask if this blockchain structure remains the same with all apps we used to know? I mean is it the same with Ethereum (using Solidity) or Beam (using MimbleWimble) or any other independent blockchain?

Am not a programmer, neither thinking to start coding with blockchain programming languages. But those questions came into my mind after reading this great easy topic .
legendary
Activity: 1918
Merit: 1759
I really like your tutorial, good job, it's really straightforward for newbies (and not only). You deserve a reward for your work, enjoy:
XX---Header Image---XX
Note: I am not a designer, I am doing it just for fun.

Thanks. Nice design!
Added to OP alongwith credits. Smiley
full member
Activity: 693
Merit: 120
I really like your tutorial, good job, it's really straightforward for newbies (and not only). You deserve a reward for your work, enjoy:

Note: I am not a designer, I am doing it just for fun.
legendary
Activity: 1918
Merit: 1759
It's a good example that explains how blockchain works by building a baby blockchain in one of the simplest and most popular programming languages, but it's important to understand that the presented code isn't practical, this blockchain lacks file system support, it doesn't have networking, it doesn't have transactions, scripts and so on. You won't become a blockchain specialist by reading articles like this, you'll have to dig much deeper.

That's the problem with people at large. Everyone thinks from the producer's point of view. Nobody gives due importance to consumer point-of-view. I didn't create this thread so that person start deploying high-class applications using code above. Rather I wanted to give general understanding to everyone about how blockchain works under the hood.
The term 'blockchain' is nowadays is floating like some fairy tale on internet. Many websites such as gambling, exchanges and others claim that they are using blockchain for their operations. But that's not true always. But people (aka consumers) have no idea what implementations should they check on website to confirm whether such sites actually using blockchain or not. After reading the guide above, I can bet that people will have clearer idea about blockchain even if they don't understand code. That is what I wanna achieve through this thread. Period.
Pages:
Jump to: