您好,欢迎来到二三四教育网。
搜索
您的当前位置:首页<new version> TruffleDapp_

<new version> TruffleDapp_

来源:二三四教育网
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.

Getting started

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.

OS preparation

Create a vm of ubuntu-16.04.4 from VMware workstation, connect it with Putty.

Install environment

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 <local IP>

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 blockchain

6. Dapp development

$npm run dev

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

Here takes an example of voting App

How an Ethereum Dapp looks like at a high level:

Copyright © 2019- how234.cn 版权所有 赣ICP备2023008801号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务