<new version> TruffleDapp_Metacoin

论坛 期权论坛 区块链     
Olly_Zhang   2018-11-20 23:35   2584   0
            
This article is a summary of how I deploy my first metacoin smart contract to ethereum in the dev env, and all the issues I have met in the deployment are also marked down.[h1]Getting started[/h1]Basic tools we need -
NPM is a package manager for Node.js packages or modules.
Ganachecli: a Nodejs based Ethereum client for testing and development. it runs locally and mimics a full ethererum client but is much faster making it idea for testing and development.
Truffle: a development env, testing framework, and asset pipeline for ethereum. Basically, it helps you delpoy your contracts to the blockchain, and hoop your front-end up to your deployed contracts
MetaMask: an Ethereum light client and Chrome extension that lets users interact with the blockchain without downloading the whole blockchain. In other words, it allows you to interact with dApps in an ordinary Chrome browser.
[h1]OS preparation[/h1]Create a vm of ubuntu-16.04.4 from VMware workstation, connect it with Putty.
[h2]Install environment[/h2]1. install nodejs 5+ (npm)
$ npm install -g web3

2. install truffle
$ npm install -g truffle
To verify it installed, type truffle list in the terminal to list all truffle commands.
3.Init project
$mkdir metacoin
$cd metacoin
Using truffle Dapp framework to init a project
$truffle unbox webpack

Main components in the directory: app/---the entry file to your Dapp including javascript used to talk with smart contract, css file for frontend and html. contracts/---three contracts by default, metacoin.sol; migration.sol; ConvertLab.sol.  node_modules/ ---required modules.4. project deployment
Before smart contract deployed, we need to install an ethereum client as your local personal blockchain, here i use the test dev env of ganache-cli(new version of testrpc);
$npm install -g ganache-cli
$ganache-cli -h

Ganachecli default port: 8545.5. $truffle migrate
If there is error warning you unable to connect to enthereum client, you need open truffle.js to replace the default port of 7545 with 8545.

Make sure the port and host ganache run in the same with $ganache-cli then smart contract could successfully deploy to the blockchain6. Dapp development
$npm run dev

7. Open http://localhost:8080, you should be able to see

8. Add Metamask to chrome
It lets you run Ethereum stuff in a browser without a node.
choose the private network localhost:8545
import private keys to generate all the 10 accounts in Metamask.




Now you should be able to send metacoin to any accounts in MetaMask[h3]Here takes an example of voting App [/h3][h3]How an Ethereum Dapp looks like at a high level:[/h3]


         
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:249
帖子:5
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP