Blockchain

 
 
A blockchain is a distributed database managed by a peer-to-peer network. The distributed database is also called a ledger which is a continuously growing chain of blocks. Each block contains a number of records and each block is linked to a previous block.

It is extremely difficult to change a record in any given block without the alteration of all subsequent blocks and the collusion of the network.

The first implementation of a blockchain was Bitcoin in 2009 invented by an unknown programmer, or a group of programmers, under the name Satoshi Nakamoto.

After the Bitcoin success many blockchain implementations followed such as Litecoin and Peercoin.

Other blockchain implementations introduces new kind of functionalities such as Ethereum and Dash.






How to setup truffle on macOS



Information
Truffle is a development environment, testing framework and asset pipeline for Ethereum, aiming to make life as an Ethereum developer easier.

Information about truffle, see: https://github.com/trufflesuite/truffle
Truffle commands, see: http://truffleframework.com/docs/advanced/commands

For this tutorial you need to have a running ethereum node, for example testrpc.

Operating system used
macOS 10.12 Sierra

Software prerequisites
Node.js


Procedure
  1. Make sure you have access to a running ethereum node, for example testrpc
    By default testrpc listens to http://localhost:8545.
    To start a stopped testrpc docker container, type: docker start CONTAINERID

  2. I have the following versions installed:

    Type: node -v     (version = 8.0.0)
    Type: npm -v      (version = 5.0.3)

  3. Install truffle, type: npm install -g truffle
    Version 3.2.5 installed.

    Show all installed npm packages, type: npm list -g --depth=0

  4. Create a truffle project, type: mkdir ~/ethdemos
    Type: cd ~/ethdemos

  5. Create a truffle environment with default set of contracts and tests, type: truffle init

    You will see the following:

    Downloading project...
    Project initialized.

       Documentation: http://truffleframework.com/docs

    Commands:

       Compile: truffle compile
       Migrate: truffle migrate
       Test: truffle test


  6. Truffle creates the following:
    • contracts
      Directory where Truffle expects to find solidity contracts.
    • migrations
      Directory to place scriptable deployment files.
    • test
      Location of test files for testing your application and contracts.
    • truffle.js
      your main Truffle configuration file.

  7. Compile all solidity files in the contracts folder.
    Type: cd ~/ethdemos
    Type: truffle compile

    You will see the following:

    Compiling ./contracts/ConvertLib.sol...
    Compiling ./contracts/MetaCoin.sol...
    Compiling ./contracts/Migrations.sol...
    Writing artifacts to ./build/contracts


  8. Deploy the contracts in the testrpc node.
    Type: truffle migrate

    You will see the following:

    Using network 'development'.

    Running migration: 1_initial_migration.js
       Deploying Migrations...
       Migrations: 0x3eab8380c69ba859c2cd57fc50592c9636f55dff
    Saving successful migration to network...
    Saving artifacts...
    Running migration: 2_deploy_contracts.js
       Deploying ConvertLib...
       ConvertLib: 0x8df9609b6c5a18176ae783dde08ce932d67ac2de
       Linking ConvertLib to MetaCoin
       Deploying MetaCoin...
       MetaCoin: 0xb313cec73471c44bed2bbf900dcf013087a24085
    Saving successful migration to network...
    Saving artifacts...


  9. To execute all test scripts in the test folder.
    Type: truffle test

    You will see the following:

    Using network 'development'.

    Compiling ./contracts/ConvertLib.sol...
    Compiling ./contracts/MetaCoin.sol...
    Compiling ./test/TestMetacoin.sol...
    Compiling truffle/Assert.sol...
    Compiling truffle/DeployedAddresses.sol...

    TestMetacoin
      ✓ testInitialBalanceUsingDeployedContract (172ms)
      ✓ testInitialBalanceWithNewMetaCoin (116ms)

    Contract: MetaCoin
      ✓ should put 10000 MetaCoin in the first account (47ms)
      ✓ should call a function that depends on a linked library (78ms)
      ✓ should send coin correctly (162ms)

    5 passing (929ms)