Installation on React with Truffle Box in Blockchain
MD. SHOHAG MIA
Ex-SELISE & DataSoft | Fintech | .NET(C#) | MSSQL | Solidity | Web3 | Ethereum & Polygon | ERC Standard | IPFS | ETL | Clean Code | Continuous Learner
React Truffle Box
This box comes with everything you need to start using smart contracts from a react app. This is as barebones as it gets, so nothing stands in your way.
Installation
First ensure you are in a new and empty directory.
1. Install Truffle globally in client machines
npm install -g truffle
2. Unbox truffle boilerplate templates that we are working with react js apps. A Create-React-App is generated in the?client?directory.
truffle unbox react
3. Run the development console.
truffle develop
4. Compile and migrate the smart contracts. Note inside the development console we don't preface commands with?truffle.
compile
migrate
5. In the?client?directory, we run the React app. Smart contract changes must be manually recompiled and migrated.
cd client
npm run start
6. 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.
// inside the development console.
test
// outside the development console..
truffle test
7. Jest is included for testing React components. Compile your contracts before running Jest, or you may receive some file not found errors.
// ensure you are inside the client directory when running this
npm run test
8. To build the application for production, use the build script. A production build will be in the?client/build?folder.
// ensure you are inside the client directory when running this
npm run build
More details- https://github.com/truffle-box/react-box
Key Takeaways
truffle compile
truffle migrate
truffle test
truffle migrate --reset
cd client
npm test
npm run start
npm run build
truffle development
truffle develop
truffle build
truffle --quiet
stop truffle develop command- Ctr+D