# 環境建置 [TZ的環境建置](/5B9ARw_zQ_OJafKk-0WRLA) ## 軟體安裝 1. [install Visual Studio Code](/PxNTeUnXTzaE-ONUYRsVyg) 2. [install VS code plugins](/6V6yBSmoRTmwtcOcBzbPWA) 3. [install Node.js](/1DyCd-BnRq2bAKRnb9IepA) 4. [install cmder](/dOivW9NLRESOc2ntJ47fRw) 5. [install Truffle](/HTiZLP1zR5Sl0AbeA4OMMg) 6. [install Ganache](/WtEW7VCxRButAqTEKlWR2w) 7. [install remixd](/aCGvDE2LQ-qPJVmMKw0d6A) ## 佈署建立 [Truffle Tutorial](https://trufflesuite.com/tutorial/index.html) **1. 開啟Ganache**  設置路徑至專案中的truffle-config.js  **2. 記住IP位置**  **3. 建立專案** ```bash= mkdir project_name cd project_name truffle init # 建立 contracts, migrations, truffle-config.js 等檔案 ``` **4. truffle-config.js 連結設定** ```javascript= module.exports = { networks: { development: { host: "127.0.0.1", // Localhost (default: none) port: 7545, // Standard Ethereum port (default: none) network_id: "*", // Any network (default: none) }, }, compilers: { solc: { version: "0.8.10", }, } }, }; ``` **5. Solidity 檔案** <font color="#f00">合約名字要和檔名一致,不然佈署有問題</font> contracts/HelloWorld.sol ```solidity= // SPDX-License-Identifier: MIT // compiler version must be greater than or equal to 0.8.10 and less than 0.9.0 pragma solidity ^0.8.10; contract HelloWorld { string public greet = "Hello World!"; } ``` **6. migrations/2_depoly_hello_world.js 方法1-佈署設定** <font color="#f00">新增的檔名一定要是數字+底線,如果太麻煩,就看方法2</font> ```js= const HelloWorld = artifacts.require("HelloWorld.sol"); module.exports = function (deployer) { deployer.deploy(HelloWorld); }; ``` **6. migrations/1_initial_migration.js 方法2-佈署設定** ```bash= const Migrations = artifacts.require("Migrations"); const HelloWorld = artifacts.require("HelloWorld"); module.exports = function (deployer) { deployer.deploy(Migrations); deployer.deploy(HelloWorld); }; ``` 不加.sol也沒差 **7. 編譯和佈署** ```bash= truffle compile # 編譯 truffle migrate # 執行佈署合約用,他會執行在此專案內migrations資料夾內的檔案 truffle migrate --reset # 如果佈署過了,想重新佈署的指令 # 另外補充 truffle console # 命令行,類似資料庫命令行(mongo之類的) ``` **8. 執行結果** 就被扣錢了  **9. [install remixd](/aCGvDE2LQ-qPJVmMKw0d6A)**
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up