Coder Social home page Coder Social logo

adrianmcli / truffle-react Goto Github PK

View Code? Open in Web Editor NEW
46.0 5.0 5.0 232 KB

⚛️ A boilerplate Truffle Box project with Create React App for rapid Ethereum Dapp development

HTML 12.86% CSS 0.76% JavaScript 86.38%
truffle truffle-framework react reactjs create-react-app solidity ethereum ethereum-contract

truffle-react's Introduction

DEPRECATION NOTICE

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.


Truffle and React.js


comet

Rapid Ethereum Dapp Development

made for ethereum to the moon MIT license


Smart Contract Development with Create-React-App

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.

Installation

  1. Install Truffle globally.

    npm install -g truffle
  2. Download the box. This also takes care of installing the necessary dependencies.

    truffle unbox adrianmcli/truffle-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. 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
  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.

    // If inside the development console.
    test
    
    // If 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.

    // 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
  8. 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

FAQ

  • 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 of truffle.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!

truffle-react's People

Contributors

adrianmcli avatar sinasab avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

truffle-react's Issues

npm run test - ERROR

`sum@XPS15 ~/DEV/truffle-react/client $ npm run test

[email protected] test /home/sum/DEV/truffle-react/client
react-scripts test --env=jsdom

internal/fs/watchers.js:167
throw error;
^

Error: ENOSPC: no space left on device, watch '/home/sum/DEV/truffle-react/client/node_modules/async-each'
at FSWatcher.start (internal/fs/watchers.js:161:26)
at Object.watch (fs.js:1218:11)
at NodeWatcher.watchdir (/home/sum/DEV/truffle-react/client/node_modules/sane/src/node_watcher.js:150:20)
at Walker. (/home/sum/DEV/truffle-react/client/node_modules/sane/src/node_watcher.js:374:12)
at Walker.emit (events.js:182:13)
at /home/sum/DEV/truffle-react/client/node_modules/walker/lib/walker.js:69:16
at go$readdir$cb (/home/sum/DEV/truffle-react/client/node_modules/graceful-fs/graceful-fs.js:149:14)
at FSReqWrap.oncomplete (fs.js:139:20)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] test: react-scripts test --env=jsdom
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! /home/sum/.npm/_logs/2018-08-11T11_18_32_643Z-debug.log`

localhost:3000 says "Failed to load web3, accounts, or contract. Check console for details"

$ npm run start

localhost:3000 says "Failed to load web3, accounts, or contract. Check console for details"

Injected web3 detected.
App.js:28 TypeError: Cannot read property 'address' of undefined
    at Object._callee$ (getContractInstance.js:4)
    at tryCatch (runtime.js:62)
    at Generator.invoke [as _invoke] (runtime.js:296)
    at Generator.prototype.(:3000/anonymous function) [as next] (http://localhost:3000/static/js/bundle.js:63142:21)
    at step (registerServiceWorker.js:117)
    at registerServiceWorker.js:117

Is it a problem because MetaMask already injected an old 0.20 web3 version ? How is this handled best?

License

Could you please add a license file? Everything else looks great.

Add Windows support

Unfortunately I don't have a Windows machine, but in order for Windows support to work, we need to make sure that the symlink is created automatically when unboxing happens. Currently, that is done by running an NPM script npm run link-contracts, but since this uses ln -s, it only works on Linux and Mac.

We basically need a "cross-env" way of doing this.

Failed to load web3, accounts, or contract. Check console for details.

i have install web3,truffle ,python and so on.
npm run start it works .but the edge tell me that Failed to load web3, accounts, or contract. Check console for details. and the console tells that No web3 instance injected, using Local web3.
i don't change any files.i have metamask ,but the port 8545 shows me that it can't connect.i have no idea,please help me! thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.