How to Build a Proof of Stake (PoS) Coin with its Own Blockchain

in #cryptocurrency6 years ago

There are not many tutorials to build a Proof of Stake cryptocurrency, so I did my researches for learning purpose, and I decided to write one and build an opensource generator: https://coingenerator.sh

Build it in a few minutes 🚀

The Cryptocurrency that will be a clone of Nxt Cryptocurrency (from Jelurida). It uses the Proof of Stake consensus. There is no mining needed so it’s energy efficient. Also, the source code is in Java which is very well written and very easy to understand!

It will be released under the JPL license: https://www.jelurida.com/jpl

This license requires you to:

  • Give 10% of your coins to the Nxt holders (we will see how)
  • Keep your cryptocurrency open source

Download CoinGenerator

First, you need to download the CoinGenerator:

  1. Go to the repository https://github.com/sandoche/Proof-of-Stake-Cryptocurrency-generator
    Fork it (optional)
  2. Download your fork, or better clone it to your computer
  3. Make sure you have Java, NodeJS and Yarn installed
  4. Go to the folder you cloned, and run npm install

Sync the Nxt blockchain

Then you need to sync the Nxt blockchain (it can take a few hours), there is about 500 MB of data to download. This is required because of the JPL license that asks to share 10% of the coins with the NXT holders.

To sync it, run it with: npm run nxt

Then open http://localhost:7876/index.html in your favorite browser. Create a NXT account and save the private keys securely. Copy your nxt address and also its public key.

Create the Genesis block

Once the NXT blockchain synced we can create the genesis block. This genesis block will contain 1 billion of coins. From these coins, 10% will go to the NXT holders and the 90% will be distributed to the addresses you want to, thanks to the following process:

Open the file docs/config/newGenesisAccounts.json, this file will define the repartition of the coins you are creating:

  • You have to put the list of accounts you want to credit in the first block (the genesis block) and its matching public key. The total of the amounts should be 90000000000000000, it equals to 90% of the coins
  • If you don't know what to do, just put your NXT address your created previously and it's public key like this and save it. If you are not sure about what you are doing check this video:


{
    "balances": {
         "my nxt address here": 90000000000000000
     },
     "publicKeys": [
         "the public key of this nxt address"
     ]
 }



Once done:

  1. Go to http://localhost:7876/test?requestTag=ADDONS click on “downloadJPLSnapshot”
  2. Upload your file “newGenesisAccounts.json”
  3. Copy paste the height you can see in your wallet as in the screenshot below, then submit. A file will be generated after a few minutes
  4. Save it as “genesisAccounts.json” in the templates/conf/data folder.

The height is on the top left-hand corner: 1763825 in this case, the number of the last block, be sure that the blockchain is totally downloaded, unlike this screenshot!
The last thing to do is to set up the public key of the address which is going to generate the 1 billion of coins in the genesis block!

To do so, create another account (like you did previously), and save its public address in the file templates/conf/data/genesisParameter.json, also edit the epochBeginning with the current date.

Build your crypto

Now we are done setting up the genesis block it’s time to create the cryptocurrency and the blockchain! It’s the easy part:

  1. Update the images from templates/img according to your blockchain images and the favicon in templates
  2. Then just run npm run generate and answer the generator's questions. The generator will clone the nxt-clone-starter, it will automatically change the port and name in the source code.
  3. Once the cryptocurrency generated you can, of course, edit the interface inside the <yourCrypto>/html folder and find the java source in <yourCrypto>/src/java, note that you can find many parameters that you can edit in the following file <yourCrypto>/src/java/nxt/Constants.java
  4. Run it ! Go to <yourCrypto> folder compile with sh ./compile.sh (or win-compile.sh for Windows) then run with sh ./run.sh (or run.bat for Windows).
    Tada 🎉!!! Your crypto is alive! But just on your computer, that’s already something!

What else should I do?

Now what is next to do is:

Read more about how I learnt about cryptocurrencies: https://medium.com/learning-lab/how-i-learnt-about-cryptocurrencies-and-built-one-in-2-months-5d6d58616358

Sort:  

@sandoche, I gave you an upvote on your first post! Please give me a follow and I will give you a follow in return!

Please also take a moment to read this post regarding bad behavior on Steemit.

Congratulations @sandoche! You have received a personal award!

1 Year on Steemit
Click on the badge to view your Board of Honor.

Do not miss the last post from @steemitboard:

SteemFest3 and SteemitBoard - Meet the Steemians Contest

Support SteemitBoard's project! Vote for its witness and get one more award!

Congratulations @sandoche! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 2 years!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Do not miss the last post from @steemitboard:

SteemFest Meet The Stemians Contest - The mysterious rule revealed
Vote for @Steemitboard as a witness to get one more award and increased upvotes!

Coin Marketplace

STEEM 0.35
TRX 0.12
JST 0.040
BTC 70557.88
ETH 3560.83
USDT 1.00
SBD 4.75