How to Build a Blockchain: Part Two
Recently I built my own blockchain using the NXT Blockchain Creation Kit, and I showed you how I did it in How to Build Your Own Blockchain: The Genesis Block. We used the NXT Blockchain Creation Kit to do this.
- First, we took a blockchain snapshot.
- Then we created our own Genesis block.
- We reviewed the new blockchain to make sure that was running.
When we checked we saw some things that still identified this as an NXT blockchain clone. These are the things that we’re going to change today.
We will make some tweaks to work with the naming in the identification of the blockchain to reflect our own project and remove some of the features that we don’t want.
Before I go any further, let’s make sure we have backed up any work that we have done to this point. It’s important to have a backup of the Genesis text file, the Genesis account list that was created during the snapshot and the files from the Nxt Blockchain Creation Kit that I have renamed to reflect my project.
The readme.md file tells us the first file we will edit is the Nxt.java file found in your blockchain project at src/java/nxt/Nxt.java
There on line 55 is a reference to our application. I replaced the words “NxtClone” with “FreeSpeech”, which if you haven’t guessed is going to be the name of my project. And I saved the file, opened up my client wallet, logged in and expected to see my changes and look at those highlighted places.
Not one thing had changed and it was a little bit frustrating. I didn’t know where to look for directions in any other place than the included readme file. So I dug a little bit deeper and I found a few other places to tweak that are not well documented. Let me show you.
Log out of your wallet and go back into your blockchain folder. Navigate to /src/java/nxt/Constants.java there are three places to update this file, you can see that I’ve highlighted them on the left side the image. And on the right side of the image, you can see where I replaced some of those terms with my identifying symbols and names. You want to make sure that you replace the “FSC” with your coin symbol and the “FreeSpeech” with your token name.
Save your file and then navigate back to the main folder of your project directory and then to /html/www/js/nrs.constants.js
This is where it’s going to get a little bit tricky. On the left hand side, you will see four lines highlighted. When we’re done, we’re going to have five lines because we are going to add one and most of the text of each of these lines is going to be replaced. So make sure you read this carefully.
Lines 125 through 127 will look like this:
NRS.constants.COIN_SYMBOL = String("FSC");
(Be sure to use your coin symbol instead of “FSC”)
NRS.constants.ACCOUNT_PREFIX = NRS.constants.COIN_SYMBOL;
Line 128 and 129
After line 127 we are going to add a new line 128.
response.accountPrefix = NRS.constants.COIN_SYMBOL;
And in line 129 replace with the text, making sure that you substitute your project name for “FreeSpeech”.
NRS.constants.PROJECT_NAME = "FreeSpeech";
This is what my new file looks like.
Start Your Blockchain and See the Changes
Now it’s time to check the blockchain to make sure the changes have been applied.
In the command box we will start our client wallet, navigate to it in a browser and login. Choose returning user and use an account from your Genesis account list. Refer to How to Build Your Own Blockchain, Part One for a reminder on how to do this.
Everything looks great! Let’s move one and remove some of the included blockchain features that we don’t want to be part of our cloned blockchain.
Choose Your Blockchain Features
Here I must talk about how awesome the blockchain NXT is. It is so fully featured. There are so many things you can do right out of the box with over 250 API’s that are ready for your developer or you to use to manage your data or to create smart contracts.
My project is going to be called Free Speech. It’s going to be about communication and I’m going to want encrypted messaging and probably want the voting system, and I might decide to keep the data cloud storage because sharing pictures is part of communicating and telling a story.
I know for sure today that I don’t want the marketplace, coin shuffling or the monetary system. So I want to eliminate those features. I don’t even want to see them. So how am I going to do it?
Create nxt.properties File
Inside my project folder I will navigate to the /conf directory to find the nxt-default.properties file. Changing this file could really mess things up. So let’s copy and paste the relevant code into a new file called nxt.properties
The first thing I want to do is just disable those big feature groups that I know I don’t want to use. So I just list them here separated by semi-colons. Here, I’ve listed the digital goods store, the monetary system and coin shuffling. After I save the file it looks like this.
Now, let’s start the NRS (client-wallet) back up to check and make sure that these blockchain features have disappeared. And we can see they are gone. The features of monetary system, marketplace and coin shuffling are no longer available to my end users, just like I wanted.
Remove a Specific API
There might be some instances where I want to keep the blockchain feature group but there might be a specific API, or function inside that I don’t want my end users to use. For instance, I believe I may want my end users to be able to set an alias so they can interact with each other without using their account numbers all of the time. But I don’t think I want my users to sell those aliases.
Let’s navigate back into the API console learn what the exact name of that function is inside the console. I will add sellAlias it to nxt. properties file like you can see here.
After I save everything and open my client wallet again I can see the option to sell an alias has disappeared.
You can easily edit your blockchain to choose the features you present to your end users by adding more items to these two lines until you get it exactly the way that you want it.
In this demonstration I changed the name of the project and the coin symbol so the wallet looks a little like my own instead of branded with an NXT. Then I turned off the built-in features that I don’t want to be available for my end users of my blockchain.
Wow, can you believe it? I’ve created it my own blockchain project, Free Speech Coin. Who knows what’s going to happen with this? For now, it is a demonstration and at some point in the future, we’re going to finish it.
But before we do that,
- I want to show you how to set up nodes in the network. That’s a pretty important thing and we need to do that soon.
- Then, I want to show you how the interface some of these API’s with your website to make it a little bit more accessible to your end user.
- And we need to talk about how we’re going to distribute this coin.
So there’s still lots of work to do. Stay tuned, and I’m going to let you see exactly how I do it. If you’re following along. I hope you are as excited as I am about where you’re bringing your project andIf you’re just watching, I hope you’re getting a lot of really good ideas, best success to all of you.
Watch the full demonstration where I show you how to change Coin Symbols and Choose Blockchain Features in How to Build Your Own Blockchain, Part 2.