Distributed Applications

in #dapp7 years ago (edited)

The taugh mission: writing distributed apps


Now comes the part when you should read the posts on testrpc and Truffle.

There seems to be an intermediary step between the Ethereum Wallet and building DApps, the Metamask Chrome plugin as an interface for your users. Metamask is on my list to explore, as soon as I’m there, I will report on it.

Actually, I started with this step, before checking out Ethereum Wallet, that’s why I’m warning you from doing this.

It cost me very long hours until I got everything needed up and running. For me the main source of problems was Python, so I share what I learnt.

Warning: Python version matters

If you are a Python aficionado like me, you should use, whenever you can, the latest version of it. Python 3.x versions have a lot of improvements over the latest of the 2.x series, 2.7, two of the most crucial ones being unicode handling, and printing to file.

I use the Anaconda distribution with Python 3.6 (which is not the latest Python version, there exists alredy 3.7). Anaconda took itself as “Superpowers for People Who Change the World  Leading Open Data Science Platform Powered by Python”.

Using Anaconda with Jupyter Notebook as a user interface and publication platform (which allows you to combine executable code, formatted text and on the fly generated charts in one web page) will blow your mind (see an example).

The challenge is, OSX also uses Python to manage its file system operations, and they stick with the 2.6 version.

So when I tried to install the necessary tools for deploying DApps, I got a banch of error messages, from which it was not at all obvious what to do.

After several hours of trying the decipher and googling after error messages I could come up with the diagnosis and the solution:

OSX decides which version of Python to use, based on its PATH system variable. After installing Anaconda, the value of PATH (which you can see after issuing the echo $PATH command in Terminal) looks like this:

/Library/Anaconda/anaconda/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

Instead of the original value:

/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

The value of the PATH variable is actually not a single path, but an ordered list of paths (actually, folders), divided by colons. When OSX needs to decide how to resolve the python command, it launches that version of Python, which it first founds in any of these folders.

As you can see, the first path leads to the Anaconda folders, and we know that in there is contained Python 3.6. If you issue the command which python in Terminal, the result confirms this:

/Library/Anaconda/anaconda/bin/python

But the original Python 2.6, which belongs to OSX, sits in the “usr/bin” folder.
So the trick here is to duplicate this folder at the beginning of the PATH variable, with the

PATH=/usr/bin:$PATH command.

After this, the result of the echo PATH command will be this:

/usr/bin:/Library/Anaconda/anaconda/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

So the first folder, in which OSX will find a Python version, will be “usr/bin”. Correspondingly the result of the which python command will be:

/usr/bin/python

And the installation of every software we need will work as advertised.

The PATH variable change described above is temporary, which means it’s only valid for the current Terminal session, but this is exactly what we need, because the usage of the installed software doesn’t depend on the default Python version any more.
(There is also a way to change the value of the PATH variable forever, if need be, you will find it easily via a Google search.)

So back to the list of tools you will need to write and deploy test web DApps: Node.js, which is a server side JavaScript library. Part of Node.js is the NPM package manager, everything else you will install using that.

For OSX, you will need XCode Command Line Tools. (I didn’t know that I don’t need a developer account and the whole XCode package for this, so I started with creating a developer account and installing XCode — one time maybe I also will need it.)

Testrpc, you can install it via the npm install -g ethereumjs-testrpc command in Terminal. This is a test Ethereum client, which gives you at each launch 10 test addresses with enough Ether to pay for transactions. You should let it run in the background in a separate Terminal window, while you are working with the other tools.

Truffle, which is an Ethereum web app framework. You can install it via the npm install -g truffle command. It creates the necessary JavaScript and HTML files for your web app. Part of Truffle is web3, which is the JavaScript API to the Ethereum Virtual Machine (EVM), the runtime environment for smart contracts. Make sure you have the latest version installed of Truffle.

I spent several hours trying to find and fix a bug, which prevented me from starting the server on localhost which serves my app. It turned out that the bug was known, and a few days earlier fixed, I just had to upgrade Truffle. Truffle comes with a default contract for issuing a coin, called Metacoin. Here you have a tutorial on how to deploy it to the blockchain, and build the web app to interact with it.

You will also need a code editor. Just use Atom, which is one of the most popular ones within the Ethereum community. Once again, the order I recommend you to follow: Start playing with smart contracts, using the Ethereum Wallet. Wen you already know what they are good for, and think you need to build your own web app, learn and use Truffle.

Sort:  

intense info!

Thanks for the share :)

You are welcome :) Other posts are coming soon.

Congratulations @ipman! 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

Vote for @Steemitboard as a witness to get one more award and increased upvotes!

Coin Marketplace

STEEM 0.17
TRX 0.16
JST 0.029
BTC 60826.76
ETH 2393.38
USDT 1.00
SBD 2.62