Codementor Events

Your First Truffle Dapp — An attempt at a beginners guide to the Truffle Framework — Part 2

Published Nov 09, 2017Last updated May 08, 2018
Your First Truffle Dapp — An attempt at a beginners guide to the Truffle Framework — Part 2

Well, I’m going to be making some assumptions along the way because of the fact that we’re not programming in the same office space. Perhaps you’ve already dabbled in Dapp development before. Perhaps you just got started with solidity a couple days ago, or maybe you thought this post about truffle was about cooking…

Either way, here are my assumptions.

  1. You’re not too familiar with the command prompt or terminal

  2. You’ve never installed Truffle before

If I’m completely off target, you can go ahead and skip this section, but let’s assume I’m right. In that case, I would recommend that you keep reading in order to get a better grasp of the basics that will allow you to start coding as soon as possible.

So, I’m using windows for these series. Why? Well you remember those assumptions? I’m assuming that if you’ve just starting out, that you’re like the 91.41% of people out there that is running some type of windows operating system. I typically program in a Linux environment, but for you, I’ll making an exception. With that being said, please note that we might have to make some slight adjustments in order for our Dapp to play nicely with windows.

Command Line Interface

The easiest way I can put it is, you know those hacker movies you’re always watching, and the dude is sitting at his computer with a dark screen and nothing but text on the screen and he’s just furiously hacking away on his keyboard, no buttons, no windows, and no file menus. That my friend in is what’s called a “command line interface”, or CLI, or Terminal, but for us windows users, it’s a command prompt — which is still used by developers.

All those fancy menus are nice, but let’s say they can sometimes get time-consuming, and sometimes slow us down.

As such, you’ll even notice that truffle and Testrpc don’t use UI or User interface. In order to interact with our Dapp as we build it, we’ll have to use the command prompt. Don’t be scared…and no this doesn’t make you a hacker…

To get started, first find the command prompt application on your computer. After you locate it, go ahead and open it up so we can start.


Command Prompt

Setting up your environment is fairly straight-forward. You’ll need just a few things.

1. Nodejs : A platform built on Chrome’s JavaScript runtime for easily building fast and scalable network applications.

2. Truffle : Development framework for Ethereum

3. Ethereum TestRPC : A Node.js based Ethereum client for testing and development. It uses ethereumjs to simulate full client behavior and make developing Ethereum applications much faster.

Node

If you’re downloading node on a windows machines, you can go to: https://nodejs.org/en/ and just click the “Download for windows” button on the front page.


Node installation button on website

Then click “next” all the way through the defaults and then “finished” once installed. Once node is successfully installed you can open the command prompt terminal to verify that nodejs has been installed and type the following:

node –v

Press the “Enter” key on your keyboard and you should see the version of node that was installed. Mine is currently v6.11.2. Do the same thing to ensure that npm (node package manager) is installed correctly also.

npm –version

If you’re on:

· Mac: You can download the package: https://nodejs.org/en/download/

· Linux: https://nodejs.org/en/download/package-manager/

Great that looks good, let’s continue on shall we.

Truffle

In the same command prompt terminal type the following:

npm –g install truffle

Ethereum TestRPC

Once again in the same command prompt window you can type the following:

npm –g install ethereumjs-testrpc@beta

Let’s do a quick check to make sure that everything is working as expected.

I don’t intent to dive too deep into the command prompt, but this ones on the house. There are 4 windows command prompts commands that we’ll be using:

  1. mkdir  — this is used to create a new folder

  2. dir  — this is used to see the current files in that directory

  3. cd  — used to change directory to the specified folder path

  4. cd..  — when you want to jump one folder back in the path.

  5. “tab”  — This isn’t really a command. If you type the first few letters of the folder you want and press the “tab” key on your keyboard it will autocomplete the folder name for you.

Let’s put those commands and tricks to good use. When you opened the command prompt you probably noticed that the path is pointing to your user account name. So in the same command prompt you had opened before, type in the following command (don’t forget to press the “enter” key after you’ve typed your command:

cd desktop

Noticed the last listed name in the path is now “/desktop”. Perfect! Let’s speed this up a little. And then I’ll quickly explain what I did.

  1. I created a folder called “myapp”

  2. Then changed directory into the “myapp” folder and the created another folder name “truffle_test”

  3. After that I changed directory into the “truffle_test”_ folder

  4. With “truffle init” I told truffle to grab some files for me because this is where I’ll be create my super awesome Dapp.

  5. And finally we took a look into the folder to see what files truffle created for us

Now this is one of those times that we’ll have to make a slight adjustment in order to get windows to play nicely. After you initialize truffle it creates a file called “truffle”, please go ahead and rename that file to “truffle-config”. Perfect! We now know that truffle works.

What about that TestRCP package. Simple, open a separate command prompt (you don’t need to navigate back to the folder) and just type Testrcp. If you see below, you’re golden.


Verify TestRPC

Final Words

What have we learnt?

· Command line is your friend, when it comes to Dapps

· We might have to make some adjustments every now and then if you’re on windows, so bear with me please.

Join the conversation, follow us on Twitter: @ Tap_Coin, Reddit, or swing by and have a chat with us on Telegram: https://t.co/eIP47QmZ1E to discuss all things Tap Project.

“Fueled by gamers, inspired by the community, disruptive to all”

Discover and read more posts from TapDev
get started
post commentsBe the first to share your opinion
Show more replies