Blockchain – Embark Framework

September 13, 2018

Author: Michael Gord

Tutorial - MLG Blockchain

This tutorial will walk through how to use Embark, which is a framework to help developers easily build and deploy serverless decentralized applications. A Decentralized Application (Dapp) is a serverless application that uses decentralized technologies, such as blockchain and smart contract technology, and has no single point of failure. Embark is currently integrated with the Ethereum EVM blockchain, IPFS decentralized storage and decentralized communication platforms called Whisper and Orbit.

Embark is a tool to automatically deploy smart contracts to the Ethereum EVM blockchain and make them easily accessible with traditional Javascript code. Embark handles the contract migration if there are multiple contracts, automatically redeploys contracts as needed and watched for changes. It supports test driven development of contracts with Javascript and allows developers to easily manage their contracts on different blockchains, such as a testnet, a private net and the live network.

You can use any traditional web development language with Embark including Angular, React, Meteor, etc. You are also able to use any build pipeline you want, including grunt or gulp.

To begin you need to install the Embark package manager with NPM.

$ npm -g install embark

If you would like to deploy your smart contract to the Ethereum test network rather than a real ethereum node use this command.

$ npm -g install ethereumjs-testrpc

You can create a sample working DApp with one command with many dependencies downloaded automatically such as web3, cryptojs, bignumber, lodash, grunt, mocha, yargs, etc. When you create a new embark app it should complete by returning “init complete” and by confirming that the embark app is ready.

$ embark new demoCreate a new application with Embark

You can now change directory into the embark_demo and connect your demo to an ethereum node with this command. After you run the command embark should automatically run geth, initialize a genesis block, return the address of the genesis block, give you an IPC and https endpoints, and start to download the DAG. Downloading the DAG will take a couple minutes.

$ embark blockchainCreate a new blockchain instance with Embark

Once the DAG is fully generated the blockchain will begin to mine and a message will be returned to confirm that your account has been funded.

Your Embark account has been funded

Next we can run our app locally by running this command in a new terminal window from the embark demo dapp file directory. This will run our embark dapp in the same way as a traditional application running on localhost and we should be able to view our dapp locally. When we do, a window shows up to show the contracts that are deployed and a log of events.

$ embark runRun your Embark application to see event logs

Your fully functional dapp should now be live on whatever port is specified in your code (localhost:8545 is default). If you look at your folder directory you can see that you have an app folder for your dapp files, including contracts for your smart contract files, css for your styles, js for your javascript files and an index.html for your layout. The config folder is for custom configuration of your blockchain, contracts, etc. The blockchain.json is to configure your blockchain environment and the contracts.json is to configure your smart contracts. The dist folder is for your production code.

In the next Embark tutorial we will walk through how to handle smart contracts using Solidity and Embark. To get a feel for how smart contracts work check out our Introduction to Solidity Smart Contracts tutorial and our How to Setup a Wallet Smart Contract using Solidity tutorial.

MLG Blockchain is a blockchain development and consulting firm based in Toronto that is focused on building next generation applications using blockchain and smart contract technology. View all our blockchain development tutorials at www.mlgblockchain.com/learn.html.

MLG Blockchain