Spartan Blockchain Truffle Box — An educational tool to learn the blockchain.

Sawyer Ruben
Spartan Blockchain Solutions
5 min readMay 7, 2020

Blockchain and Cryptocurrency technology has been through a wide swing of publicity since its creation in October 2008. The Bitcoin Whitepaper is where bitcoin and the larger “blockchain” technology came to life. A small group of developers and technologists picked it up and used it for about 9 years until late 2017 when Bitcoin and newer tokens (we’ll talk about these later) hit the mainstream media and exploded in price. So, what’s happened since then?

Gartner Hype Cycle
Gartner Hype Cycle — src(https://www.gartner.com/en/research/methodologies/gartner-hype-cycle)

Gartner developed this cycle to show the path of interest and expectations over time for emerging technologies, like blockchain. As you may have already inferred, December 2017 was right at the peak, and currently we are sitting in the Trough of Disillusionment and into the Slope of Enlightenment. The scope of this project and article is to move from the Trough and further along onto the Slope of Enlightenment; We want to empower people to develop and build solutions so we can find powerful use cases for blockchain and bring the technology into widespread adoption.

Blockchain technology holds lots of promise to solve some very complex and interesting issues that people face in the world. Its applications range from the sophisticated financial markets to the seemingly basic refugee camps around the world. New ideas and efforts are springing up from open source projects to corporate initiatives to start-up innovations. As we learn lessons from the past and people work to develop stronger, safer, and faster blockchain solutions, there grows an important educational need.

This Truffle Box Project is intended as a learning tool for all of us who may struggle understanding what a blockchain is, how it works, and why it is a viable solution for some problems. So if this sounds like you please follow along!

Lets start by introducing the tools we’ll be using. You’ll need all of the following before starting, and if you have some already, gold star for you!

Got both of those parts? Awesome, lets start!

The first thing we’re going to do is “unbox” what we’ve made for you. To do that open a Terminal and in the command line do the following:

npm install -g truffle

then

truffle unbox spartanblockchain/spartan-truffle-box

You should see a bunch of new files in your folder that we’ve made! Now:

npm install i

I know you’re excited so lets do this:

npm run dev

“NPM RUN DEV” is the command you will use to start the project every time!

So great! You have successfully copied our code base to your computer and are through the first step. Next we’re going to connect Ganache!

  1. Open the Ganache App so you’re faced with a brown screen and 2 buttons. Click the “New Workspace.”
  2. At the bottom is an “Add Project” button, click on that and navigate to the folder where you just copied the box. You’ll want to select the truffle-config.js file from your project.
  3. Give your project a cool name!
  4. At the top you’ll need to click on “Server.” And under “Port Number” change this to 8545.
  5. Save the workspace in the top right.

Now. In a new terminal we need you to do the following:

truffle compiletruffle migrate

If you go to Ganache and to the “Contracts” section you should see 2 new contracts — Migrations and Simple. You have just migrated the smart contracts to the blockchain. These smart contracts are how you can interact with data on the blockchain. As we go on you’ll see when these are used and what happens. Its important to note that these smart contracts do much of the heavy lifting and the Ethereum Blockchain is dependent on these.

You should now be able to play with your app and see changes in Ganache!

You have just successfully deployed smart contracts to a blockchain! How fancy! The goal with this Truffle Box is to allow you and others to learn the core of a blockchain and hopefully we can answer these questions:

What is a blockchain?
How does blockchain work?
Why is blockchain important?
How can we use blockchain technology?

We’d like to highlight a few things you’ll see:

  1. There are 2 input fields (Name and Data) these are meant to be placeholders for any sort of information you wish to keep. Maybe it’s Star Wars quotes, maybe it’s a receipt barcode, maybe it’s a ticket for a concert. The goal here is to allow the project to be malleable for you to use in whatever situation you need.
  2. There is a TimeStamp that gets set once you set the values for the block. The time is to mark each block with more information of when it was set and used, helping to keep the order and validity of the inputted information.
  3. There is a Block Hash which is a fancy way to combine lots of information. In the code you’ll see a function ‘sha256()’ which is a common hashing algorithm across applications of cryptography (you can check more out about cryptography later, it’s outside the scope of this project). In our case we use all sorts of information to become our hash. We use a timestamp, the name, the data, and the previous hash to create the block hash, which you can think about like a fingerprint for the block. This hashing is critical to the integrity of the blockchain, check it out.
  4. There is a Previous Hash field that holds the hash from the previous block. This is the field that makes blocks into a chain. Each Previous Hash points back to the ‘parent’ block and keeps the order of the blocks so transactions aren’t read out of order or fake transactions cannot be inserted. Since we use the previous blocks hash in all new blocks, they also roll up the previous data and time because if you remember how the hash is created (name + data + timestamp + previous hash = new hash).
  5. You’ll also notice that as you ‘Set’ blocks they become greyed out and you can’t type anymore. This is to show the property of immutability of previous blocks — blocks cannot be changed retroactively! This is an important note because it allows the blockchain to retain the validity and structure of the data it holds.

Feel free to play around and move your own data through! We want to encourage learning and building of such systems. While this project misses many details of blockchains, we can capture the essentials to learn on and can begin to share the flexibility and power of blockchain technology.

The impetus is on you to innovate and build new products, systems, and processes to increase the livelihood of others.

--

--