Hi all, I've since joined the Truffle team. If you're looking for a good React boilerplate to start your development, head over to the official React box here which I will be maintaining personally along with the rest of the team.
Rapid Ethereum Dapp Development
How does this differ from the official React Truffle Box?
- No ejection required;
- React frontend is located in its own separate folder (i.e.
/client
); - Babel is included so you can use ES6 module import statements;
- Uses Web3 1.0 beta with PromiEvents
- Truffle-Contract is no longer a dependency
If you have Truffle installed, run the following to get started (more detailed instructions below):
truffle unbox adrianmcli/truffle-react
Note: This Truffle box works by creating a symlink in the client/src
directory to the build/contracts
folder generated by Truffle compiled JSON files (i.e. when truffle compile
is run). Because of this, we cannot support Windows machines at this time. Windows users can still use this Truffle box, but they will have to make the symlink themselves (as per the link-contracts
npm script located inside client/package.json
). If anyone can integrate Windows support for this project, feel free to discuss in the issues and submit a PR.
Consider consulting the Truffle-Next project for a more streamlined React development process.
This Truffle Box is still in early development, there is much work to be done. Any issues and PRs are welcome.
-
Install Truffle globally.
npm install -g truffle
-
Download the box. This also takes care of installing the necessary dependencies.
truffle unbox adrianmcli/truffle-react
-
Run the development console.
truffle develop
-
Compile and migrate the smart contracts. Note inside the development console we don't preface commands with
truffle
.compile migrate
-
Run the webpack server for front-end hot reloading (outside the development console). Smart contract changes must be manually recompiled and migrated.
// Change directory to the front-end folder cd client // Serves the front-end on http://localhost:3000 npm run start
-
Truffle can run tests written in Solidity or JavaScript against your smart contracts. Note the command varies slightly if you're in or outside of the development console.
// If inside the development console. test // If outside the development console.. truffle test
-
Jest is included for testing React components. Compile your contracts before running Jest, or you may receive some file not found errors.
// Make sure you are inside the client folder cd client // Run Jest outside of the development console for front-end component tests. npm run test
-
To build the application for production, use the build command. A production build will be in the build_webpack folder.
// Make sure you are inside the client folder cd client // Run the build script npm run build
-
How do I use this with the EthereumJS TestRPC?
It's as easy as modifying the config file! Check out our documentation on adding network configurations. Depending on the port you're using, you'll also need to update line 24 of
src/utils/getWeb3.js
. -
Why is there both a truffle.js file and a truffle-config.js file?
truffle-config.js
is a copy oftruffle.js
for compatibility with Windows development environments. Feel free to it if it's irrelevant to your platform. -
Where is my production build?
The production build will be in the build_webpack folder. This is because Truffle outputs contract compilations to the build folder.
-
Where can I find more documentation?
This box is a marriage of Truffle and a React setup created with create-react-app. Either one would be a great place to start!