npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

create-react-dapp

v0.3.10

Published

An Ethereum template layered upon create-react-app

Downloads

61

Readme

Create React dApp

An Ethereum dApp bootstrapper.

Quick Start

Install Truffle

npm install -g truffle

Create your app and start a Ganache blockchain.

npx create-react-dapp mydapp
cd mydapp
npm run ganache

Compile and deploy contracts, then launch the app.

In a separate shell (from the same ./mydapp folder)

npm run migrate
npm start

This should launch a browser at URL http://localhost:3000. If it doesn't, try navigating there directly.

Contents

Features

  1. Uses Facebook's create-react-app directly, so it will always retrieve the latest React and Webpack features and best practices, with no configuation.
  2. Clear separation of concerns between the React and Ethereum programming.
  3. Uses Truffle for compilation and migration management of Ganache, Rinkeby, and MainNet configurations.
  4. Minimal and self-contained installation. Doesn't require Remix, Geth, or Parity.

Build Your dApp

  • All of the React code is in the src folder. Most of your work there will be in src/components
  • All of the Ethereum code is in the dapp folder, most of your work will be in the Solidity code of dapp/contracts.
  • When contracts are deployed (or migrated) the necessary contract connection info is copied into the public/contract-info folder.
  • Use src/helpers/fetchContracts.js to retrieve this contract info, so that it can be connected to the appropriate handlers in your app. See src/helpers/Voting.js for example.

Deployment Options

All of the out-of-the box deployment configurations are in the truffle.js file.

All of the npm run ... scripts are in the package.json file.

BTW feel free to use yarn instead of npm in any of the commands below (I do).

Ganache and Ganache UI

The Quick Start section uses the ganache-cli testnet (formerly testrpc). This is the simplest and default configuration.

The Ganache UI gives a more visual and interactive interaction to a Ganache testnet. After installing and launching the Ganache UI. Use

npm run migrate_ganacheUI
npm run start_ganacheUI

💡 Restarting the GanachUI is easy but not obvious. Click on the ⚙️ icon in the upper right of the UI. Then click the "Restart" button.

💡 Truffle migrations are designed to be roughly analogous to database migrations, in that they replace and/or extend the original contracts. Migrations need to be thought through carefully and are case specific. So for simplicity npm run migrate_ganacheUI scripts heavy handedly uses --reset and --compile-all.

Rinkeby and Other Public TestNets

For the public test nets you will need to install MetaMask in your browser. Follow the installation instructions, create an account, then use the upper right menu to select the "Rinkeby Test Network".

⚠️ Security precaution. If you already have a real Ethereum account on the Main Ethereum Network, you should create a new dummy account for use with Rinkeby. This will prevent accidental exposure of your real account's PrivateKey. To do so use the MetaMask account selection icon (top of metamask, second icon from the right).

You will also need to get some test "ether" from the Rinkeby Faucet

Next copy the account's Private Key from MetaMask. To do so click on the ▪️ ▪️ ▪️ icon to the right of the account's name, click "Export Private Key", follow the password prompt, then click on the private key to copy it to the clipboard.

Now we're ready to go. (Be patient with the migration. It can take a minute.)

ETH_PK=<paste private key here> npm run migrate_rinkeby
npm run start_rinkeby

Once a smart contract is deployed to a public network it lives there forever. However our sample contracts inherit from the standard mortal contract, which means they have a "kill" switch. To kill the contracts in Rinkeby use

ETH_PK=<paste private key here> npm run kill_rinkeby

⚠️ Redo'ing the "migrate" step overwrites the contract address in the compilation artifacts, so the "kill" script will not be able to find the contract to kill. So be sure to "kill" the contracts before re-migrating.

The other test nets (Kovan and Ropsten) should be similar, but you will need to add their configs to truffle.js and optionally migrate and start scripts to package.json

Ethereum Main Network

Once everything is tested thoroughly on Rinkeby, you'll (obviously) want to deploy to the Ethereum Main Network. No scripts are included for working with the "live" network, because if you are to this point, you shouldn't need to use the scripts as training wheels.

⚠️ Deploying the contracts will cost you. At the time of this writing it's about $5, and each "vote" in the app costs about $0.10. However if you set your gasPrice too high it can cost you a lot more. So don't put your life savings into the account that you deploy from, and be careful how you set the gas and gasPrice parameters in truffle.js

Testing

A few sample tests are included on both sides of the app. The npm test commands are.

npm run test_components // runs the standard create-react-app Jest tests for the front end.
npm run test_contracts  // launches a silent ganache testnet then runs "truffle test"
npm test                // runs both

Troubleshooting

Installation

  1. Upgrade to node version >=8 and npm version >=5.2.0. The create-react-dapp script depends on npx which is included in the later versions of npm.
  2. Upgrade create-react-app to the latest version. Or even better uninstall it. You probably don't need it anymore since npx create-react-app ... loads and uses the most recent version of create-react-app on the fly.

Migration

If migration fails on GanacheUI just try rerunning. Example error:

Error encountered, bailing. Network state unknown. Review successful transactions manually.
Error: The contract code couldn't be stored, please check your gas amount.
...

Any Other Problems

Please file an issue: https://github.com/mjhm/create-react-dapp/issues

Acknowledgements

  • The starting place for the Voting app in this project came from Mahesh Murthy's Medium article which provides a very easy to follow introduction to writing Ethereum dApps.
  • The Create React App developers have done an awesome job building the very best starting tool for web app development. The standards they've set are an inspiration.
  • The Truffle Framework team is pioneering the infrustructure needed for building Ethereum dApps. This framework is not just providing tools, but also establishing best practices for dApp development.