Truffle framework set up a lot of tutorials online, but with the truffle version of the update, truffle.js renamed truffle-config.js, truffle command upgrade, truffle and TESTRPC port inconsistent, Browser wallet plug-ins and other issues, leading to the original tutorial no longer applicable, after stepping on one after another pit, intends to write a non-pit version, so that the vast number of beginners can one go build up the environment.
I. Installing node. JS
Download the installation package at https://nodejs.org/en/and select the LTS version to download.
Write the latest version of the article is 8.11.1, after installation in the Windows Command CMD window, input node-v, can display the version of node succeeded first step two, install truffle
Truffle is a local tool for compiling and deploying smart contracts.
In the Windows command-line window, enter npm-g install truffle.
No error message is successful. Step three, install Ethereum Testrpc
Command Line window input NPM install-g ethereumjs-testrpc
After installing and then entering TESTRPC to see if it started successfully, TESTRPC is listening on the 8545 port by default.
iv. start Dapp
The third step launches the Testrpc window do not close, the newly established development directory HelloWorld, opens a new command window. Go to the Helloword directory.
Truffle initialization
Enter Truffle unbox webpack after execution, and then enter DIR to see if the local download to the new file. Many of the old tutorials on the web are truffle init webpack commands, but truffle new versions are not supported, only truffle unbox webpack.
Build contract
Enter the command truffle compile the following error appears, which is also a pit of the old tutorial.
Rename the truffle.js of the HelloWorld directory to Truffle-config.js, and then execute the command.
Deployment contract
The prerequisite for a successful deployment of a smart contract is that TESTRPC is already running and the input command truffle migrate.
Start the service
Enter the command npm run Dev.
Open Browser, enter http://localhost:8080/, "couldn ' t get any accounts! Make sure Yourethereum client is configured correctly. "
The reason is that the metamask-Ethereum Wallet plugin is installed in the Chrome browser, removing the plugin or using a different browser.
Remove the plugin and open it, prompting "there was an error fetching your accounts."
F12 Open the Developer tool, JS code is the request Testrpc 9545 port.
The request contract port 9545 and TESTRPC listening port 8545 is inconsistent, as long as the two are changed to a consistent line, the solution to the following two select one:
1. Modify the contract call code. Helloworld\app\javascripts\app.js, window.web3 = new Web3 (New Web3.providers.HttpProvider ("http://127.0.0.1:9545") ); The port number 9545 is changed to 8545
2. Change the TESTRPC listening port to 8545.
Use command line testrpc–p 9545 when starting TESTRPC.
The port of the truffle deployment contract is also changed to 9545, and in Truffle-config.js, change port parameter to 9545.
Perform truffle compile, truffle migrate, npm run dev recompile, deploy, start.
Contract Invocation
The TESTRPC console has 10 test addresses and copies an address to transfer the page.