├── .gitignore ├── GeektReactApp ├── .gitignore ├── README.md ├── package.json ├── public │ ├── Blockgeeks-blue-black-white.png │ ├── favicon.ico │ ├── index.html │ └── jquery.ajax-cross-origin.min.js └── src │ ├── App.css │ ├── App.js │ ├── App.test.js │ ├── index.css │ ├── index.js │ └── logo.svg ├── GeektSolidity ├── build │ └── contracts │ │ ├── ConvertLib.json │ │ ├── Geekt.json │ │ ├── MetaCoin.json │ │ └── Migrations.json ├── contracts │ ├── ConvertLib.sol │ ├── Geekt.sol │ ├── MetaCoin.sol │ └── Migrations.sol ├── migrations │ ├── 1_initial_migration.js │ └── 2_deploy_contracts.js ├── test │ ├── TestMetacoin.sol │ └── metacoin.js └── truffle.js ├── LICENSE ├── README.md └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | # Directory for instrumented libs generated by jscoverage/JSCover 12 | lib-cov 13 | 14 | # Coverage directory used by tools like istanbul 15 | coverage 16 | 17 | # nyc test coverage 18 | .nyc_output 19 | 20 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 21 | .grunt 22 | 23 | # node-waf configuration 24 | .lock-wscript 25 | 26 | # Compiled binary addons (http://nodejs.org/api/addons.html) 27 | build/Release 28 | 29 | # Dependency directories 30 | node_modules 31 | jspm_packages 32 | 33 | # Optional npm cache directory 34 | .npm 35 | 36 | # Optional REPL history 37 | .node_repl_history 38 | -------------------------------------------------------------------------------- /GeektReactApp/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | 6 | # testing 7 | /coverage 8 | 9 | # production 10 | /build 11 | 12 | # misc 13 | .DS_Store 14 | .env 15 | npm-debug.log* 16 | yarn-debug.log* 17 | yarn-error.log* 18 | 19 | -------------------------------------------------------------------------------- /GeektReactApp/README.md: -------------------------------------------------------------------------------- 1 | This project was bootstrapped with [Create React App](https://github.com/facebookincubator/create-react-app). 2 | 3 | Below you will find some information on how to perform common tasks.
4 | You can find the most recent version of this guide [here](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md). 5 | 6 | ## Table of Contents 7 | 8 | - [Updating to New Releases](#updating-to-new-releases) 9 | - [Sending Feedback](#sending-feedback) 10 | - [Folder Structure](#folder-structure) 11 | - [Available Scripts](#available-scripts) 12 | - [npm start](#npm-start) 13 | - [npm test](#npm-test) 14 | - [npm run build](#npm-run-build) 15 | - [npm run eject](#npm-run-eject) 16 | - [Supported Language Features and Polyfills](#supported-language-features-and-polyfills) 17 | - [Syntax Highlighting in the Editor](#syntax-highlighting-in-the-editor) 18 | - [Displaying Lint Output in the Editor](#displaying-lint-output-in-the-editor) 19 | - [Debugging in the Editor](#debugging-in-the-editor) 20 | - [Changing the Page ``](#changing-the-page-title) 21 | - [Installing a Dependency](#installing-a-dependency) 22 | - [Importing a Component](#importing-a-component) 23 | - [Adding a Stylesheet](#adding-a-stylesheet) 24 | - [Post-Processing CSS](#post-processing-css) 25 | - [Adding a CSS Preprocessor (Sass, Less etc.)](#adding-a-css-preprocessor-sass-less-etc) 26 | - [Adding Images and Fonts](#adding-images-and-fonts) 27 | - [Using the `public` Folder](#using-the-public-folder) 28 | - [Changing the HTML](#changing-the-html) 29 | - [Adding Assets Outside of the Module System](#adding-assets-outside-of-the-module-system) 30 | - [When to Use the `public` Folder](#when-to-use-the-public-folder) 31 | - [Using Global Variables](#using-global-variables) 32 | - [Adding Bootstrap](#adding-bootstrap) 33 | - [Using a Custom Theme](#using-a-custom-theme) 34 | - [Adding Flow](#adding-flow) 35 | - [Adding Custom Environment Variables](#adding-custom-environment-variables) 36 | - [Referencing Environment Variables in the HTML](#referencing-environment-variables-in-the-html) 37 | - [Adding Temporary Environment Variables In Your Shell](#adding-temporary-environment-variables-in-your-shell) 38 | - [Adding Development Environment Variables In `.env`](#adding-development-environment-variables-in-env) 39 | - [Can I Use Decorators?](#can-i-use-decorators) 40 | - [Integrating with an API Backend](#integrating-with-an-api-backend) 41 | - [Node](#node) 42 | - [Ruby on Rails](#ruby-on-rails) 43 | - [Proxying API Requests in Development](#proxying-api-requests-in-development) 44 | - [Using HTTPS in Development](#using-https-in-development) 45 | - [Generating Dynamic `<meta>` Tags on the Server](#generating-dynamic-meta-tags-on-the-server) 46 | - [Pre-Rendering into Static HTML Files](#pre-rendering-into-static-html-files) 47 | - [Injecting Data from the Server into the Page](#injecting-data-from-the-server-into-the-page) 48 | - [Running Tests](#running-tests) 49 | - [Filename Conventions](#filename-conventions) 50 | - [Command Line Interface](#command-line-interface) 51 | - [Version Control Integration](#version-control-integration) 52 | - [Writing Tests](#writing-tests) 53 | - [Testing Components](#testing-components) 54 | - [Using Third Party Assertion Libraries](#using-third-party-assertion-libraries) 55 | - [Initializing Test Environment](#initializing-test-environment) 56 | - [Focusing and Excluding Tests](#focusing-and-excluding-tests) 57 | - [Coverage Reporting](#coverage-reporting) 58 | - [Continuous Integration](#continuous-integration) 59 | - [Disabling jsdom](#disabling-jsdom) 60 | - [Snapshot Testing](#snapshot-testing) 61 | - [Editor Integration](#editor-integration) 62 | - [Developing Components in Isolation](#developing-components-in-isolation) 63 | - [Making a Progressive Web App](#making-a-progressive-web-app) 64 | - [Deployment](#deployment) 65 | - [Static Server](#static-server) 66 | - [Other Solutions](#other-solutions) 67 | - [Serving Apps with Client-Side Routing](#serving-apps-with-client-side-routing) 68 | - [Building for Relative Paths](#building-for-relative-paths) 69 | - [Azure](#azure) 70 | - [Firebase](#firebase) 71 | - [GitHub Pages](#github-pages) 72 | - [Heroku](#heroku) 73 | - [Modulus](#modulus) 74 | - [Netlify](#netlify) 75 | - [Now](#now) 76 | - [S3 and CloudFront](#s3-and-cloudfront) 77 | - [Surge](#surge) 78 | - [Advanced Configuration](#advanced-configuration) 79 | - [Troubleshooting](#troubleshooting) 80 | - [`npm start` doesn’t detect changes](#npm-start-doesnt-detect-changes) 81 | - [`npm test` hangs on macOS Sierra](#npm-test-hangs-on-macos-sierra) 82 | - [`npm run build` silently fails](#npm-run-build-silently-fails) 83 | - [`npm run build` fails on Heroku](#npm-run-build-fails-on-heroku) 84 | - [Something Missing?](#something-missing) 85 | 86 | ## Updating to New Releases 87 | 88 | Create React App is divided into two packages: 89 | 90 | * `create-react-app` is a global command-line utility that you use to create new projects. 91 | * `react-scripts` is a development dependency in the generated projects (including this one). 92 | 93 | You almost never need to update `create-react-app` itself: it delegates all the setup to `react-scripts`. 94 | 95 | When you run `create-react-app`, it always creates the project with the latest version of `react-scripts` so you’ll get all the new features and improvements in newly created apps automatically. 96 | 97 | To update an existing project to a new version of `react-scripts`, [open the changelog](https://github.com/facebookincubator/create-react-app/blob/master/CHANGELOG.md), find the version you’re currently on (check `package.json` in this folder if you’re not sure), and apply the migration instructions for the newer versions. 98 | 99 | In most cases bumping the `react-scripts` version in `package.json` and running `npm install` in this folder should be enough, but it’s good to consult the [changelog](https://github.com/facebookincubator/create-react-app/blob/master/CHANGELOG.md) for potential breaking changes. 100 | 101 | We commit to keeping the breaking changes minimal so you can upgrade `react-scripts` painlessly. 102 | 103 | ## Sending Feedback 104 | 105 | We are always open to [your feedback](https://github.com/facebookincubator/create-react-app/issues). 106 | 107 | ## Folder Structure 108 | 109 | After creation, your project should look like this: 110 | 111 | ``` 112 | my-app/ 113 | README.md 114 | node_modules/ 115 | package.json 116 | public/ 117 | index.html 118 | favicon.ico 119 | src/ 120 | App.css 121 | App.js 122 | App.test.js 123 | index.css 124 | index.js 125 | logo.svg 126 | ``` 127 | 128 | For the project to build, **these files must exist with exact filenames**: 129 | 130 | * `public/index.html` is the page template; 131 | * `src/index.js` is the JavaScript entry point. 132 | 133 | You can delete or rename the other files. 134 | 135 | You may create subdirectories inside `src`. For faster rebuilds, only files inside `src` are processed by Webpack.<br> 136 | You need to **put any JS and CSS files inside `src`**, or Webpack won’t see them. 137 | 138 | Only files inside `public` can be used from `public/index.html`.<br> 139 | Read instructions below for using assets from JavaScript and HTML. 140 | 141 | You can, however, create more top-level directories.<br> 142 | They will not be included in the production build so you can use them for things like documentation. 143 | 144 | ## Available Scripts 145 | 146 | In the project directory, you can run: 147 | 148 | ### `npm start` 149 | 150 | Runs the app in the development mode.<br> 151 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 152 | 153 | The page will reload if you make edits.<br> 154 | You will also see any lint errors in the console. 155 | 156 | ### `npm test` 157 | 158 | Launches the test runner in the interactive watch mode.<br> 159 | See the section about [running tests](#running-tests) for more information. 160 | 161 | ### `npm run build` 162 | 163 | Builds the app for production to the `build` folder.<br> 164 | It correctly bundles React in production mode and optimizes the build for the best performance. 165 | 166 | The build is minified and the filenames include the hashes.<br> 167 | Your app is ready to be deployed! 168 | 169 | See the section about [deployment](#deployment) for more information. 170 | 171 | ### `npm run eject` 172 | 173 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 174 | 175 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 176 | 177 | Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. 178 | 179 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. 180 | 181 | ## Supported Language Features and Polyfills 182 | 183 | This project supports a superset of the latest JavaScript standard.<br> 184 | In addition to [ES6](https://github.com/lukehoban/es6features) syntax features, it also supports: 185 | 186 | * [Exponentiation Operator](https://github.com/rwaldron/exponentiation-operator) (ES2016). 187 | * [Async/await](https://github.com/tc39/ecmascript-asyncawait) (ES2017). 188 | * [Object Rest/Spread Properties](https://github.com/sebmarkbage/ecmascript-rest-spread) (stage 3 proposal). 189 | * [Class Fields and Static Properties](https://github.com/tc39/proposal-class-public-fields) (stage 2 proposal). 190 | * [JSX](https://facebook.github.io/react/docs/introducing-jsx.html) and [Flow](https://flowtype.org/) syntax. 191 | 192 | Learn more about [different proposal stages](https://babeljs.io/docs/plugins/#presets-stage-x-experimental-presets-). 193 | 194 | While we recommend to use experimental proposals with some caution, Facebook heavily uses these features in the product code, so we intend to provide [codemods](https://medium.com/@cpojer/effective-javascript-codemods-5a6686bb46fb) if any of these proposals change in the future. 195 | 196 | Note that **the project only includes a few ES6 [polyfills](https://en.wikipedia.org/wiki/Polyfill)**: 197 | 198 | * [`Object.assign()`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/assign) via [`object-assign`](https://github.com/sindresorhus/object-assign). 199 | * [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) via [`promise`](https://github.com/then/promise). 200 | * [`fetch()`](https://developer.mozilla.org/en/docs/Web/API/Fetch_API) via [`whatwg-fetch`](https://github.com/github/fetch). 201 | 202 | If you use any other ES6+ features that need **runtime support** (such as `Array.from()` or `Symbol`), make sure you are including the appropriate polyfills manually, or that the browsers you are targeting already support them. 203 | 204 | ## Syntax Highlighting in the Editor 205 | 206 | To configure the syntax highlighting in your favorite text editor, head to the [relevant Babel documentation page](https://babeljs.io/docs/editors) and follow the instructions. Some of the most popular editors are covered. 207 | 208 | ## Displaying Lint Output in the Editor 209 | 210 | >Note: this feature is available with `react-scripts@0.2.0` and higher. 211 | 212 | Some editors, including Sublime Text, Atom, and Visual Studio Code, provide plugins for ESLint. 213 | 214 | They are not required for linting. You should see the linter output right in your terminal as well as the browser console. However, if you prefer the lint results to appear right in your editor, there are some extra steps you can do. 215 | 216 | You would need to install an ESLint plugin for your editor first. 217 | 218 | >**A note for Atom `linter-eslint` users** 219 | 220 | >If you are using the Atom `linter-eslint` plugin, make sure that **Use global ESLint installation** option is checked: 221 | 222 | ><img src="http://i.imgur.com/yVNNHJM.png" width="300"> 223 | 224 | 225 | >**For Visual Studio Code users** 226 | 227 | >VS Code ESLint plugin automatically detects Create React App's configuration file. So you do not need to create `eslintrc.json` at the root directory, except when you want to add your own rules. In that case, you should include CRA's config by adding this line: 228 | 229 | >```js 230 | { 231 | // ... 232 | "extends": "react-app" 233 | } 234 | ``` 235 | 236 | Then add this block to the `package.json` file of your project: 237 | 238 | ```js 239 | { 240 | // ... 241 | "eslintConfig": { 242 | "extends": "react-app" 243 | } 244 | } 245 | ``` 246 | 247 | Finally, you will need to install some packages *globally*: 248 | 249 | ```sh 250 | npm install -g eslint-config-react-app@0.3.0 eslint@3.8.1 babel-eslint@7.0.0 eslint-plugin-react@6.4.1 eslint-plugin-import@2.0.1 eslint-plugin-jsx-a11y@4.0.0 eslint-plugin-flowtype@2.21.0 251 | ``` 252 | 253 | We recognize that this is suboptimal, but it is currently required due to the way we hide the ESLint dependency. The ESLint team is already [working on a solution to this](https://github.com/eslint/eslint/issues/3458) so this may become unnecessary in a couple of months. 254 | 255 | ## Debugging in the Editor 256 | 257 | **This feature is currently only supported by [Visual Studio Code](https://code.visualstudio.com) editor.** 258 | 259 | Visual Studio Code supports live-editing and debugging out of the box with Create React App. This enables you as a developer to write and debug your React code without leaving the editor, and most importantly it enables you to have a continuous development workflow, where context switching is minimal, as you don’t have to switch between tools. 260 | 261 | You would need to have the latest version of [VS Code](https://code.visualstudio.com) and VS Code [Chrome Debugger Extension](https://marketplace.visualstudio.com/items?itemName=msjsdiag.debugger-for-chrome) installed. 262 | 263 | Then add the block below to your `launch.json` file and put it inside the `.vscode` folder in your app’s root directory. 264 | 265 | ```json 266 | { 267 | "version": "0.2.0", 268 | "configurations": [{ 269 | "name": "Chrome", 270 | "type": "chrome", 271 | "request": "launch", 272 | "url": "http://localhost:3000", 273 | "webRoot": "${workspaceRoot}/src", 274 | "userDataDir": "${workspaceRoot}/.vscode/chrome", 275 | "sourceMapPathOverrides": { 276 | "webpack:///src/*": "${webRoot}/*" 277 | } 278 | }] 279 | } 280 | ``` 281 | 282 | Start your app by running `npm start`, and start debugging in VS Code by pressing `F5` or by clicking the green debug icon. You can now write code, set breakpoints, make changes to the code, and debug your newly modified code—all from your editor. 283 | 284 | ## Changing the Page `<title>` 285 | 286 | You can find the source HTML file in the `public` folder of the generated project. You may edit the `<title>` tag in it to change the title from “React App” to anything else. 287 | 288 | Note that normally you wouldn’t edit files in the `public` folder very often. For example, [adding a stylesheet](#adding-a-stylesheet) is done without touching the HTML. 289 | 290 | If you need to dynamically update the page title based on the content, you can use the browser [`document.title`](https://developer.mozilla.org/en-US/docs/Web/API/Document/title) API. For more complex scenarios when you want to change the title from React components, you can use [React Helmet](https://github.com/nfl/react-helmet), a third party library. 291 | 292 | If you use a custom server for your app in production and want to modify the title before it gets sent to the browser, you can follow advice in [this section](#generating-dynamic-meta-tags-on-the-server). Alternatively, you can pre-build each page as a static HTML file which then loads the JavaScript bundle, which is covered [here](#pre-rendering-into-static-html-files). 293 | 294 | ## Installing a Dependency 295 | 296 | The generated project includes React and ReactDOM as dependencies. It also includes a set of scripts used by Create React App as a development dependency. You may install other dependencies (for example, React Router) with `npm`: 297 | 298 | ``` 299 | npm install --save <library-name> 300 | ``` 301 | 302 | ## Importing a Component 303 | 304 | This project setup supports ES6 modules thanks to Babel.<br> 305 | While you can still use `require()` and `module.exports`, we encourage you to use [`import` and `export`](http://exploringjs.com/es6/ch_modules.html) instead. 306 | 307 | For example: 308 | 309 | ### `Button.js` 310 | 311 | ```js 312 | import React, { Component } from 'react'; 313 | 314 | class Button extends Component { 315 | render() { 316 | // ... 317 | } 318 | } 319 | 320 | export default Button; // Don’t forget to use export default! 321 | ``` 322 | 323 | ### `DangerButton.js` 324 | 325 | 326 | ```js 327 | import React, { Component } from 'react'; 328 | import Button from './Button'; // Import a component from another file 329 | 330 | class DangerButton extends Component { 331 | render() { 332 | return <Button color="red" />; 333 | } 334 | } 335 | 336 | export default DangerButton; 337 | ``` 338 | 339 | Be aware of the [difference between default and named exports](http://stackoverflow.com/questions/36795819/react-native-es-6-when-should-i-use-curly-braces-for-import/36796281#36796281). It is a common source of mistakes. 340 | 341 | We suggest that you stick to using default imports and exports when a module only exports a single thing (for example, a component). That’s what you get when you use `export default Button` and `import Button from './Button'`. 342 | 343 | Named exports are useful for utility modules that export several functions. A module may have at most one default export and as many named exports as you like. 344 | 345 | Learn more about ES6 modules: 346 | 347 | * [When to use the curly braces?](http://stackoverflow.com/questions/36795819/react-native-es-6-when-should-i-use-curly-braces-for-import/36796281#36796281) 348 | * [Exploring ES6: Modules](http://exploringjs.com/es6/ch_modules.html) 349 | * [Understanding ES6: Modules](https://leanpub.com/understandinges6/read#leanpub-auto-encapsulating-code-with-modules) 350 | 351 | ## Adding a Stylesheet 352 | 353 | This project setup uses [Webpack](https://webpack.github.io/) for handling all assets. Webpack offers a custom way of “extending” the concept of `import` beyond JavaScript. To express that a JavaScript file depends on a CSS file, you need to **import the CSS from the JavaScript file**: 354 | 355 | ### `Button.css` 356 | 357 | ```css 358 | .Button { 359 | padding: 20px; 360 | } 361 | ``` 362 | 363 | ### `Button.js` 364 | 365 | ```js 366 | import React, { Component } from 'react'; 367 | import './Button.css'; // Tell Webpack that Button.js uses these styles 368 | 369 | class Button extends Component { 370 | render() { 371 | // You can use them as regular CSS styles 372 | return <div className="Button" />; 373 | } 374 | } 375 | ``` 376 | 377 | **This is not required for React** but many people find this feature convenient. You can read about the benefits of this approach [here](https://medium.com/seek-ui-engineering/block-element-modifying-your-javascript-components-d7f99fcab52b). However you should be aware that this makes your code less portable to other build tools and environments than Webpack. 378 | 379 | In development, expressing dependencies this way allows your styles to be reloaded on the fly as you edit them. In production, all CSS files will be concatenated into a single minified `.css` file in the build output. 380 | 381 | If you are concerned about using Webpack-specific semantics, you can put all your CSS right into `src/index.css`. It would still be imported from `src/index.js`, but you could always remove that import if you later migrate to a different build tool. 382 | 383 | ## Post-Processing CSS 384 | 385 | This project setup minifies your CSS and adds vendor prefixes to it automatically through [Autoprefixer](https://github.com/postcss/autoprefixer) so you don’t need to worry about it. 386 | 387 | For example, this: 388 | 389 | ```css 390 | .App { 391 | display: flex; 392 | flex-direction: row; 393 | align-items: center; 394 | } 395 | ``` 396 | 397 | becomes this: 398 | 399 | ```css 400 | .App { 401 | display: -webkit-box; 402 | display: -ms-flexbox; 403 | display: flex; 404 | -webkit-box-orient: horizontal; 405 | -webkit-box-direction: normal; 406 | -ms-flex-direction: row; 407 | flex-direction: row; 408 | -webkit-box-align: center; 409 | -ms-flex-align: center; 410 | align-items: center; 411 | } 412 | ``` 413 | 414 | If you need to disable autoprefixing for some reason, [follow this section](https://github.com/postcss/autoprefixer#disabling). 415 | 416 | ## Adding a CSS Preprocessor (Sass, Less etc.) 417 | 418 | Generally, we recommend that you don’t reuse the same CSS classes across different components. For example, instead of using a `.Button` CSS class in `<AcceptButton>` and `<RejectButton>` components, we recommend creating a `<Button>` component with its own `.Button` styles, that both `<AcceptButton>` and `<RejectButton>` can render (but [not inherit](https://facebook.github.io/react/docs/composition-vs-inheritance.html)). 419 | 420 | Following this rule often makes CSS preprocessors less useful, as features like mixins and nesting are replaced by component composition. You can, however, integrate a CSS preprocessor if you find it valuable. In this walkthrough, we will be using Sass, but you can also use Less, or another alternative. 421 | 422 | First, let’s install the command-line interface for Sass: 423 | 424 | ``` 425 | npm install node-sass --save-dev 426 | ``` 427 | 428 | Then in `package.json`, add the following lines to `scripts`: 429 | 430 | ```diff 431 | "scripts": { 432 | + "build-css": "node-sass src/ -o src/", 433 | + "watch-css": "npm run build-css && node-sass src/ -o src/ --watch --recursive", 434 | "start": "react-scripts start", 435 | "build": "react-scripts build", 436 | "test": "react-scripts test --env=jsdom", 437 | ``` 438 | 439 | >Note: To use a different preprocessor, replace `build-css` and `watch-css` commands according to your preprocessor’s documentation. 440 | 441 | Now you can rename `src/App.css` to `src/App.scss` and run `npm run watch-css`. The watcher will find every Sass file in `src` subdirectories, and create a corresponding CSS file next to it, in our case overwriting `src/App.css`. Since `src/App.js` still imports `src/App.css`, the styles become a part of your application. You can now edit `src/App.scss`, and `src/App.css` will be regenerated. 442 | 443 | To share variables between Sass files, you can use Sass imports. For example, `src/App.scss` and other component style files could include `@import "./shared.scss";` with variable definitions. 444 | 445 | At this point you might want to remove all CSS files from the source control, and add `src/**/*.css` to your `.gitignore` file. It is generally a good practice to keep the build products outside of the source control. 446 | 447 | As a final step, you may find it convenient to run `watch-css` automatically with `npm start`, and run `build-css` as a part of `npm run build`. You can use the `&&` operator to execute two scripts sequentially. However, there is no cross-platform way to run two scripts in parallel, so we will install a package for this: 448 | 449 | ``` 450 | npm install --save-dev npm-run-all 451 | ``` 452 | 453 | Then we can change `start` and `build` scripts to include the CSS preprocessor commands: 454 | 455 | ```diff 456 | "scripts": { 457 | "build-css": "node-sass src/ -o src/", 458 | "watch-css": "npm run build-css && node-sass src/ -o src/ --watch --recursive", 459 | - "start": "react-scripts start", 460 | - "build": "react-scripts build", 461 | + "start-js": "react-scripts start", 462 | + "start": "npm-run-all -p watch-css start-js", 463 | + "build": "npm run build-css && react-scripts build", 464 | "test": "react-scripts test --env=jsdom", 465 | "eject": "react-scripts eject" 466 | } 467 | ``` 468 | 469 | Now running `npm start` and `npm run build` also builds Sass files. Note that `node-sass` seems to have an [issue recognizing newly created files on some systems](https://github.com/sass/node-sass/issues/1891) so you might need to restart the watcher when you create a file until it’s resolved. 470 | 471 | ## Adding Images and Fonts 472 | 473 | With Webpack, using static assets like images and fonts works similarly to CSS. 474 | 475 | You can **`import` an image right in a JavaScript module**. This tells Webpack to include that image in the bundle. Unlike CSS imports, importing an image or a font gives you a string value. This value is the final image path you can reference in your code. 476 | 477 | Here is an example: 478 | 479 | ```js 480 | import React from 'react'; 481 | import logo from './logo.png'; // Tell Webpack this JS file uses this image 482 | 483 | console.log(logo); // /logo.84287d09.png 484 | 485 | function Header() { 486 | // Import result is the URL of your image 487 | return <img src={logo} alt="Logo" />; 488 | } 489 | 490 | export default Header; 491 | ``` 492 | 493 | This ensures that when the project is built, Webpack will correctly move the images into the build folder, and provide us with correct paths. 494 | 495 | This works in CSS too: 496 | 497 | ```css 498 | .Logo { 499 | background-image: url(./logo.png); 500 | } 501 | ``` 502 | 503 | Webpack finds all relative module references in CSS (they start with `./`) and replaces them with the final paths from the compiled bundle. If you make a typo or accidentally delete an important file, you will see a compilation error, just like when you import a non-existent JavaScript module. The final filenames in the compiled bundle are generated by Webpack from content hashes. If the file content changes in the future, Webpack will give it a different name in production so you don’t need to worry about long-term caching of assets. 504 | 505 | Please be advised that this is also a custom feature of Webpack. 506 | 507 | **It is not required for React** but many people enjoy it (and React Native uses a similar mechanism for images).<br> 508 | An alternative way of handling static assets is described in the next section. 509 | 510 | ## Using the `public` Folder 511 | 512 | >Note: this feature is available with `react-scripts@0.5.0` and higher. 513 | 514 | ### Changing the HTML 515 | 516 | The `public` folder contains the HTML file so you can tweak it, for example, to [set the page title](#changing-the-page-title). 517 | The `<script>` tag with the compiled code will be added to it automatically during the build process. 518 | 519 | ### Adding Assets Outside of the Module System 520 | 521 | You can also add other assets to the `public` folder. 522 | 523 | Note that we normally encourage you to `import` assets in JavaScript files instead. 524 | For example, see the sections on [adding a stylesheet](#adding-a-stylesheet) and [adding images and fonts](#adding-images-and-fonts). 525 | This mechanism provides a number of benefits: 526 | 527 | * Scripts and stylesheets get minified and bundled together to avoid extra network requests. 528 | * Missing files cause compilation errors instead of 404 errors for your users. 529 | * Result filenames include content hashes so you don’t need to worry about browsers caching their old versions. 530 | 531 | However there is an **escape hatch** that you can use to add an asset outside of the module system. 532 | 533 | If you put a file into the `public` folder, it will **not** be processed by Webpack. Instead it will be copied into the build folder untouched. To reference assets in the `public` folder, you need to use a special variable called `PUBLIC_URL`. 534 | 535 | Inside `index.html`, you can use it like this: 536 | 537 | ```html 538 | <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico"> 539 | ``` 540 | 541 | Only files inside the `public` folder will be accessible by `%PUBLIC_URL%` prefix. If you need to use a file from `src` or `node_modules`, you’ll have to copy it there to explicitly specify your intention to make this file a part of the build. 542 | 543 | When you run `npm run build`, Create React App will substitute `%PUBLIC_URL%` with a correct absolute path so your project works even if you use client-side routing or host it at a non-root URL. 544 | 545 | In JavaScript code, you can use `process.env.PUBLIC_URL` for similar purposes: 546 | 547 | ```js 548 | render() { 549 | // Note: this is an escape hatch and should be used sparingly! 550 | // Normally we recommend using `import` for getting asset URLs 551 | // as described in “Adding Images and Fonts” above this section. 552 | return <img src={process.env.PUBLIC_URL + '/img/logo.png'} />; 553 | } 554 | ``` 555 | 556 | Keep in mind the downsides of this approach: 557 | 558 | * None of the files in `public` folder get post-processed or minified. 559 | * Missing files will not be called at compilation time, and will cause 404 errors for your users. 560 | * Result filenames won’t include content hashes so you’ll need to add query arguments or rename them every time they change. 561 | 562 | ### When to Use the `public` Folder 563 | 564 | Normally we recommend importing [stylesheets](#adding-a-stylesheet), [images, and fonts](#adding-images-and-fonts) from JavaScript. 565 | The `public` folder is useful as a workaround for a number of less common cases: 566 | 567 | * You need a file with a specific name in the build output, such as [`manifest.webmanifest`](https://developer.mozilla.org/en-US/docs/Web/Manifest). 568 | * You have thousands of images and need to dynamically reference their paths. 569 | * You want to include a small script like [`pace.js`](http://github.hubspot.com/pace/docs/welcome/) outside of the bundled code. 570 | * Some library may be incompatible with Webpack and you have no other option but to include it as a `<script>` tag. 571 | 572 | Note that if you add a `<script>` that declares global variables, you also need to read the next section on using them. 573 | 574 | ## Using Global Variables 575 | 576 | When you include a script in the HTML file that defines global variables and try to use one of these variables in the code, the linter will complain because it cannot see the definition of the variable. 577 | 578 | You can avoid this by reading the global variable explicitly from the `window` object, for example: 579 | 580 | ```js 581 | const $ = window.$; 582 | ``` 583 | 584 | This makes it obvious you are using a global variable intentionally rather than because of a typo. 585 | 586 | Alternatively, you can force the linter to ignore any line by adding `// eslint-disable-line` after it. 587 | 588 | ## Adding Bootstrap 589 | 590 | You don’t have to use [React Bootstrap](https://react-bootstrap.github.io) together with React but it is a popular library for integrating Bootstrap with React apps. If you need it, you can integrate it with Create React App by following these steps: 591 | 592 | Install React Bootstrap and Bootstrap from npm. React Bootstrap does not include Bootstrap CSS so this needs to be installed as well: 593 | 594 | ``` 595 | npm install react-bootstrap --save 596 | npm install bootstrap@3 --save 597 | ``` 598 | 599 | Import Bootstrap CSS and optionally Bootstrap theme CSS in the beginning of your ```src/index.js``` file: 600 | 601 | ```js 602 | import 'bootstrap/dist/css/bootstrap.css'; 603 | import 'bootstrap/dist/css/bootstrap-theme.css'; 604 | // Put any other imports below so that CSS from your 605 | // components takes precedence over default styles. 606 | ``` 607 | 608 | Import required React Bootstrap components within ```src/App.js``` file or your custom component files: 609 | 610 | ```js 611 | import { Navbar, Jumbotron, Button } from 'react-bootstrap'; 612 | ``` 613 | 614 | Now you are ready to use the imported React Bootstrap components within your component hierarchy defined in the render method. Here is an example [`App.js`](https://gist.githubusercontent.com/gaearon/85d8c067f6af1e56277c82d19fd4da7b/raw/6158dd991b67284e9fc8d70b9d973efe87659d72/App.js) redone using React Bootstrap. 615 | 616 | ### Using a Custom Theme 617 | 618 | Sometimes you might need to tweak the visual styles of Bootstrap (or equivalent package).<br> 619 | We suggest the following approach: 620 | 621 | * Create a new package that depends on the package you wish to customize, e.g. Bootstrap. 622 | * Add the necessary build steps to tweak the theme, and publish your package on npm. 623 | * Install your own theme npm package as a dependency of your app. 624 | 625 | Here is an example of adding a [customized Bootstrap](https://medium.com/@tacomanator/customizing-create-react-app-aa9ffb88165) that follows these steps. 626 | 627 | ## Adding Flow 628 | 629 | Flow is a static type checker that helps you write code with fewer bugs. Check out this [introduction to using static types in JavaScript](https://medium.com/@preethikasireddy/why-use-static-types-in-javascript-part-1-8382da1e0adb) if you are new to this concept. 630 | 631 | Recent versions of [Flow](http://flowtype.org/) work with Create React App projects out of the box. 632 | 633 | To add Flow to a Create React App project, follow these steps: 634 | 635 | 1. Run `npm install --save-dev flow-bin` (or `yarn add --dev flow-bin`). 636 | 2. Add `"flow": "flow"` to the `scripts` section of your `package.json`. 637 | 3. Run `npm run flow -- init` (or `yarn flow -- init`) to create a [`.flowconfig` file](https://flowtype.org/docs/advanced-configuration.html) in the root directory. 638 | 4. Add `// @flow` to any files you want to type check (for example, to `src/App.js`). 639 | 640 | Now you can run `npm run flow` (or `yarn flow`) to check the files for type errors. 641 | You can optionally use an IDE like [Nuclide](https://nuclide.io/docs/languages/flow/) for a better integrated experience. 642 | In the future we plan to integrate it into Create React App even more closely. 643 | 644 | To learn more about Flow, check out [its documentation](https://flowtype.org/). 645 | 646 | ## Adding Custom Environment Variables 647 | 648 | >Note: this feature is available with `react-scripts@0.2.3` and higher. 649 | 650 | Your project can consume variables declared in your environment as if they were declared locally in your JS files. By 651 | default you will have `NODE_ENV` defined for you, and any other environment variables starting with 652 | `REACT_APP_`. 653 | 654 | **The environment variables are embedded during the build time**. Since Create React App produces a static HTML/CSS/JS bundle, it can’t possibly read them at runtime. To read them at runtime, you would need to load HTML into memory on the server and replace placeholders in runtime, just like [described here](#injecting-data-from-the-server-into-the-page). Alternatively you can rebuild the app on the server anytime you change them. 655 | 656 | >Note: You must create custom environment variables beginning with `REACT_APP_`. Any other variables except `NODE_ENV` will be ignored to avoid accidentally [exposing a private key on the machine that could have the same name](https://github.com/facebookincubator/create-react-app/issues/865#issuecomment-252199527). Changing any environment variables will require you to restart the development server if it is running. 657 | 658 | These environment variables will be defined for you on `process.env`. For example, having an environment 659 | variable named `REACT_APP_SECRET_CODE` will be exposed in your JS as `process.env.REACT_APP_SECRET_CODE`. 660 | 661 | There is also a special built-in environment variable called `NODE_ENV`. You can read it from `process.env.NODE_ENV`. When you run `npm start`, it is always equal to `'development'`, when you run `npm test` it is always equal to `'test'`, and when you run `npm run build` to make a production bundle, it is always equal to `'production'`. **You cannot override `NODE_ENV` manually.** This prevents developers from accidentally deploying a slow development build to production. 662 | 663 | These environment variables can be useful for displaying information conditionally based on where the project is 664 | deployed or consuming sensitive data that lives outside of version control. 665 | 666 | First, you need to have environment variables defined. For example, let’s say you wanted to consume a secret defined 667 | in the environment inside a `<form>`: 668 | 669 | ```jsx 670 | render() { 671 | return ( 672 | <div> 673 | <small>You are running this application in <b>{process.env.NODE_ENV}</b> mode.</small> 674 | <form> 675 | <input type="hidden" defaultValue={process.env.REACT_APP_SECRET_CODE} /> 676 | </form> 677 | </div> 678 | ); 679 | } 680 | ``` 681 | 682 | During the build, `process.env.REACT_APP_SECRET_CODE` will be replaced with the current value of the `REACT_APP_SECRET_CODE` environment variable. Remember that the `NODE_ENV` variable will be set for you automatically. 683 | 684 | When you load the app in the browser and inspect the `<input>`, you will see its value set to `abcdef`, and the bold text will show the environment provided when using `npm start`: 685 | 686 | ```html 687 | <div> 688 | <small>You are running this application in <b>development</b> mode.</small> 689 | <form> 690 | <input type="hidden" value="abcdef" /> 691 | </form> 692 | </div> 693 | ``` 694 | 695 | The above form is looking for a variable called `REACT_APP_SECRET_CODE` from the environment. In order to consume this 696 | value, we need to have it defined in the environment. This can be done using two ways: either in your shell or in 697 | a `.env` file. Both of these ways are described in the next few sections. 698 | 699 | Having access to the `NODE_ENV` is also useful for performing actions conditionally: 700 | 701 | ```js 702 | if (process.env.NODE_ENV !== 'production') { 703 | analytics.disable(); 704 | } 705 | ``` 706 | 707 | When you compile the app with `npm run build`, the minification step will strip out this condition, and the resulting bundle will be smaller. 708 | 709 | ### Referencing Environment Variables in the HTML 710 | 711 | >Note: this feature is available with `react-scripts@0.9.0` and higher. 712 | 713 | You can also access the environment variables starting with `REACT_APP_` in the `public/index.html`. For example: 714 | 715 | ```html 716 | <title>%REACT_APP_WEBSITE_NAME% 717 | ``` 718 | 719 | Note that the caveats from the above section apply: 720 | 721 | * Apart from a few built-in variables (`NODE_ENV` and `PUBLIC_URL`), variable names must start with `REACT_APP_` to work. 722 | * The environment variables are injected at build time. If you need to inject them at runtime, [follow this approach instead](#generating-dynamic-meta-tags-on-the-server). 723 | 724 | ### Adding Temporary Environment Variables In Your Shell 725 | 726 | Defining environment variables can vary between OSes. It’s also important to know that this manner is temporary for the 727 | life of the shell session. 728 | 729 | #### Windows (cmd.exe) 730 | 731 | ```cmd 732 | set REACT_APP_SECRET_CODE=abcdef&&npm start 733 | ``` 734 | 735 | (Note: the lack of whitespace is intentional.) 736 | 737 | #### Linux, macOS (Bash) 738 | 739 | ```bash 740 | REACT_APP_SECRET_CODE=abcdef npm start 741 | ``` 742 | 743 | ### Adding Development Environment Variables In `.env` 744 | 745 | >Note: this feature is available with `react-scripts@0.5.0` and higher. 746 | 747 | To define permanent environment variables, create a file called `.env` in the root of your project: 748 | 749 | ``` 750 | REACT_APP_SECRET_CODE=abcdef 751 | ``` 752 | 753 | These variables will act as the defaults if the machine does not explicitly set them.
754 | Please refer to the [dotenv documentation](https://github.com/motdotla/dotenv) for more details. 755 | 756 | >Note: If you are defining environment variables for development, your CI and/or hosting platform will most likely need 757 | these defined as well. Consult their documentation how to do this. For example, see the documentation for [Travis CI](https://docs.travis-ci.com/user/environment-variables/) or [Heroku](https://devcenter.heroku.com/articles/config-vars). 758 | 759 | ## Can I Use Decorators? 760 | 761 | Many popular libraries use [decorators](https://medium.com/google-developers/exploring-es7-decorators-76ecb65fb841) in their documentation.
762 | Create React App doesn’t support decorator syntax at the moment because: 763 | 764 | * It is an experimental proposal and is subject to change. 765 | * The current specification version is not officially supported by Babel. 766 | * If the specification changes, we won’t be able to write a codemod because we don’t use them internally at Facebook. 767 | 768 | However in many cases you can rewrite decorator-based code without decorators just as fine.
769 | Please refer to these two threads for reference: 770 | 771 | * [#214](https://github.com/facebookincubator/create-react-app/issues/214) 772 | * [#411](https://github.com/facebookincubator/create-react-app/issues/411) 773 | 774 | Create React App will add decorator support when the specification advances to a stable stage. 775 | 776 | ## Integrating with an API Backend 777 | 778 | These tutorials will help you to integrate your app with an API backend running on another port, 779 | using `fetch()` to access it. 780 | 781 | ### Node 782 | Check out [this tutorial](https://www.fullstackreact.com/articles/using-create-react-app-with-a-server/). 783 | You can find the companion GitHub repository [here](https://github.com/fullstackreact/food-lookup-demo). 784 | 785 | ### Ruby on Rails 786 | 787 | Check out [this tutorial](https://www.fullstackreact.com/articles/how-to-get-create-react-app-to-work-with-your-rails-api/). 788 | You can find the companion GitHub repository [here](https://github.com/fullstackreact/food-lookup-demo-rails). 789 | 790 | ## Proxying API Requests in Development 791 | 792 | >Note: this feature is available with `react-scripts@0.2.3` and higher. 793 | 794 | People often serve the front-end React app from the same host and port as their backend implementation.
795 | For example, a production setup might look like this after the app is deployed: 796 | 797 | ``` 798 | / - static server returns index.html with React app 799 | /todos - static server returns index.html with React app 800 | /api/todos - server handles any /api/* requests using the backend implementation 801 | ``` 802 | 803 | Such setup is **not** required. However, if you **do** have a setup like this, it is convenient to write requests like `fetch('/api/todos')` without worrying about redirecting them to another host or port during development. 804 | 805 | To tell the development server to proxy any unknown requests to your API server in development, add a `proxy` field to your `package.json`, for example: 806 | 807 | ```js 808 | "proxy": "http://localhost:4000", 809 | ``` 810 | 811 | This way, when you `fetch('/api/todos')` in development, the development server will recognize that it’s not a static asset, and will proxy your request to `http://localhost:4000/api/todos` as a fallback. The development server will only attempt to send requests without a `text/html` accept header to the proxy. 812 | 813 | Conveniently, this avoids [CORS issues](http://stackoverflow.com/questions/21854516/understanding-ajax-cors-and-security-considerations) and error messages like this in development: 814 | 815 | ``` 816 | Fetch API cannot load http://localhost:4000/api/todos. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled. 817 | ``` 818 | 819 | Keep in mind that `proxy` only has effect in development (with `npm start`), and it is up to you to ensure that URLs like `/api/todos` point to the right thing in production. You don’t have to use the `/api` prefix. Any unrecognized request without a `text/html` accept header will be redirected to the specified `proxy`. 820 | 821 | The `proxy` option supports HTTP, HTTPS and WebSocket connections.
822 | If the `proxy` option is **not** flexible enough for you, alternatively you can: 823 | 824 | * Enable CORS on your server ([here’s how to do it for Express](http://enable-cors.org/server_expressjs.html)). 825 | * Use [environment variables](#adding-custom-environment-variables) to inject the right server host and port into your app. 826 | 827 | ## Using HTTPS in Development 828 | 829 | >Note: this feature is available with `react-scripts@0.4.0` and higher. 830 | 831 | You may require the dev server to serve pages over HTTPS. One particular case where this could be useful is when using [the "proxy" feature](#proxying-api-requests-in-development) to proxy requests to an API server when that API server is itself serving HTTPS. 832 | 833 | To do this, set the `HTTPS` environment variable to `true`, then start the dev server as usual with `npm start`: 834 | 835 | #### Windows (cmd.exe) 836 | 837 | ```cmd 838 | set HTTPS=true&&npm start 839 | ``` 840 | 841 | (Note: the lack of whitespace is intentional.) 842 | 843 | #### Linux, macOS (Bash) 844 | 845 | ```bash 846 | HTTPS=true npm start 847 | ``` 848 | 849 | Note that the server will use a self-signed certificate, so your web browser will almost definitely display a warning upon accessing the page. 850 | 851 | ## Generating Dynamic `` Tags on the Server 852 | 853 | Since Create React App doesn’t support server rendering, you might be wondering how to make `` tags dynamic and reflect the current URL. To solve this, we recommend to add placeholders into the HTML, like this: 854 | 855 | ```html 856 | 857 | 858 | 859 | 860 | 861 | ``` 862 | 863 | Then, on the server, regardless of the backend you use, you can read `index.html` into memory and replace `__OG_TITLE__`, `__OG_DESCRIPTION__`, and any other placeholders with values depending on the current URL. Just make sure to sanitize and escape the interpolated values so that they are safe to embed into HTML! 864 | 865 | If you use a Node server, you can even share the route matching logic between the client and the server. However duplicating it also works fine in simple cases. 866 | 867 | ## Pre-Rendering into Static HTML Files 868 | 869 | If you’re hosting your `build` with a static hosting provider you can use [react-snapshot](https://www.npmjs.com/package/react-snapshot) to generate HTML pages for each route, or relative link, in your application. These pages will then seamlessly become active, or “hydrated”, when the JavaScript bundle has loaded. 870 | 871 | There are also opportunities to use this outside of static hosting, to take the pressure off the server when generating and caching routes. 872 | 873 | The primary benefit of pre-rendering is that you get the core content of each page _with_ the HTML payload—regardless of whether or not your JavaScript bundle successfully downloads. It also increases the likelihood that each route of your application will be picked up by search engines. 874 | 875 | You can read more about [zero-configuration pre-rendering (also called snapshotting) here](https://medium.com/superhighfives/an-almost-static-stack-6df0a2791319). 876 | 877 | ## Injecting Data from the Server into the Page 878 | 879 | Similarly to the previous section, you can leave some placeholders in the HTML that inject global variables, for example: 880 | 881 | ```js 882 | 883 | 884 | 885 | 888 | ``` 889 | 890 | Then, on the server, you can replace `__SERVER_DATA__` with a JSON of real data right before sending the response. The client code can then read `window.SERVER_DATA` to use it. **Make sure to [sanitize the JSON before sending it to the client](https://medium.com/node-security/the-most-common-xss-vulnerability-in-react-js-applications-2bdffbcc1fa0) as it makes your app vulnerable to XSS attacks.** 891 | 892 | ## Running Tests 893 | 894 | >Note: this feature is available with `react-scripts@0.3.0` and higher.
895 | >[Read the migration guide to learn how to enable it in older projects!](https://github.com/facebookincubator/create-react-app/blob/master/CHANGELOG.md#migrating-from-023-to-030) 896 | 897 | Create React App uses [Jest](https://facebook.github.io/jest/) as its test runner. To prepare for this integration, we did a [major revamp](https://facebook.github.io/jest/blog/2016/09/01/jest-15.html) of Jest so if you heard bad things about it years ago, give it another try. 898 | 899 | Jest is a Node-based runner. This means that the tests always run in a Node environment and not in a real browser. This lets us enable fast iteration speed and prevent flakiness. 900 | 901 | While Jest provides browser globals such as `window` thanks to [jsdom](https://github.com/tmpvar/jsdom), they are only approximations of the real browser behavior. Jest is intended to be used for unit tests of your logic and your components rather than the DOM quirks. 902 | 903 | We recommend that you use a separate tool for browser end-to-end tests if you need them. They are beyond the scope of Create React App. 904 | 905 | ### Filename Conventions 906 | 907 | Jest will look for test files with any of the following popular naming conventions: 908 | 909 | * Files with `.js` suffix in `__tests__` folders. 910 | * Files with `.test.js` suffix. 911 | * Files with `.spec.js` suffix. 912 | 913 | The `.test.js` / `.spec.js` files (or the `__tests__` folders) can be located at any depth under the `src` top level folder. 914 | 915 | We recommend to put the test files (or `__tests__` folders) next to the code they are testing so that relative imports appear shorter. For example, if `App.test.js` and `App.js` are in the same folder, the test just needs to `import App from './App'` instead of a long relative path. Colocation also helps find tests more quickly in larger projects. 916 | 917 | ### Command Line Interface 918 | 919 | When you run `npm test`, Jest will launch in the watch mode. Every time you save a file, it will re-run the tests, just like `npm start` recompiles the code. 920 | 921 | The watcher includes an interactive command-line interface with the ability to run all tests, or focus on a search pattern. It is designed this way so that you can keep it open and enjoy fast re-runs. You can learn the commands from the “Watch Usage” note that the watcher prints after every run: 922 | 923 | ![Jest watch mode](http://facebook.github.io/jest/img/blog/15-watch.gif) 924 | 925 | ### Version Control Integration 926 | 927 | By default, when you run `npm test`, Jest will only run the tests related to files changed since the last commit. This is an optimization designed to make your tests runs fast regardless of how many tests you have. However it assumes that you don’t often commit the code that doesn’t pass the tests. 928 | 929 | Jest will always explicitly mention that it only ran tests related to the files changed since the last commit. You can also press `a` in the watch mode to force Jest to run all tests. 930 | 931 | Jest will always run all tests on a [continuous integration](#continuous-integration) server or if the project is not inside a Git or Mercurial repository. 932 | 933 | ### Writing Tests 934 | 935 | To create tests, add `it()` (or `test()`) blocks with the name of the test and its code. You may optionally wrap them in `describe()` blocks for logical grouping but this is neither required nor recommended. 936 | 937 | Jest provides a built-in `expect()` global function for making assertions. A basic test could look like this: 938 | 939 | ```js 940 | import sum from './sum'; 941 | 942 | it('sums numbers', () => { 943 | expect(sum(1, 2)).toEqual(3); 944 | expect(sum(2, 2)).toEqual(4); 945 | }); 946 | ``` 947 | 948 | All `expect()` matchers supported by Jest are [extensively documented here](http://facebook.github.io/jest/docs/expect.html).
949 | You can also use [`jest.fn()` and `expect(fn).toBeCalled()`](http://facebook.github.io/jest/docs/expect.html#tohavebeencalled) to create “spies” or mock functions. 950 | 951 | ### Testing Components 952 | 953 | There is a broad spectrum of component testing techniques. They range from a “smoke test” verifying that a component renders without throwing, to shallow rendering and testing some of the output, to full rendering and testing component lifecycle and state changes. 954 | 955 | Different projects choose different testing tradeoffs based on how often components change, and how much logic they contain. If you haven’t decided on a testing strategy yet, we recommend that you start with creating simple smoke tests for your components: 956 | 957 | ```js 958 | import React from 'react'; 959 | import ReactDOM from 'react-dom'; 960 | import App from './App'; 961 | 962 | it('renders without crashing', () => { 963 | const div = document.createElement('div'); 964 | ReactDOM.render(, div); 965 | }); 966 | ``` 967 | 968 | This test mounts a component and makes sure that it didn’t throw during rendering. Tests like this provide a lot value with very little effort so they are great as a starting point, and this is the test you will find in `src/App.test.js`. 969 | 970 | When you encounter bugs caused by changing components, you will gain a deeper insight into which parts of them are worth testing in your application. This might be a good time to introduce more specific tests asserting specific expected output or behavior. 971 | 972 | If you’d like to test components in isolation from the child components they render, we recommend using [`shallow()` rendering API](http://airbnb.io/enzyme/docs/api/shallow.html) from [Enzyme](http://airbnb.io/enzyme/). You can write a smoke test with it too: 973 | 974 | ```sh 975 | npm install --save-dev enzyme react-addons-test-utils 976 | ``` 977 | 978 | ```js 979 | import React from 'react'; 980 | import { shallow } from 'enzyme'; 981 | import App from './App'; 982 | 983 | it('renders without crashing', () => { 984 | shallow(); 985 | }); 986 | ``` 987 | 988 | Unlike the previous smoke test using `ReactDOM.render()`, this test only renders `` and doesn’t go deeper. For example, even if `` itself renders a ` 418 | } 419 | } 420 | } 421 | 422 | goBack() { // puts the bottom left panel back into ready state for new images to be added, after an image is added 423 | var myImage = this.refs.myImageRef; 424 | myImage.src=''; 425 | this.setState({ 426 | newImageReady:0, 427 | newImageURL:'Paste Image URL Here' 428 | }); 429 | this.refreshUser(this.state.users[this.state.thisUser].address); 430 | } 431 | 432 | newImageButton() { // display SHA256 of the image to be added, and the button to click to add it to this user's account on-chain 433 | //console.log("newImageButton : " + this.state.newImageReady); 434 | var outerThis = this; 435 | if(outerThis.state.newImageReady===1){ 436 | return( 437 | 438 | Image SHA: { outerThis.state.newImageSHA }

439 |

440 | outerThis.goBack() }>Go Back 441 |
442 | ); 443 | } else if(outerThis.state.newImageReady) { // if newImageReady is not 0/1, it's being used for loading / error display message 444 | return {outerThis.state.newImageReady}; 445 | } else { // this is the default "ready to add new image" state, showing the myImages selector and the "paste image URL here" input box 446 | return 447 | Image SHA: { outerThis.state.newImageSHA } { outerThis.myUserCheckMark() }

448 | Your Images: { outerThis.drawImageSelect(1,this.state.thisUser) }

449 | Add Image: { this.clearStateIf('newImageURL','Paste Image URL Here',null) } } 458 | />

459 |
460 | } 461 | } 462 | 463 | myUserCheckMark(){ 464 | //console.log("myUserCheckMark called! : " + this.state.myImageVerified); 465 | if(!!this.state.mySelectedImage){ 466 | if(this.state.myImageVerified){ 467 | return { '\u2713' } 468 | } else { 469 | return x 470 | } 471 | } 472 | } 473 | 474 | newMyImageSelected(e){ 475 | //console.log("newMyImageSelected : name(" + e.target.name + "), value(" + e.target.value + ")"); 476 | this.checkImage(1,e.target.value); 477 | } 478 | 479 | selectedUserImageSelected(e){ 480 | console.log("selectedUserImageSelected : name(" + e.target.name + "), value(" + e.target.value + ")"); 481 | this.checkImage(0,e.target.value); 482 | } 483 | 484 | drawImageSelect(mine,thisUser) { 485 | var outerThis = this; 486 | if(thisUser && outerThis.state.users[thisUser]) { 487 | //console.log("drawImageSelect! user: " + thisUser); 488 | if(mine){ 489 | //console.log("drawing myUser image select: " + thisUser + ", myImages: " + JSON.stringify(outerThis.state.myImages)); 490 | return( 491 | 505 | ); 506 | } else { 507 | //console.log("drawing selectedUser image select: " + thisUser + ", myImages: " + JSON.stringify(outerThis.state.myImages)); 508 | return( 509 | 523 | ); 524 | } 525 | } 526 | } 527 | 528 | addImageToUser() { // handles the "add image to user" button functionality 529 | var outerThis = this; 530 | console.log("adding image to user now!"); 531 | console.log("imageURL : " + outerThis.state.newImageURL + ", sha: 0x"+ outerThis.state.newImageSHA); 532 | try { 533 | GeektContract.addImageToUser.estimateGas(outerThis.state.newImageURL,"0x"+outerThis.state.newImageSHA,{from:defaultAccount}, function(err, result){ 534 | if(err) { 535 | throw err; 536 | } else { 537 | console.log("addNewImage gas estimate : " + result); 538 | var myGasNum = result; 539 | GeektContract.addImageToUser.sendTransaction(outerThis.state.newImageURL,"0x"+outerThis.state.newImageSHA,{from:defaultAccount, gas: myGasNum}, function(err, result){ 540 | if(err) { 541 | throw err; 542 | } else { 543 | console.log("image added!") 544 | outerThis.goBack(); 545 | } 546 | }); 547 | } 548 | }); 549 | } catch (err) { 550 | console.log("addImageToUser threw err: " + err); 551 | } 552 | } 553 | 554 | signGuestbook() { // handles the "sign guestbook now" button functionality 555 | var outerThis = this; 556 | console.log("signing GuestBook now!"); 557 | console.log(outerThis.state.defaultHandle,outerThis.state.defaultCity,outerThis.state.defaultState,outerThis.state.defaultCountry); 558 | try { 559 | GeektContract.registerNewUser.estimateGas(outerThis.state.defaultHandle,outerThis.state.defaultCity,outerThis.state.defaultState,outerThis.state.defaultCountry,{from:defaultAccount}, function(err, result){ 560 | if(err) { 561 | throw err; 562 | } else { 563 | console.log("registerNewUser gas estimate : " + result); 564 | var myGasNum = result; 565 | GeektContract.registerNewUser.sendTransaction(outerThis.state.defaultHandle,outerThis.state.defaultCity,outerThis.state.defaultState,outerThis.state.defaultCountry,{from:defaultAccount, gas: myGasNum}, function(err, result){ 566 | if(err) { 567 | throw err; 568 | } else { 569 | console.log("GuestBook signed! TXID : " + result); 570 | outerThis.refreshUser(defaultAccount); 571 | } 572 | }); 573 | } 574 | }); 575 | } catch (err) { 576 | console.log("signing GuestBook threw err: " + err); 577 | } 578 | return null; 579 | } 580 | 581 | RegisterChange(e) { // updates input fields in response to user typing in them, gets SHA256 of new image if needed 582 | //console.log('registering change : ' + e.target.name + " - " + e.target.value); 583 | var outerThis = this; 584 | var newState = this.state; 585 | newState[e.target.name] = e.target.value; 586 | this.setState(newState); 587 | if(e.target.name === 'newImageURL'){ 588 | outerThis.fetchNewImage(); 589 | } 590 | } 591 | 592 | checkImage(mine,imageHash){ 593 | console.log("checking image, mine(" + mine + ")"); 594 | var outerThis = this; 595 | var thisURL = ''; 596 | if(mine){ 597 | thisURL = this.state.myImages[imageHash].url; 598 | this.refs.myImageRef.src = thisURL; 599 | } else { 600 | thisURL = this.state.selectedUserImages[imageHash].url; 601 | this.refs.selectedUserImageRef.src = thisURL; 602 | } 603 | console.log(" - image: " + imageHash + " url : " + thisURL); 604 | // fetch image via proxy, get sha hash, compare to on-chain image hash 605 | var proxyURL='https://fierce-temple-74228.herokuapp.com/'+thisURL; 606 | var request = new Request(proxyURL, { 607 | method: 'GET', 608 | mode: 'basic', 609 | redirect: 'follow', 610 | headers: new Headers({ 611 | 'Origin': 'localhost', 612 | 'x-requested-with':'GeektReactApp' 613 | }) 614 | }); 615 | try { 616 | fetch(request).then(function(resp) { 617 | if(resp.ok) { 618 | return resp.blob(); 619 | } 620 | //console.log("saw checkImage fetch response: " + JSON.stringify(resp)); 621 | //console.debug(resp) 622 | throw new Error("Couldn't fetch this image! "); 623 | }).then(function(respBlob) { 624 | reader.readAsBinaryString(respBlob); 625 | reader.onloadend = function(){ 626 | var dataURL = reader.result; 627 | var sha256 = cryptojs.SHA256(cryptojs.enc.Latin1.parse(dataURL)).toString(cryptojs.enc.Hex); 628 | //console.log("reader callback fired: " + dataURL); 629 | //console.log("saw sha256 of image data: 0x" + sha256 + ", comparing to chain sha: " + imageHash); 630 | if("0x" + sha256 === imageHash){ 631 | if(mine){ 632 | outerThis.setState({ 633 | newImageSHA: "0x" + sha256, 634 | myImageVerified: true, 635 | mySelectedImage: imageHash 636 | }); 637 | } else { 638 | outerThis.setState({ 639 | selectedUserImageSHA: "0x" + sha256, 640 | selectedUserImageVerified: true, 641 | selectedUserImage: imageHash 642 | }); 643 | } 644 | } else { 645 | if(mine){ 646 | outerThis.setState({ 647 | newImageSHA: "0x" + sha256, 648 | myImageVerified: false, 649 | mySelectedImage: imageHash 650 | }); 651 | } else { 652 | outerThis.setState({ 653 | selectedUserImageSHA: "0x" + sha256, 654 | selectedUserImageVerified: false, 655 | selectedUserImage: imageHash 656 | }); 657 | } 658 | } 659 | } 660 | }).catch(function(error) { 661 | console.log('fetch saw error: '); 662 | if(mine){ 663 | outerThis.setState({ 664 | newImageSHA: '', 665 | myImageVerified: false, 666 | mySelectedImage: imageHash 667 | }); 668 | } else { 669 | outerThis.setState({ 670 | selectedUserImageSHA: '', 671 | selectedUserImageVerified: false, 672 | selectedUserImage: imageHash 673 | }); 674 | } 675 | console.debug(error); 676 | }); 677 | } catch (err) { 678 | console.log("checkImage caught error : " + err); 679 | if(mine){ 680 | outerThis.setState({ 681 | newImageSHA: '', 682 | myImageVerified: false, 683 | mySelectedImage: imageHash 684 | }); 685 | } else { 686 | outerThis.setState({ 687 | selectedUserImageSHA: '', 688 | selectedUserImageVerified: false, 689 | selectedUserImage: imageHash 690 | }); 691 | } 692 | } 693 | } 694 | 695 | fetchNewImage() { // when URL is pasted into newImage box, simple error-check, display, and get SHA256 hash of the image also 696 | var outerThis = this; 697 | console.log("fetch new image : " + this.state.newImageURL); 698 | var lastFour = this.state.newImageURL.substr(this.state.newImageURL.length - 4); 699 | var isNewImage = /png|bmp|gif|jpg|jpeg|tif|tiff/.test(lastFour.toLowerCase()) 700 | // console.log("isImage test passed : " + isNewImage + ", lastFour : " + lastFour); 701 | //lastThree.includes('image'); 702 | var myImage = this.refs.myImageRef; 703 | var proxyURL='https://fierce-temple-74228.herokuapp.com/'+this.state.newImageURL; 704 | if(isNewImage){ 705 | outerThis.setState({ 706 | newImageReady:'Checking image...', 707 | newImageSHA:'', 708 | myImageVerified:false 709 | }); 710 | // myImage.src = "http://www.unm.edu/~reason/Tesseract.jpg"; // 3dc54764f06ec1f556fc27735a94a436bb28ed21b3ffcf8133c151b9ada68030 711 | var request = new Request(proxyURL, { 712 | method: 'GET', 713 | mode: 'basic', 714 | redirect: 'follow', 715 | headers: new Headers({ 716 | 'Origin': 'localhost', 717 | 'x-requested-with':'GeektReactApp' 718 | }) 719 | }); 720 | try { 721 | fetch(request).then(function(resp) { 722 | if(resp.ok) { 723 | return resp.blob(); 724 | } 725 | //console.debug(resp) 726 | throw new Error("Couldn't fetch this image! "); 727 | }).then(function(respBlob) { 728 | console.debug(respBlob); 729 | //reader.readAsDataURL(respBlob); 730 | var isBlobImage = respBlob.type.includes('image'); 731 | if(isBlobImage){ 732 | var objectURL = URL.createObjectURL(respBlob); 733 | myImage.src = objectURL; 734 | reader.readAsBinaryString(respBlob); 735 | outerThis.setState({ 736 | newImageReady:'Getting image SHA256 hash...' 737 | }); 738 | reader.onloadend = function(){ 739 | var dataURL = reader.result; 740 | var sha256 = cryptojs.SHA256(cryptojs.enc.Latin1.parse(dataURL)).toString(cryptojs.enc.Hex); 741 | //console.log("reader callback fired: " + dataURL); 742 | console.log("saw sha256 of image data: " + sha256); 743 | outerThis.setState({ 744 | newImageReady:1, 745 | newImageSHA:sha256 746 | }); 747 | }; 748 | } 749 | }).catch(function(error) { 750 | console.log('fetch saw error: '); 751 | console.debug(error); 752 | }); 753 | } catch (err) { 754 | console.log("fetchImage caught error : " + err); 755 | } 756 | } else { 757 | console.log("didn't test file SHA, no image format detected."); 758 | } 759 | } 760 | 761 | clearState(target, warn) { // clears input boxes from their default value upon user clicking on that input box 762 | console.log("clearState called! target " + target); 763 | this.setState({ 764 | [target]: '', 765 | [warn]: '' 766 | }); 767 | } 768 | 769 | clearStateIf(target, val, warn) { // nested clearState calls allow for custom error/warning message clearing also, if needed 770 | console.log("clearStateIf called! target(" + this.state[target] + "), val (" + val + ")"); 771 | if(this.state[target] === val){ 772 | this.clearState(target,warn); 773 | } 774 | } 775 | 776 | componentDidMount() { // gets called every time a redraw occurs on the main top-level react elect (so, all the time) 777 | var outerThis = this; 778 | if(!alreadyLoaded){ // we only want this to happen once upon page load, not every component reload... 779 | alreadyLoaded = true; 780 | loadWeb3(); 781 | setTimeout(function(){ 782 | // console.log("hello"); 783 | outerThis.getInfo(); 784 | }, 1000); 785 | } 786 | } 787 | 788 | render() { // renders the main page, updates automatically upon setState() calls which alter the state 789 | return ( 790 |
791 |
792 | 793 | 794 | 795 | 799 | 803 | 807 | 808 |
796 | EnLedger-Logo
797 | EnLedger.io 798 |
800 | Blockgeeks-Logo
801 |

Demo Ethereum GuestBook & Image Notary

802 |
804 | See the BlockGeeks Article

805 | See the Github Code Repository 806 |
809 |
810 | 811 | 812 | 813 | 817 | 819 | 820 | 821 | 824 | 833 | 834 | 835 |
814 | Users List
815 | { this.drawUserSelect() } 816 |
818 |
822 | { this.getSelected() }
823 |

825 |
Saw connection to network: { this.state.thisNetId }!

826 | Saw default account: { this.defaultEthAddressLink() }

827 |

{ this.getDefault('Handle') }


828 | { this.getDefault('City') } 829 | { this.getDefault('State') } 830 | { this.getDefault('Country') }
831 | { this.viewOrSignButton() } 832 |
836 |
837 | 838 | 839 | 840 | 845 | 861 | 862 |
841 | 842 | Thank you for visiting EnLedger.io and the Ethereum Guestbook Demo!

843 |
844 |
846 | 847 | To use this tool you'll need a connection to an Ethereum network, via:
848 | 849 | 1. start Ethereum server or testrpc server running at localhost:8545, then reload this page 850 |
851 | 2. Install Metamask plugin, connect to network of your choice (including Mainnet!), then reload this page 852 |
853 | notes: for localhost testrpc (testnet), you don't need Metamask running, see the README for metamask signing locally & ethereumjs-testrpc notes
854 | notes: sometimes you may need to reload once or twice for it to see your web3.eth.accounts[0] account 855 |

856 | Author: Ryan Molecke, sponsored by BlockGeeks.com!
857 | Issues, comments, suggestions? Please use this page to start an issue ticket, do not email Ryan for help directly :)
858 | Also check out Tectract's EthDeployer! 859 |
860 |
863 |
864 |

865 |
866 |
867 | ); 868 | } 869 | } 870 | 871 | export default App; 872 | -------------------------------------------------------------------------------- /GeektReactApp/src/App.test.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import App from './App'; 4 | 5 | it('renders without crashing', () => { 6 | const div = document.createElement('div'); 7 | ReactDOM.render(, div); 8 | }); 9 | -------------------------------------------------------------------------------- /GeektReactApp/src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | padding: 0; 4 | font-family: sans-serif; 5 | } 6 | -------------------------------------------------------------------------------- /GeektReactApp/src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import App from './App'; 4 | import './index.css'; 5 | 6 | ReactDOM.render( 7 | , 8 | document.getElementById('root') 9 | ); 10 | -------------------------------------------------------------------------------- /GeektReactApp/src/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /GeektSolidity/build/contracts/ConvertLib.json: -------------------------------------------------------------------------------- 1 | { 2 | "contract_name": "ConvertLib", 3 | "abi": [ 4 | { 5 | "constant": false, 6 | "inputs": [ 7 | { 8 | "name": "amount", 9 | "type": "uint256" 10 | }, 11 | { 12 | "name": "conversionRate", 13 | "type": "uint256" 14 | } 15 | ], 16 | "name": "convert", 17 | "outputs": [ 18 | { 19 | "name": "convertedAmount", 20 | "type": "uint256" 21 | } 22 | ], 23 | "payable": false, 24 | "type": "function" 25 | } 26 | ], 27 | "unlinked_binary": "0x6060604052346000575b6076806100176000396000f300606060405263ffffffff60e060020a60003504166396e4ee3d81146022575b6000565b602e6004356024356040565b60408051918252519081900360200190f35b8181025b929150505600a165627a7a72305820e1cabdad421a5162f05de796b753a95d2f9213dbdd9ccfa5f8dff24b90a0d0090029", 28 | "networks": {}, 29 | "schema_version": "0.0.5", 30 | "updated_at": 1493095546065 31 | } -------------------------------------------------------------------------------- /GeektSolidity/build/contracts/Geekt.json: -------------------------------------------------------------------------------- 1 | { 2 | "contract_name": "Geekt", 3 | "abi": [ 4 | { 5 | "constant": true, 6 | "inputs": [], 7 | "name": "getUsers", 8 | "outputs": [ 9 | { 10 | "name": "", 11 | "type": "address[]" 12 | } 13 | ], 14 | "payable": false, 15 | "type": "function" 16 | }, 17 | { 18 | "constant": false, 19 | "inputs": [ 20 | { 21 | "name": "handle", 22 | "type": "string" 23 | }, 24 | { 25 | "name": "city", 26 | "type": "bytes32" 27 | }, 28 | { 29 | "name": "state", 30 | "type": "bytes32" 31 | }, 32 | { 33 | "name": "country", 34 | "type": "bytes32" 35 | } 36 | ], 37 | "name": "registerNewUser", 38 | "outputs": [ 39 | { 40 | "name": "success", 41 | "type": "bool" 42 | } 43 | ], 44 | "payable": false, 45 | "type": "function" 46 | }, 47 | { 48 | "constant": true, 49 | "inputs": [ 50 | { 51 | "name": "SHA256notaryHash", 52 | "type": "bytes32" 53 | } 54 | ], 55 | "name": "getImage", 56 | "outputs": [ 57 | { 58 | "name": "", 59 | "type": "string" 60 | }, 61 | { 62 | "name": "", 63 | "type": "uint256" 64 | } 65 | ], 66 | "payable": false, 67 | "type": "function" 68 | }, 69 | { 70 | "constant": true, 71 | "inputs": [ 72 | { 73 | "name": "userAddress", 74 | "type": "address" 75 | } 76 | ], 77 | "name": "getUser", 78 | "outputs": [ 79 | { 80 | "name": "", 81 | "type": "string" 82 | }, 83 | { 84 | "name": "", 85 | "type": "bytes32" 86 | }, 87 | { 88 | "name": "", 89 | "type": "bytes32" 90 | }, 91 | { 92 | "name": "", 93 | "type": "bytes32" 94 | }, 95 | { 96 | "name": "", 97 | "type": "bytes32[]" 98 | } 99 | ], 100 | "payable": false, 101 | "type": "function" 102 | }, 103 | { 104 | "constant": true, 105 | "inputs": [], 106 | "name": "getAllImages", 107 | "outputs": [ 108 | { 109 | "name": "", 110 | "type": "bytes32[]" 111 | } 112 | ], 113 | "payable": false, 114 | "type": "function" 115 | }, 116 | { 117 | "constant": false, 118 | "inputs": [ 119 | { 120 | "name": "imageURL", 121 | "type": "string" 122 | }, 123 | { 124 | "name": "SHA256notaryHash", 125 | "type": "bytes32" 126 | } 127 | ], 128 | "name": "addImageToUser", 129 | "outputs": [ 130 | { 131 | "name": "success", 132 | "type": "bool" 133 | } 134 | ], 135 | "payable": false, 136 | "type": "function" 137 | }, 138 | { 139 | "constant": false, 140 | "inputs": [ 141 | { 142 | "name": "badUser", 143 | "type": "address" 144 | } 145 | ], 146 | "name": "removeUser", 147 | "outputs": [ 148 | { 149 | "name": "success", 150 | "type": "bool" 151 | } 152 | ], 153 | "payable": false, 154 | "type": "function" 155 | }, 156 | { 157 | "constant": false, 158 | "inputs": [ 159 | { 160 | "name": "badImage", 161 | "type": "bytes32" 162 | } 163 | ], 164 | "name": "removeImage", 165 | "outputs": [ 166 | { 167 | "name": "success", 168 | "type": "bool" 169 | } 170 | ], 171 | "payable": false, 172 | "type": "function" 173 | }, 174 | { 175 | "constant": true, 176 | "inputs": [ 177 | { 178 | "name": "userAddress", 179 | "type": "address" 180 | } 181 | ], 182 | "name": "getUserImages", 183 | "outputs": [ 184 | { 185 | "name": "", 186 | "type": "bytes32[]" 187 | } 188 | ], 189 | "payable": false, 190 | "type": "function" 191 | }, 192 | { 193 | "inputs": [], 194 | "payable": false, 195 | "type": "constructor" 196 | } 197 | ], 198 | "unlinked_binary": "0x606060405234610000575b60008054600160a060020a03191633600160a060020a03161790555b5b610d60806100366000396000f3006060604052361561007c5763ffffffff60e060020a600035041662ce8e3e8114610081578063124b1789146100e95780636ced1ae91461015d5780636f77926b146101f95780637b7284fc146102f95780637f2a6a5c1461036157806398575188146103ca5780639f6c9358146103f7578063eb6bbd781461041b575b610000565b346100005761008e61048f565b60408051602080825283518183015283519192839290830191858101910280838382156100d6575b8051825260208311156100d657601f1990920191602091820191016100b6565b5050509050019250505060405180910390f35b3461000057610149600480803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284375094965050843594602081013594506040013592506104fa915050565b604080519115158252519081900360200190f35b346100005761016d6004356106ba565b60405180806020018381526020018281038252848181518152602001915080519060200190808383600083146101be575b8051825260208311156101be57601f19909201916020918201910161019e565b505050905090810190601f1680156101ea5780820380516001836020036101000a031916815260200191505b50935050505060405180910390f35b3461000057610212600160a060020a0360043516610774565b6040805160208082018790529181018590526060810184905260a0808252875190820152865190918291608083019160c0840191908a01908083838215610274575b80518252602083111561027457601f199092019160209182019101610254565b505050905090810190601f1680156102a05780820380516001836020036101000a031916815260200191505b508381038252845181528451602091820191808701910280838382156102e1575b8051825260208311156102e157601f1990920191602091820191016102c1565b50505090500197505050505050505060405180910390f35b346100005761008e6108b2565b60408051602080825283518183015283519192839290830191858101910280838382156100d6575b8051825260208311156100d657601f1990920191602091820191016100b6565b5050509050019250505060405180910390f35b3461000057610149600480803590602001908201803590602001908080601f01602080910402602001604051908101604052809392919081815260200183838082843750949650509335935061091492505050565b604080519115158252519081900360200190f35b3461000057610149600160a060020a0360043516610b2d565b604080519115158252519081900360200190f35b3461000057610149600435610c1d565b604080519115158252519081900360200190f35b346100005761008e600160a060020a0360043516610cbb565b60408051602080825283518183015283519192839290830191858101910280838382156100d6575b8051825260208311156100d657601f1990920191602091820191016100b6565b5050509050019250505060405180910390f35b6040805160208181018352600082526004805484518184028101840190955280855292939290918301828280156104ef57602002820191906000526020600020905b8154600160a060020a031681526001909101906020018083116104d1575b505050505090505b90565b33600160a060020a038116600090815260036020526040812054909190600260018216156101000260001901909116041580156105375750855115155b156106ab57856003600083600160a060020a0316600160a060020a031681526020019081526020016000206000019080519060200190828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106105ae57805160ff19168380011785556105db565b828001600101855582156105db579182015b828111156105db5782518255916020019190600101906105c0565b5b506105fc9291505b808211156105f857600081556001016105e4565b5090565b5050600160a060020a03811660009081526003602081905260409091206001808201889055600282018790559101849055600480549182018082559091908281838015829011610671576000838152602090206106719181019083015b808211156105f857600081556001016105e4565b5090565b5b505050916000526020600020900160005b8154600160a060020a038086166101009390930a9283029202191617905550600191506106b0565b600091505b5b50949350505050565b6040805160208082018352600080835284815260018083528482208082015481548751600260001995831615610100029590950190911693909304601f8101869004860284018601909752868352949592949093909284918301828280156107635780601f1061073857610100808354040283529160200191610763565b820191906000526020600020905b81548152906001019060200180831161074657829003601f168201915b50505050509150915091505b915091565b6040805160208082018352600080835283518083018552818152600160a060020a038616825260038084528583206001808201546002808401549484015484548b519481161561010002600019011691909104601f8101899004890284018901909a52898352979895978897889794959294929391926004870192918791908301828280156108445780601f1061081957610100808354040283529160200191610844565b820191906000526020600020905b81548152906001019060200180831161082757829003601f168201915b505050505094508080548060200260200160405190810160405280929190818152602001828054801561089757602002820191906000526020600020905b81548152600190910190602001808311610882575b50505050509050945094509450945094505b91939590929450565b6040805160208181018352600082526002805484518184028101840190955280855292939290918301828280156104ef57602002820191906000526020600020905b815481526001909101906020018083116108f4575b505050505090505b90565b33600160a060020a0381166000908152600360205260408120549091906002600182161561010002600019019091160415610b0e57835115610b0e576000838152600160208190526040909120546002610100928216159290920260001901160415156109d557600280548060010182818154818355818115116109bd576000838152602090206109bd9181019083015b808211156105f857600081556001016105e4565b5090565b5b505050916000526020600020900160005b50849055505b600083815260016020818152604083208751815482865294839020919460026000199582161561010002959095011693909304601f90810183900482019392890190839010610a2f57805160ff1916838001178555610a5c565b82800160010185558215610a5c579182015b82811115610a5c578251825591602001919060010190610a41565b5b50610a7d9291505b808211156105f857600081556001016105e4565b5090565b505060008381526001602081815260408084204290840155600160a060020a0385168452600390915290912060040180549182018082559091908281838015829011610aee57600083815260209020610aee9181019083015b808211156105f857600081556001016105e4565b5090565b5b505050916000526020600020900160005b508490555060019150610b25565b60009150610b25565b60019150610b25565b600091505b5b5092915050565b6000805433600160a060020a03908116911614610b4957610000565b600160a060020a03821660009081526003602052604081208054828255909190829060026000196101006001841615020190911604601f819010610b8d5750610bbf565b601f016020900490600052602060002090810190610bbf91905b808211156105f857600081556001016105e4565b5090565b5b506001820160009055600282016000905560038201600090556004820180546000825590600052602060002090810190610c0e91905b808211156105f857600081556001016105e4565b5090565b5b505050600190505b5b919050565b6000805433600160a060020a03908116911614610c3957610000565b600082815260016020819052604082208054838255909291839160026101009282161592909202600019011604601f819010610c755750610ca7565b601f016020900490600052602060002090810190610ca791905b808211156105f857600081556001016105e4565b5090565b5b5050600060019182015590505b5b919050565b60408051602081810183526000808352600160a060020a03851681526003825283902060040180548451818402810184019095528085529293929091830182828015610d2757602002820191906000526020600020905b81548152600190910190602001808311610d12575b505050505090505b9190505600a165627a7a72305820471ee0a08d7071f99740507bfa1650dddd106f120ed066eaf6a89d958e847b5e0029", 199 | "networks": { 200 | "20": { 201 | "events": {}, 202 | "links": {}, 203 | "address": "0xe70ff0fa937a25d5dd4172318fa1593baba5a027", 204 | "updated_at": 1493718331726 205 | }, 206 | "1493098395215": { 207 | "events": {}, 208 | "links": {}, 209 | "address": "0xe70ff0fa937a25d5dd4172318fa1593baba5a027", 210 | "updated_at": 1493098473639 211 | }, 212 | "1493109596771": { 213 | "events": {}, 214 | "links": {}, 215 | "address": "0xe70ff0fa937a25d5dd4172318fa1593baba5a027", 216 | "updated_at": 1493109700370 217 | }, 218 | "1493114129475": { 219 | "events": {}, 220 | "links": {}, 221 | "address": "0xe70ff0fa937a25d5dd4172318fa1593baba5a027", 222 | "updated_at": 1493114143297 223 | } 224 | }, 225 | "schema_version": "0.0.5", 226 | "updated_at": 1493718331726 227 | } -------------------------------------------------------------------------------- /GeektSolidity/build/contracts/MetaCoin.json: -------------------------------------------------------------------------------- 1 | { 2 | "contract_name": "MetaCoin", 3 | "abi": [ 4 | { 5 | "constant": false, 6 | "inputs": [ 7 | { 8 | "name": "addr", 9 | "type": "address" 10 | } 11 | ], 12 | "name": "getBalanceInEth", 13 | "outputs": [ 14 | { 15 | "name": "", 16 | "type": "uint256" 17 | } 18 | ], 19 | "payable": false, 20 | "type": "function" 21 | }, 22 | { 23 | "constant": false, 24 | "inputs": [ 25 | { 26 | "name": "receiver", 27 | "type": "address" 28 | }, 29 | { 30 | "name": "amount", 31 | "type": "uint256" 32 | } 33 | ], 34 | "name": "sendCoin", 35 | "outputs": [ 36 | { 37 | "name": "sufficient", 38 | "type": "bool" 39 | } 40 | ], 41 | "payable": false, 42 | "type": "function" 43 | }, 44 | { 45 | "constant": false, 46 | "inputs": [ 47 | { 48 | "name": "addr", 49 | "type": "address" 50 | } 51 | ], 52 | "name": "getBalance", 53 | "outputs": [ 54 | { 55 | "name": "", 56 | "type": "uint256" 57 | } 58 | ], 59 | "payable": false, 60 | "type": "function" 61 | }, 62 | { 63 | "inputs": [], 64 | "payable": false, 65 | "type": "constructor" 66 | }, 67 | { 68 | "anonymous": false, 69 | "inputs": [ 70 | { 71 | "indexed": true, 72 | "name": "_from", 73 | "type": "address" 74 | }, 75 | { 76 | "indexed": true, 77 | "name": "_to", 78 | "type": "address" 79 | }, 80 | { 81 | "indexed": false, 82 | "name": "_value", 83 | "type": "uint256" 84 | } 85 | ], 86 | "name": "Transfer", 87 | "type": "event" 88 | } 89 | ], 90 | "unlinked_binary": "0x606060405234610000575b600160a060020a033216600090815260208190526040902061271090555b5b610223806100386000396000f300606060405263ffffffff60e060020a6000350416637bd703e8811461003a57806390b98a1114610065578063f8b2cb4f14610095575b610000565b3461000057610053600160a060020a03600435166100c0565b60408051918252519081900360200190f35b3461000057610081600160a060020a0360043516602435610140565b604080519115158252519081900360200190f35b3461000057610053600160a060020a03600435166101d8565b60408051918252519081900360200190f35b600073__ConvertLib____________________________6396e4ee3d6100e5846101d8565b60026000604051602001526040518363ffffffff1660e060020a028152600401808381526020018281526020019250505060206040518083038186803b156100005760325a03f415610000575050604051519150505b919050565b600160a060020a03331660009081526020819052604081205482901015610169575060006101d2565b600160a060020a0333811660008181526020818152604080832080548890039055938716808352918490208054870190558351868152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a35060015b92915050565b600160a060020a0381166000908152602081905260409020545b9190505600a165627a7a72305820c286531fc1fa7d1b8ed755fc6fbb113715be9bda2c6171399afd0646de2bbdfb0029", 91 | "networks": {}, 92 | "schema_version": "0.0.5", 93 | "updated_at": 1493095546066 94 | } -------------------------------------------------------------------------------- /GeektSolidity/build/contracts/Migrations.json: -------------------------------------------------------------------------------- 1 | { 2 | "contract_name": "Migrations", 3 | "abi": [ 4 | { 5 | "constant": false, 6 | "inputs": [ 7 | { 8 | "name": "new_address", 9 | "type": "address" 10 | } 11 | ], 12 | "name": "upgrade", 13 | "outputs": [], 14 | "payable": false, 15 | "type": "function" 16 | }, 17 | { 18 | "constant": true, 19 | "inputs": [], 20 | "name": "last_completed_migration", 21 | "outputs": [ 22 | { 23 | "name": "", 24 | "type": "uint256" 25 | } 26 | ], 27 | "payable": false, 28 | "type": "function" 29 | }, 30 | { 31 | "constant": true, 32 | "inputs": [], 33 | "name": "owner", 34 | "outputs": [ 35 | { 36 | "name": "", 37 | "type": "address" 38 | } 39 | ], 40 | "payable": false, 41 | "type": "function" 42 | }, 43 | { 44 | "constant": false, 45 | "inputs": [ 46 | { 47 | "name": "completed", 48 | "type": "uint256" 49 | } 50 | ], 51 | "name": "setCompleted", 52 | "outputs": [], 53 | "payable": false, 54 | "type": "function" 55 | }, 56 | { 57 | "inputs": [], 58 | "payable": false, 59 | "type": "constructor" 60 | } 61 | ], 62 | "unlinked_binary": "0x606060405234610000575b60008054600160a060020a03191633600160a060020a03161790555b5b610190806100366000396000f300606060405263ffffffff60e060020a6000350416630900f0108114610045578063445df0ac146100605780638da5cb5b1461007f578063fdacd576146100a8575b610000565b346100005761005e600160a060020a03600435166100ba565b005b346100005761006d61012d565b60408051918252519081900360200190f35b346100005761008c610133565b60408051600160a060020a039092168252519081900360200190f35b346100005761005e600435610142565b005b6000805433600160a060020a03908116911614156101275781905080600160a060020a031663fdacd5766001546040518263ffffffff1660e060020a02815260040180828152602001915050600060405180830381600087803b156100005760325a03f115610000575050505b5b5b5050565b60015481565b600054600160a060020a031681565b60005433600160a060020a039081169116141561015f5760018190555b5b5b505600a165627a7a7230582060af0db5ca8bbf833ded4b1cea729b39315cd60d05621d7cb1f5b5d62ab613650029", 63 | "networks": { 64 | "20": { 65 | "events": {}, 66 | "links": {}, 67 | "address": "0xd06a1935230c5bae8c7ecf75fbf4f17a04564ed8", 68 | "updated_at": 1493718331727 69 | }, 70 | "1493097046806": { 71 | "events": {}, 72 | "links": {}, 73 | "address": "0xeb5c61034a64df92184f20e69a61bc3ffae4e8e9", 74 | "updated_at": 1493097069419 75 | }, 76 | "1493098395215": { 77 | "events": {}, 78 | "links": {}, 79 | "address": "0xd06a1935230c5bae8c7ecf75fbf4f17a04564ed8", 80 | "updated_at": 1493098473640 81 | }, 82 | "1493109596771": { 83 | "events": {}, 84 | "links": {}, 85 | "address": "0xd06a1935230c5bae8c7ecf75fbf4f17a04564ed8", 86 | "updated_at": 1493109700371 87 | }, 88 | "1493114129475": { 89 | "events": {}, 90 | "links": {}, 91 | "address": "0xd06a1935230c5bae8c7ecf75fbf4f17a04564ed8", 92 | "updated_at": 1493114143298 93 | } 94 | }, 95 | "schema_version": "0.0.5", 96 | "updated_at": 1493718331727 97 | } -------------------------------------------------------------------------------- /GeektSolidity/contracts/ConvertLib.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.4; 2 | 3 | library ConvertLib{ 4 | function convert(uint amount,uint conversionRate) returns (uint convertedAmount) 5 | { 6 | return amount * conversionRate; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /GeektSolidity/contracts/Geekt.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.4; 2 | 3 | // Simple Solidity intro/demo contract for BlockGeeks Article 4 | contract Geekt { 5 | 6 | address GeektAdmin; 7 | 8 | mapping ( bytes32 => notarizedImage) notarizedImages; // this allows to look up notarizedImages by their SHA256notaryHash 9 | bytes32[] imagesByNotaryHash; // this is like a whitepages of all images, by SHA256notaryHash 10 | 11 | mapping ( address => User ) Users; // this allows to look up Users by their ethereum address 12 | address[] usersByAddress; // this is like a whitepages of all users, by ethereum address 13 | 14 | struct notarizedImage { 15 | string imageURL; 16 | uint timeStamp; 17 | } 18 | 19 | struct User { 20 | string handle; 21 | bytes32 city; 22 | bytes32 state; 23 | bytes32 country; 24 | bytes32[] myImages; 25 | } 26 | 27 | function Geekt() payable { // this is the CONSTRUCTOR (same name as contract) it gets called ONCE only when contract is first deployed 28 | GeektAdmin = msg.sender; // just set the admin, so they can remove bad users or images if needed, but nobody else can 29 | } 30 | 31 | modifier onlyAdmin() { 32 | if (msg.sender != GeektAdmin) 33 | throw; 34 | // Do not forget the "_;"! It will be replaced by the actual function body when the modifier is used. 35 | _; 36 | } 37 | 38 | function removeUser(address badUser) onlyAdmin returns (bool success) { 39 | delete Users[badUser]; 40 | return true; 41 | } 42 | 43 | function removeImage(bytes32 badImage) onlyAdmin returns (bool success) { 44 | delete notarizedImages[badImage]; 45 | return true; 46 | } 47 | 48 | function registerNewUser(string handle, bytes32 city, bytes32 state, bytes32 country) returns (bool success) { 49 | address thisNewAddress = msg.sender; 50 | // don't overwrite existing entries, and make sure handle isn't null 51 | if(bytes(Users[msg.sender].handle).length == 0 && bytes(handle).length != 0){ 52 | Users[thisNewAddress].handle = handle; 53 | Users[thisNewAddress].city = city; 54 | Users[thisNewAddress].state = state; 55 | Users[thisNewAddress].country = country; 56 | usersByAddress.push(thisNewAddress); // adds an entry for this user to the user 'whitepages' 57 | return true; 58 | } else { 59 | return false; // either handle was null, or a user with this handle already existed 60 | } 61 | } 62 | 63 | function addImageToUser(string imageURL, bytes32 SHA256notaryHash) returns (bool success) { 64 | address thisNewAddress = msg.sender; 65 | if(bytes(Users[thisNewAddress].handle).length != 0){ // make sure this user has created an account first 66 | if(bytes(imageURL).length != 0){ // ) { // couldn't get bytes32 null check to work, oh well! 67 | // prevent users from fighting over sha->image listings in the whitepages, but still allow them to add a personal ref to any sha 68 | if(bytes(notarizedImages[SHA256notaryHash].imageURL).length == 0) { 69 | imagesByNotaryHash.push(SHA256notaryHash); // adds entry for this image to our image whitepages 70 | } 71 | notarizedImages[SHA256notaryHash].imageURL = imageURL; 72 | notarizedImages[SHA256notaryHash].timeStamp = block.timestamp; // note that updating an image also updates the timestamp 73 | Users[thisNewAddress].myImages.push(SHA256notaryHash); // add the image hash to this users .myImages array 74 | return true; 75 | } else { 76 | return false; // either imageURL or SHA256notaryHash was null, couldn't store image 77 | } 78 | return true; 79 | } else { 80 | return false; // user didn't have an account yet, couldn't store image 81 | } 82 | } 83 | 84 | function getUsers() constant returns (address[]) { return usersByAddress; } 85 | 86 | function getUser(address userAddress) constant returns (string,bytes32,bytes32,bytes32,bytes32[]) { 87 | return (Users[userAddress].handle,Users[userAddress].city,Users[userAddress].state,Users[userAddress].country,Users[userAddress].myImages); 88 | } 89 | 90 | function getAllImages() constant returns (bytes32[]) { return imagesByNotaryHash; } 91 | 92 | function getUserImages(address userAddress) constant returns (bytes32[]) { return Users[userAddress].myImages; } 93 | 94 | function getImage(bytes32 SHA256notaryHash) constant returns (string,uint) { 95 | return (notarizedImages[SHA256notaryHash].imageURL,notarizedImages[SHA256notaryHash].timeStamp); 96 | } 97 | 98 | } 99 | -------------------------------------------------------------------------------- /GeektSolidity/contracts/MetaCoin.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.4; 2 | 3 | import "./ConvertLib.sol"; 4 | 5 | // This is just a simple example of a coin-like contract. 6 | // It is not standards compatible and cannot be expected to talk to other 7 | // coin/token contracts. If you want to create a standards-compliant 8 | // token, see: https://github.com/ConsenSys/Tokens. Cheers! 9 | 10 | contract MetaCoin { 11 | mapping (address => uint) balances; 12 | 13 | event Transfer(address indexed _from, address indexed _to, uint256 _value); 14 | 15 | function MetaCoin() { 16 | balances[tx.origin] = 10000; 17 | } 18 | 19 | function sendCoin(address receiver, uint amount) returns(bool sufficient) { 20 | if (balances[msg.sender] < amount) return false; 21 | balances[msg.sender] -= amount; 22 | balances[receiver] += amount; 23 | Transfer(msg.sender, receiver, amount); 24 | return true; 25 | } 26 | 27 | function getBalanceInEth(address addr) returns(uint){ 28 | return ConvertLib.convert(getBalance(addr),2); 29 | } 30 | 31 | function getBalance(address addr) returns(uint) { 32 | return balances[addr]; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /GeektSolidity/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.4; 2 | 3 | contract Migrations { 4 | address public owner; 5 | uint public last_completed_migration; 6 | 7 | modifier restricted() { 8 | if (msg.sender == owner) _; 9 | } 10 | 11 | function Migrations() { 12 | owner = msg.sender; 13 | } 14 | 15 | function setCompleted(uint completed) restricted { 16 | last_completed_migration = completed; 17 | } 18 | 19 | function upgrade(address new_address) restricted { 20 | Migrations upgraded = Migrations(new_address); 21 | upgraded.setCompleted(last_completed_migration); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /GeektSolidity/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | var Migrations = artifacts.require("./Migrations.sol"); 2 | 3 | module.exports = function(deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /GeektSolidity/migrations/2_deploy_contracts.js: -------------------------------------------------------------------------------- 1 | var Geekt = artifacts.require("Geekt.sol"); 2 | 3 | module.exports = function(deployer) { 4 | deployer.deploy(Geekt); 5 | }; 6 | -------------------------------------------------------------------------------- /GeektSolidity/test/TestMetacoin.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.2; 2 | 3 | import "truffle/Assert.sol"; 4 | import "truffle/DeployedAddresses.sol"; 5 | import "../contracts/MetaCoin.sol"; 6 | 7 | contract TestMetacoin { 8 | 9 | function testInitialBalanceUsingDeployedContract() { 10 | MetaCoin meta = MetaCoin(DeployedAddresses.MetaCoin()); 11 | 12 | uint expected = 10000; 13 | 14 | Assert.equal(meta.getBalance(tx.origin), expected, "Owner should have 10000 MetaCoin initially"); 15 | } 16 | 17 | function testInitialBalanceWithNewMetaCoin() { 18 | MetaCoin meta = new MetaCoin(); 19 | 20 | uint expected = 10000; 21 | 22 | Assert.equal(meta.getBalance(tx.origin), expected, "Owner should have 10000 MetaCoin initially"); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /GeektSolidity/test/metacoin.js: -------------------------------------------------------------------------------- 1 | var MetaCoin = artifacts.require("./MetaCoin.sol"); 2 | 3 | contract('MetaCoin', function(accounts) { 4 | it("should put 10000 MetaCoin in the first account", function() { 5 | return MetaCoin.deployed().then(function(instance) { 6 | return instance.getBalance.call(accounts[0]); 7 | }).then(function(balance) { 8 | assert.equal(balance.valueOf(), 10000, "10000 wasn't in the first account"); 9 | }); 10 | }); 11 | it("should call a function that depends on a linked library", function() { 12 | var meta; 13 | var metaCoinBalance; 14 | var metaCoinEthBalance; 15 | 16 | return MetaCoin.deployed().then(function(instance) { 17 | meta = instance; 18 | return meta.getBalance.call(accounts[0]); 19 | }).then(function(outCoinBalance) { 20 | metaCoinBalance = outCoinBalance.toNumber(); 21 | return meta.getBalanceInEth.call(accounts[0]); 22 | }).then(function(outCoinBalanceEth) { 23 | metaCoinEthBalance = outCoinBalanceEth.toNumber(); 24 | }).then(function() { 25 | assert.equal(metaCoinEthBalance, 2 * metaCoinBalance, "Library function returned unexpected function, linkage may be broken"); 26 | }); 27 | }); 28 | it("should send coin correctly", function() { 29 | var meta; 30 | 31 | // Get initial balances of first and second account. 32 | var account_one = accounts[0]; 33 | var account_two = accounts[1]; 34 | 35 | var account_one_starting_balance; 36 | var account_two_starting_balance; 37 | var account_one_ending_balance; 38 | var account_two_ending_balance; 39 | 40 | var amount = 10; 41 | 42 | return MetaCoin.deployed().then(function(instance) { 43 | meta = instance; 44 | return meta.getBalance.call(account_one); 45 | }).then(function(balance) { 46 | account_one_starting_balance = balance.toNumber(); 47 | return meta.getBalance.call(account_two); 48 | }).then(function(balance) { 49 | account_two_starting_balance = balance.toNumber(); 50 | return meta.sendCoin(account_two, amount, {from: account_one}); 51 | }).then(function() { 52 | return meta.getBalance.call(account_one); 53 | }).then(function(balance) { 54 | account_one_ending_balance = balance.toNumber(); 55 | return meta.getBalance.call(account_two); 56 | }).then(function(balance) { 57 | account_two_ending_balance = balance.toNumber(); 58 | 59 | assert.equal(account_one_ending_balance, account_one_starting_balance - amount, "Amount wasn't correctly taken from the sender"); 60 | assert.equal(account_two_ending_balance, account_two_starting_balance + amount, "Amount wasn't correctly sent to the receiver"); 61 | }); 62 | }); 63 | }); 64 | -------------------------------------------------------------------------------- /GeektSolidity/truffle.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | networks: { 3 | development: { 4 | host: "localhost", 5 | port: 8545, 6 | network_id: "*" // set to low number so deployment works? 7 | } 8 | } 9 | }; 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Mozilla Public License Version 2.0 2 | ================================== 3 | 4 | 1. Definitions 5 | -------------- 6 | 7 | 1.1. "Contributor" 8 | means each individual or legal entity that creates, contributes to 9 | the creation of, or owns Covered Software. 10 | 11 | 1.2. "Contributor Version" 12 | means the combination of the Contributions of others (if any) used 13 | by a Contributor and that particular Contributor's Contribution. 14 | 15 | 1.3. "Contribution" 16 | means Covered Software of a particular Contributor. 17 | 18 | 1.4. "Covered Software" 19 | means Source Code Form to which the initial Contributor has attached 20 | the notice in Exhibit A, the Executable Form of such Source Code 21 | Form, and Modifications of such Source Code Form, in each case 22 | including portions thereof. 23 | 24 | 1.5. "Incompatible With Secondary Licenses" 25 | means 26 | 27 | (a) that the initial Contributor has attached the notice described 28 | in Exhibit B to the Covered Software; or 29 | 30 | (b) that the Covered Software was made available under the terms of 31 | version 1.1 or earlier of the License, but not also under the 32 | terms of a Secondary License. 33 | 34 | 1.6. "Executable Form" 35 | means any form of the work other than Source Code Form. 36 | 37 | 1.7. "Larger Work" 38 | means a work that combines Covered Software with other material, in 39 | a separate file or files, that is not Covered Software. 40 | 41 | 1.8. "License" 42 | means this document. 43 | 44 | 1.9. "Licensable" 45 | means having the right to grant, to the maximum extent possible, 46 | whether at the time of the initial grant or subsequently, any and 47 | all of the rights conveyed by this License. 48 | 49 | 1.10. "Modifications" 50 | means any of the following: 51 | 52 | (a) any file in Source Code Form that results from an addition to, 53 | deletion from, or modification of the contents of Covered 54 | Software; or 55 | 56 | (b) any new file in Source Code Form that contains any Covered 57 | Software. 58 | 59 | 1.11. "Patent Claims" of a Contributor 60 | means any patent claim(s), including without limitation, method, 61 | process, and apparatus claims, in any patent Licensable by such 62 | Contributor that would be infringed, but for the grant of the 63 | License, by the making, using, selling, offering for sale, having 64 | made, import, or transfer of either its Contributions or its 65 | Contributor Version. 66 | 67 | 1.12. "Secondary License" 68 | means either the GNU General Public License, Version 2.0, the GNU 69 | Lesser General Public License, Version 2.1, the GNU Affero General 70 | Public License, Version 3.0, or any later versions of those 71 | licenses. 72 | 73 | 1.13. "Source Code Form" 74 | means the form of the work preferred for making modifications. 75 | 76 | 1.14. "You" (or "Your") 77 | means an individual or a legal entity exercising rights under this 78 | License. For legal entities, "You" includes any entity that 79 | controls, is controlled by, or is under common control with You. For 80 | purposes of this definition, "control" means (a) the power, direct 81 | or indirect, to cause the direction or management of such entity, 82 | whether by contract or otherwise, or (b) ownership of more than 83 | fifty percent (50%) of the outstanding shares or beneficial 84 | ownership of such entity. 85 | 86 | 2. License Grants and Conditions 87 | -------------------------------- 88 | 89 | 2.1. Grants 90 | 91 | Each Contributor hereby grants You a world-wide, royalty-free, 92 | non-exclusive license: 93 | 94 | (a) under intellectual property rights (other than patent or trademark) 95 | Licensable by such Contributor to use, reproduce, make available, 96 | modify, display, perform, distribute, and otherwise exploit its 97 | Contributions, either on an unmodified basis, with Modifications, or 98 | as part of a Larger Work; and 99 | 100 | (b) under Patent Claims of such Contributor to make, use, sell, offer 101 | for sale, have made, import, and otherwise transfer either its 102 | Contributions or its Contributor Version. 103 | 104 | 2.2. Effective Date 105 | 106 | The licenses granted in Section 2.1 with respect to any Contribution 107 | become effective for each Contribution on the date the Contributor first 108 | distributes such Contribution. 109 | 110 | 2.3. Limitations on Grant Scope 111 | 112 | The licenses granted in this Section 2 are the only rights granted under 113 | this License. No additional rights or licenses will be implied from the 114 | distribution or licensing of Covered Software under this License. 115 | Notwithstanding Section 2.1(b) above, no patent license is granted by a 116 | Contributor: 117 | 118 | (a) for any code that a Contributor has removed from Covered Software; 119 | or 120 | 121 | (b) for infringements caused by: (i) Your and any other third party's 122 | modifications of Covered Software, or (ii) the combination of its 123 | Contributions with other software (except as part of its Contributor 124 | Version); or 125 | 126 | (c) under Patent Claims infringed by Covered Software in the absence of 127 | its Contributions. 128 | 129 | This License does not grant any rights in the trademarks, service marks, 130 | or logos of any Contributor (except as may be necessary to comply with 131 | the notice requirements in Section 3.4). 132 | 133 | 2.4. Subsequent Licenses 134 | 135 | No Contributor makes additional grants as a result of Your choice to 136 | distribute the Covered Software under a subsequent version of this 137 | License (see Section 10.2) or under the terms of a Secondary License (if 138 | permitted under the terms of Section 3.3). 139 | 140 | 2.5. Representation 141 | 142 | Each Contributor represents that the Contributor believes its 143 | Contributions are its original creation(s) or it has sufficient rights 144 | to grant the rights to its Contributions conveyed by this License. 145 | 146 | 2.6. Fair Use 147 | 148 | This License is not intended to limit any rights You have under 149 | applicable copyright doctrines of fair use, fair dealing, or other 150 | equivalents. 151 | 152 | 2.7. Conditions 153 | 154 | Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted 155 | in Section 2.1. 156 | 157 | 3. Responsibilities 158 | ------------------- 159 | 160 | 3.1. Distribution of Source Form 161 | 162 | All distribution of Covered Software in Source Code Form, including any 163 | Modifications that You create or to which You contribute, must be under 164 | the terms of this License. You must inform recipients that the Source 165 | Code Form of the Covered Software is governed by the terms of this 166 | License, and how they can obtain a copy of this License. You may not 167 | attempt to alter or restrict the recipients' rights in the Source Code 168 | Form. 169 | 170 | 3.2. Distribution of Executable Form 171 | 172 | If You distribute Covered Software in Executable Form then: 173 | 174 | (a) such Covered Software must also be made available in Source Code 175 | Form, as described in Section 3.1, and You must inform recipients of 176 | the Executable Form how they can obtain a copy of such Source Code 177 | Form by reasonable means in a timely manner, at a charge no more 178 | than the cost of distribution to the recipient; and 179 | 180 | (b) You may distribute such Executable Form under the terms of this 181 | License, or sublicense it under different terms, provided that the 182 | license for the Executable Form does not attempt to limit or alter 183 | the recipients' rights in the Source Code Form under this License. 184 | 185 | 3.3. Distribution of a Larger Work 186 | 187 | You may create and distribute a Larger Work under terms of Your choice, 188 | provided that You also comply with the requirements of this License for 189 | the Covered Software. If the Larger Work is a combination of Covered 190 | Software with a work governed by one or more Secondary Licenses, and the 191 | Covered Software is not Incompatible With Secondary Licenses, this 192 | License permits You to additionally distribute such Covered Software 193 | under the terms of such Secondary License(s), so that the recipient of 194 | the Larger Work may, at their option, further distribute the Covered 195 | Software under the terms of either this License or such Secondary 196 | License(s). 197 | 198 | 3.4. Notices 199 | 200 | You may not remove or alter the substance of any license notices 201 | (including copyright notices, patent notices, disclaimers of warranty, 202 | or limitations of liability) contained within the Source Code Form of 203 | the Covered Software, except that You may alter any license notices to 204 | the extent required to remedy known factual inaccuracies. 205 | 206 | 3.5. Application of Additional Terms 207 | 208 | You may choose to offer, and to charge a fee for, warranty, support, 209 | indemnity or liability obligations to one or more recipients of Covered 210 | Software. However, You may do so only on Your own behalf, and not on 211 | behalf of any Contributor. You must make it absolutely clear that any 212 | such warranty, support, indemnity, or liability obligation is offered by 213 | You alone, and You hereby agree to indemnify every Contributor for any 214 | liability incurred by such Contributor as a result of warranty, support, 215 | indemnity or liability terms You offer. You may include additional 216 | disclaimers of warranty and limitations of liability specific to any 217 | jurisdiction. 218 | 219 | 4. Inability to Comply Due to Statute or Regulation 220 | --------------------------------------------------- 221 | 222 | If it is impossible for You to comply with any of the terms of this 223 | License with respect to some or all of the Covered Software due to 224 | statute, judicial order, or regulation then You must: (a) comply with 225 | the terms of this License to the maximum extent possible; and (b) 226 | describe the limitations and the code they affect. Such description must 227 | be placed in a text file included with all distributions of the Covered 228 | Software under this License. Except to the extent prohibited by statute 229 | or regulation, such description must be sufficiently detailed for a 230 | recipient of ordinary skill to be able to understand it. 231 | 232 | 5. Termination 233 | -------------- 234 | 235 | 5.1. The rights granted under this License will terminate automatically 236 | if You fail to comply with any of its terms. However, if You become 237 | compliant, then the rights granted under this License from a particular 238 | Contributor are reinstated (a) provisionally, unless and until such 239 | Contributor explicitly and finally terminates Your grants, and (b) on an 240 | ongoing basis, if such Contributor fails to notify You of the 241 | non-compliance by some reasonable means prior to 60 days after You have 242 | come back into compliance. Moreover, Your grants from a particular 243 | Contributor are reinstated on an ongoing basis if such Contributor 244 | notifies You of the non-compliance by some reasonable means, this is the 245 | first time You have received notice of non-compliance with this License 246 | from such Contributor, and You become compliant prior to 30 days after 247 | Your receipt of the notice. 248 | 249 | 5.2. If You initiate litigation against any entity by asserting a patent 250 | infringement claim (excluding declaratory judgment actions, 251 | counter-claims, and cross-claims) alleging that a Contributor Version 252 | directly or indirectly infringes any patent, then the rights granted to 253 | You by any and all Contributors for the Covered Software under Section 254 | 2.1 of this License shall terminate. 255 | 256 | 5.3. In the event of termination under Sections 5.1 or 5.2 above, all 257 | end user license agreements (excluding distributors and resellers) which 258 | have been validly granted by You or Your distributors under this License 259 | prior to termination shall survive termination. 260 | 261 | ************************************************************************ 262 | * * 263 | * 6. Disclaimer of Warranty * 264 | * ------------------------- * 265 | * * 266 | * Covered Software is provided under this License on an "as is" * 267 | * basis, without warranty of any kind, either expressed, implied, or * 268 | * statutory, including, without limitation, warranties that the * 269 | * Covered Software is free of defects, merchantable, fit for a * 270 | * particular purpose or non-infringing. The entire risk as to the * 271 | * quality and performance of the Covered Software is with You. * 272 | * Should any Covered Software prove defective in any respect, You * 273 | * (not any Contributor) assume the cost of any necessary servicing, * 274 | * repair, or correction. This disclaimer of warranty constitutes an * 275 | * essential part of this License. No use of any Covered Software is * 276 | * authorized under this License except under this disclaimer. * 277 | * * 278 | ************************************************************************ 279 | 280 | ************************************************************************ 281 | * * 282 | * 7. Limitation of Liability * 283 | * -------------------------- * 284 | * * 285 | * Under no circumstances and under no legal theory, whether tort * 286 | * (including negligence), contract, or otherwise, shall any * 287 | * Contributor, or anyone who distributes Covered Software as * 288 | * permitted above, be liable to You for any direct, indirect, * 289 | * special, incidental, or consequential damages of any character * 290 | * including, without limitation, damages for lost profits, loss of * 291 | * goodwill, work stoppage, computer failure or malfunction, or any * 292 | * and all other commercial damages or losses, even if such party * 293 | * shall have been informed of the possibility of such damages. This * 294 | * limitation of liability shall not apply to liability for death or * 295 | * personal injury resulting from such party's negligence to the * 296 | * extent applicable law prohibits such limitation. Some * 297 | * jurisdictions do not allow the exclusion or limitation of * 298 | * incidental or consequential damages, so this exclusion and * 299 | * limitation may not apply to You. * 300 | * * 301 | ************************************************************************ 302 | 303 | 8. Litigation 304 | ------------- 305 | 306 | Any litigation relating to this License may be brought only in the 307 | courts of a jurisdiction where the defendant maintains its principal 308 | place of business and such litigation shall be governed by laws of that 309 | jurisdiction, without reference to its conflict-of-law provisions. 310 | Nothing in this Section shall prevent a party's ability to bring 311 | cross-claims or counter-claims. 312 | 313 | 9. Miscellaneous 314 | ---------------- 315 | 316 | This License represents the complete agreement concerning the subject 317 | matter hereof. If any provision of this License is held to be 318 | unenforceable, such provision shall be reformed only to the extent 319 | necessary to make it enforceable. Any law or regulation which provides 320 | that the language of a contract shall be construed against the drafter 321 | shall not be used to construe this License against a Contributor. 322 | 323 | 10. Versions of the License 324 | --------------------------- 325 | 326 | 10.1. New Versions 327 | 328 | Mozilla Foundation is the license steward. Except as provided in Section 329 | 10.3, no one other than the license steward has the right to modify or 330 | publish new versions of this License. Each version will be given a 331 | distinguishing version number. 332 | 333 | 10.2. Effect of New Versions 334 | 335 | You may distribute the Covered Software under the terms of the version 336 | of the License under which You originally received the Covered Software, 337 | or under the terms of any subsequent version published by the license 338 | steward. 339 | 340 | 10.3. Modified Versions 341 | 342 | If you create software not governed by this License, and you want to 343 | create a new license for such software, you may create and use a 344 | modified version of this License if you rename the license and remove 345 | any references to the name of the license steward (except to note that 346 | such modified license differs from this License). 347 | 348 | 10.4. Distributing Source Code Form that is Incompatible With Secondary 349 | Licenses 350 | 351 | If You choose to distribute Source Code Form that is Incompatible With 352 | Secondary Licenses under the terms of this version of the License, the 353 | notice described in Exhibit B of this License must be attached. 354 | 355 | Exhibit A - Source Code Form License Notice 356 | ------------------------------------------- 357 | 358 | This Source Code Form is subject to the terms of the Mozilla Public 359 | License, v. 2.0. If a copy of the MPL was not distributed with this 360 | file, You can obtain one at http://mozilla.org/MPL/2.0/. 361 | 362 | If it is not possible or desirable to put the notice in a particular 363 | file, then You may include the notice in a location (such as a LICENSE 364 | file in a relevant directory) where a recipient would be likely to look 365 | for such a notice. 366 | 367 | You may add additional accurate notices of copyright ownership. 368 | 369 | Exhibit B - "Incompatible With Secondary Licenses" Notice 370 | --------------------------------------------------------- 371 | 372 | This Source Code Form is "Incompatible With Secondary Licenses", as 373 | defined by the Mozilla Public License, v. 2.0. 374 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ethereum-demo-tools 2 | 3 | ###dependencies 4 | 5 | (install nodejs and npm, latest versions if you can) 6 | 7 | npm i -g ethereumjs-testrpc 8 | 9 | npm i -g ethereumjs-util # see note below 10 | 11 | npm i -g truffle 12 | 13 | Useful tool info and examples for learning to write Ethereum smart-contracts, to accompany my BlockGeeks article 14 | 15 | truffle commands: 16 | 17 | truffle init 18 | 19 | truffle compile 20 | 21 | truffle migrate 22 | 23 | truffle console 24 | 25 | ### testrpc startup with pre-set seed phrase and pre-defined networkID 26 | 27 | COMMAND FROM DEMO ARTICLE: testrpc -m "sample dog come year spray crawl learn general detect silver jelly pilot" --network-id 20 28 | 29 | networkID needs to be below decimal(108) for tx signature to work properly (tx.v must be one byte only) 30 | 31 | note: ethereumjs-testrpc depends on OUTDATED ethereumjs-util, which has a signing bug which prevents Metamask from signing properly LOCALLY, 32 | 33 | but it works ok on mainnet. In order to fix this, you should: 34 | 35 | npm i -g ethereumjs-util@latest # separately from ethereumjs-testrpc 36 | 37 | now: you need to find where ethereumjs-testrpc and ethereumjs-util actually got installed, then go to the 38 | 39 | cd path-to/ethereumjs-util/node_modules 40 | 41 | mv ethereumjs-util ethereumjs-util_old 42 | 43 | ln -s path-to/ethereumjs-util . 44 | 45 | this symlink will trick ethereumjs-testrpc into using the latest version of ethereumjs-util, and solve the "signing bug" for local deployment 46 | 47 | 48 | ###examples of interacting with Geekt contract via truffle console: 49 | 50 | Geekt = Geekt.deployed() 51 | 52 | Geekt.then(function(instance){return instance.registerNewUser("Tectract","Denver","CO","USA");}) 53 | 54 | Geekt.then(function(instance){return instance.addImageToUser('https://avatars1.githubusercontent.com/u/3859005?v=3&u=f4863d518451ebe42c16c776930e913335eb837b&s=400','0x6c3e007e281f6948b37c511a11e43c8026d2a16a8a45fed4e83379b66b0ab927');}) 55 | 56 | Geekt.then(function(instance){return instance.addImageToUser('https://avatars1.githubusercontent.com/u/3859005?v=3&u=f4863d518451ebe42c16c776930e913335eb837b&s=400','');}) 57 | 58 | Geekt.then(function(instance){return instance.getUser('0x0ac21f1a6fe22241ccd3af85477e5358ac5847c2');}) 59 | 60 | Geekt.then(function(instance){return JSON.stringify(instance.abi);}) 61 | 62 | Geekt.then(function(instance){return instance.getUsers();}) 63 | 64 | Geekt.then(function(instance){return instance.getImages();}) 65 | 66 | Geekt.then(function(instance){return instance.getImage('0x6c3e007e281f6948b37c511a11e43c8026d2a16a8a45fed4e83379b66b0ab927');}) 67 | 68 | Geekt.then(function(instance){return instance.removeImage('0x6c3e007e281f6948b37c511a11e43c8026d2a16a8a45fed4e83379b66b0ab927');}) 69 | 70 | Geekt.then(function(instance){return instance.removeUser('0x0ac21f1a6fe22241ccd3af85477e5358ac5847c2');}) 71 | 72 | 73 | ###app creation 74 | 75 | this app was created with: create-react-app (see: https://github.com/facebookincubator/create-react-app) 76 | 77 | this app uses a cors-anywhere proxy (deployed at heroku with a domain whitelist and rate-limit), to grab image data for sha256 hashing 78 | 79 | see https://github.com/Rob--W/cors-anywhere for details on deploying a cors-anywhere proxy 80 | 81 | ### deployment info 82 | 83 | to install the app locally 84 | 85 | git clone https://www.github.com/tectract/ethereum-demo-tools/ 86 | 87 | cd ethereum-demo-tools/GeekReactApp 88 | 89 | npm i 90 | 91 | npm start 92 | 93 | (or) npm run build 94 | 95 | if testing against a localhost and local deployment of the contract, you'll have to update the contract address in App.js! 96 | 97 | otherwise just use metamask plugin and connect to mainnet to test the app, even if running locally :) 98 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ethereum-demo-tools", 3 | "description": "Useful tool info and examples for learning to write Ethereum smart-contracts, to accompany my BlockGeeks article", 4 | "dependencies": { 5 | "truffle": "^3.2.1" 6 | }, 7 | "repository": { 8 | "type": "git", 9 | "url": "git+https://github.com/Tectract/ethereum-demo-tools.git" 10 | }, 11 | "author": "Ryan Molecke" 12 | } 13 | --------------------------------------------------------------------------------