mac智慧合約metacoin一條龍步驟(nodejs、truffle、atom、ganache)
一、http://nodejs.cn/下載並安裝v8.11.1版本。
可設定npm國內源的命令: sudo npm config set registry http://registry.npm.taobao.org。
二、使用命令 sudo npm install -g truffle 安裝(Truffle v4.1.7 - a development framework for Ethereum)。
三、進入專案目錄cd /Users/shijun/Desktop/truffleWorkspace/metacoin,使用命令truffle unbox metacoin建立自帶demo的工程。(truffle init可建立空工程)
工程結構包括:
1、contracts目錄是Solidity合約程式碼,Migrations.sol必須,其他是自己編寫的合約程式碼。
2、migrations目錄是合約部署指令碼,1_initial_migration.js是部署Migrations.sol的,其他的指令碼按順序依次執行。
3、test目錄是測試程式碼。
四、進入ganache的下載地址https://github.com/trufflesuite/ganache/releases,下載並安裝Ganache-1.1.0.dmg版本,圖形介面形式。(也可以sudo npm install -g ganache-cli命令方式安裝)。
五、修改工程中的truffle.js檔案,部署到區塊鏈網路。
module.exports = {
networks: {
development: {
host: 'localhost',
port: '7545',
network_id: '*' // Match any network id
}
}
};
依次執行truffle命令:
1、truffle compile
2、truffle migrate
3、truffle test
截圖如下:
轉載於:https://my.oschina.net/duojin/blog/1800681