├── .gitattributes ├── .gitignore ├── .openzeppelin ├── dev-1574364836258.json ├── dev-1574611452236.json ├── project.json └── rinkeby.json ├── LICENSE ├── README.md ├── client ├── .eslintrc.json ├── .gitignore ├── .prettierrc.js ├── README.md ├── config-overrides.js ├── config │ └── webpack.js ├── netlify.toml ├── package-lock.json ├── package.json ├── public │ ├── favicon-32x32.png │ ├── index.html │ ├── manifest.json │ └── pic_bg.png └── src │ ├── App.js │ ├── App.module.scss │ ├── App.test.js │ ├── components │ ├── FileForm │ │ ├── FileForm.module.scss │ │ └── index.js │ ├── Footer │ │ ├── footer.module.scss │ │ ├── github.svg │ │ ├── index.js │ │ ├── logo-red.png │ │ ├── mail.svg │ │ ├── pencil.svg │ │ ├── twitter.svg │ │ └── zeppelin_logo.svg │ ├── Hash │ │ ├── Hash.module.scss │ │ └── index.js │ ├── Header │ │ ├── header.module.scss │ │ └── index.js │ └── Web3Info │ │ ├── Web3Info.module.scss │ │ └── index.js │ ├── images │ └── logo.svg │ ├── index.js │ ├── layout │ ├── index.scss │ └── variables.scss │ ├── serviceWorker.js │ └── utils │ ├── getTransactionReceipt.js │ ├── ipfs.js │ └── sleep.js ├── contracts └── Hash.sol ├── img ├── diagram.jpg └── ipfs-dapp-architecture.drawio ├── migrations └── .gitkeep ├── package-lock.json ├── package.json ├── solhint.json ├── test └── hash.js └── truffle-config.js /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | *.pid.lock 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # Bower dependency directory (https://bower.io/) 27 | bower_components 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (https://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | node_modules/ 37 | jspm_packages/ 38 | 39 | # TypeScript v1 declaration files 40 | typings/ 41 | 42 | # Optional npm cache directory 43 | .npm 44 | 45 | # Optional eslint cache 46 | .eslintcache 47 | 48 | # Optional REPL history 49 | .node_repl_history 50 | 51 | # Output of 'npm pack' 52 | *.tgz 53 | 54 | # Yarn Integrity file 55 | .yarn-integrity 56 | 57 | # dotenv environment variables file 58 | .env 59 | .env.* 60 | 61 | # next.js build output 62 | .next 63 | 64 | # zos sessions 65 | zos.dev-* 66 | 67 | # contracts build 68 | build 69 | 70 | .zos.session 71 | 72 | 73 | .openzeppelin/.session 74 | 75 | .vscode -------------------------------------------------------------------------------- /.openzeppelin/dev-1574364836258.json: -------------------------------------------------------------------------------- 1 | { 2 | "contracts": { 3 | "Hash": { 4 | "address": "0xe78A0F7E598Cc8b0Bb87894B0F60dD2a88d6a8Ab", 5 | "constructorCode": "6080604052611027806100136000396000f3fe", 6 | "bodyBytecodeHash": "c21fe772daf13468749efb9e922ebfff26fabcfad0f5d2bad71acc2e75b7d5c6", 7 | "localBytecodeHash": "eeae4f2e686619c5e4704d2005dbdb92beb980861da3035cff9f03cccf29ce2d", 8 | "deployedBytecodeHash": "eeae4f2e686619c5e4704d2005dbdb92beb980861da3035cff9f03cccf29ce2d", 9 | "types": { 10 | "t_bool": { 11 | "id": "t_bool", 12 | "kind": "elementary", 13 | "label": "bool" 14 | }, 15 | "t_uint256": { 16 | "id": "t_uint256", 17 | "kind": "elementary", 18 | "label": "uint256" 19 | }, 20 | "t_array:50": { 21 | "id": "t_array:50", 22 | "valueType": "t_uint256", 23 | "length": "50", 24 | "kind": "array", 25 | "label": "uint256[50]" 26 | }, 27 | "t_address": { 28 | "id": "t_address", 29 | "kind": "elementary", 30 | "label": "address" 31 | }, 32 | "t_string": { 33 | "id": "t_string", 34 | "kind": "elementary", 35 | "label": "string" 36 | } 37 | }, 38 | "storage": [ 39 | { 40 | "contract": "Initializable", 41 | "path": "@openzeppelin/upgrades/contracts/Initializable.sol", 42 | "label": "initialized", 43 | "astId": 808, 44 | "type": "t_bool", 45 | "src": "757:24:5" 46 | }, 47 | { 48 | "contract": "Initializable", 49 | "path": "@openzeppelin/upgrades/contracts/Initializable.sol", 50 | "label": "initializing", 51 | "astId": 810, 52 | "type": "t_bool", 53 | "src": "876:25:5" 54 | }, 55 | { 56 | "contract": "Initializable", 57 | "path": "@openzeppelin/upgrades/contracts/Initializable.sol", 58 | "label": "______gap", 59 | "astId": 866, 60 | "type": "t_array:50", 61 | "src": "1951:29:5" 62 | }, 63 | { 64 | "contract": "GSNRecipient", 65 | "path": "@openzeppelin/contracts-ethereum-package/contracts/GSN/GSNRecipient.sol", 66 | "label": "_relayHub", 67 | "astId": 180, 68 | "type": "t_address", 69 | "src": "1133:25:2" 70 | }, 71 | { 72 | "contract": "Hash", 73 | "path": "contracts/Hash.sol", 74 | "label": "ipfsHash", 75 | "astId": 9, 76 | "type": "t_string", 77 | "src": "218:22:0" 78 | } 79 | ], 80 | "warnings": { 81 | "hasConstructor": false, 82 | "hasSelfDestruct": false, 83 | "hasDelegateCall": false, 84 | "hasInitialValuesInDeclarations": false, 85 | "uninitializedBaseContracts": [] 86 | } 87 | } 88 | }, 89 | "solidityLibs": {}, 90 | "proxies": { 91 | "ipfs-upload-dapp/Hash": [ 92 | { 93 | "address": "0xCfEB869F69431e42cdB54A4F4f105C19C080A601", 94 | "version": "1.0.2", 95 | "implementation": "0xe78A0F7E598Cc8b0Bb87894B0F60dD2a88d6a8Ab", 96 | "admin": "0x5b1869D9A4C187F2EAa108f3062412ecf0526b24", 97 | "kind": "Upgradeable" 98 | }, 99 | { 100 | "address": "0x254dffcd3277C0b1660F6d42EFbB754edaBAbC2B", 101 | "version": "1.0.2", 102 | "implementation": "0xe78A0F7E598Cc8b0Bb87894B0F60dD2a88d6a8Ab", 103 | "admin": "0x5b1869D9A4C187F2EAa108f3062412ecf0526b24", 104 | "kind": "Upgradeable" 105 | } 106 | ] 107 | }, 108 | "manifestVersion": "2.2", 109 | "version": "1.0.2", 110 | "proxyAdmin": { 111 | "address": "0x5b1869D9A4C187F2EAa108f3062412ecf0526b24" 112 | } 113 | } -------------------------------------------------------------------------------- /.openzeppelin/dev-1574611452236.json: -------------------------------------------------------------------------------- 1 | { 2 | "contracts": { 3 | "Hash": { 4 | "address": "0xe78A0F7E598Cc8b0Bb87894B0F60dD2a88d6a8Ab", 5 | "constructorCode": "6080604052611027806100136000396000f3fe", 6 | "bodyBytecodeHash": "c21fe772daf13468749efb9e922ebfff26fabcfad0f5d2bad71acc2e75b7d5c6", 7 | "localBytecodeHash": "eeae4f2e686619c5e4704d2005dbdb92beb980861da3035cff9f03cccf29ce2d", 8 | "deployedBytecodeHash": "eeae4f2e686619c5e4704d2005dbdb92beb980861da3035cff9f03cccf29ce2d", 9 | "types": { 10 | "t_bool": { 11 | "id": "t_bool", 12 | "kind": "elementary", 13 | "label": "bool" 14 | }, 15 | "t_uint256": { 16 | "id": "t_uint256", 17 | "kind": "elementary", 18 | "label": "uint256" 19 | }, 20 | "t_array:50": { 21 | "id": "t_array:50", 22 | "valueType": "t_uint256", 23 | "length": "50", 24 | "kind": "array", 25 | "label": "uint256[50]" 26 | }, 27 | "t_address": { 28 | "id": "t_address", 29 | "kind": "elementary", 30 | "label": "address" 31 | }, 32 | "t_string": { 33 | "id": "t_string", 34 | "kind": "elementary", 35 | "label": "string" 36 | } 37 | }, 38 | "storage": [ 39 | { 40 | "contract": "Initializable", 41 | "path": "@openzeppelin/upgrades/contracts/Initializable.sol", 42 | "label": "initialized", 43 | "astId": 808, 44 | "type": "t_bool", 45 | "src": "757:24:5" 46 | }, 47 | { 48 | "contract": "Initializable", 49 | "path": "@openzeppelin/upgrades/contracts/Initializable.sol", 50 | "label": "initializing", 51 | "astId": 810, 52 | "type": "t_bool", 53 | "src": "876:25:5" 54 | }, 55 | { 56 | "contract": "Initializable", 57 | "path": "@openzeppelin/upgrades/contracts/Initializable.sol", 58 | "label": "______gap", 59 | "astId": 866, 60 | "type": "t_array:50", 61 | "src": "1951:29:5" 62 | }, 63 | { 64 | "contract": "GSNRecipient", 65 | "path": "@openzeppelin/contracts-ethereum-package/contracts/GSN/GSNRecipient.sol", 66 | "label": "_relayHub", 67 | "astId": 180, 68 | "type": "t_address", 69 | "src": "1133:25:2" 70 | }, 71 | { 72 | "contract": "Hash", 73 | "path": "contracts/Hash.sol", 74 | "label": "ipfsHash", 75 | "astId": 9, 76 | "type": "t_string", 77 | "src": "218:22:0" 78 | } 79 | ], 80 | "warnings": { 81 | "hasConstructor": false, 82 | "hasSelfDestruct": false, 83 | "hasDelegateCall": false, 84 | "hasInitialValuesInDeclarations": false, 85 | "uninitializedBaseContracts": [] 86 | } 87 | } 88 | }, 89 | "solidityLibs": {}, 90 | "proxies": { 91 | "ipfs-upload-dapp/Hash": [ 92 | { 93 | "address": "0xCfEB869F69431e42cdB54A4F4f105C19C080A601", 94 | "version": "1.0.2", 95 | "implementation": "0xe78A0F7E598Cc8b0Bb87894B0F60dD2a88d6a8Ab", 96 | "admin": "0x5b1869D9A4C187F2EAa108f3062412ecf0526b24", 97 | "kind": "Upgradeable" 98 | } 99 | ] 100 | }, 101 | "manifestVersion": "2.2", 102 | "version": "1.0.2", 103 | "proxyAdmin": { 104 | "address": "0x5b1869D9A4C187F2EAa108f3062412ecf0526b24" 105 | } 106 | } -------------------------------------------------------------------------------- /.openzeppelin/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "manifestVersion": "2.2", 3 | "contracts": { 4 | "Hash": "Hash" 5 | }, 6 | "dependencies": {}, 7 | "name": "ipfs-upload-dapp", 8 | "version": "1.0.2", 9 | "compiler": { 10 | "manager": "truffle", 11 | "compilerSettings": { 12 | "optimizer": {} 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /.openzeppelin/rinkeby.json: -------------------------------------------------------------------------------- 1 | { 2 | "contracts": { 3 | "Hash": { 4 | "address": "0xAb01E7C17002f04CFF23f29f335bf7eE56097140", 5 | "constructorCode": "6080604052611027806100136000396000f3fe", 6 | "bodyBytecodeHash": "c21fe772daf13468749efb9e922ebfff26fabcfad0f5d2bad71acc2e75b7d5c6", 7 | "localBytecodeHash": "eeae4f2e686619c5e4704d2005dbdb92beb980861da3035cff9f03cccf29ce2d", 8 | "deployedBytecodeHash": "eeae4f2e686619c5e4704d2005dbdb92beb980861da3035cff9f03cccf29ce2d", 9 | "types": { 10 | "t_bool": { 11 | "id": "t_bool", 12 | "kind": "elementary", 13 | "label": "bool" 14 | }, 15 | "t_uint256": { 16 | "id": "t_uint256", 17 | "kind": "elementary", 18 | "label": "uint256" 19 | }, 20 | "t_array:50": { 21 | "id": "t_array:50", 22 | "valueType": "t_uint256", 23 | "length": "50", 24 | "kind": "array", 25 | "label": "uint256[50]" 26 | }, 27 | "t_address": { 28 | "id": "t_address", 29 | "kind": "elementary", 30 | "label": "address" 31 | }, 32 | "t_string": { 33 | "id": "t_string", 34 | "kind": "elementary", 35 | "label": "string" 36 | } 37 | }, 38 | "storage": [ 39 | { 40 | "contract": "Initializable", 41 | "path": "@openzeppelin/upgrades/contracts/Initializable.sol", 42 | "label": "initialized", 43 | "astId": 808, 44 | "type": "t_bool", 45 | "src": "757:24:5" 46 | }, 47 | { 48 | "contract": "Initializable", 49 | "path": "@openzeppelin/upgrades/contracts/Initializable.sol", 50 | "label": "initializing", 51 | "astId": 810, 52 | "type": "t_bool", 53 | "src": "876:25:5" 54 | }, 55 | { 56 | "contract": "Initializable", 57 | "path": "@openzeppelin/upgrades/contracts/Initializable.sol", 58 | "label": "______gap", 59 | "astId": 866, 60 | "type": "t_array:50", 61 | "src": "1951:29:5" 62 | }, 63 | { 64 | "contract": "GSNRecipient", 65 | "path": "@openzeppelin/contracts-ethereum-package/contracts/GSN/GSNRecipient.sol", 66 | "label": "_relayHub", 67 | "astId": 180, 68 | "type": "t_address", 69 | "src": "1133:25:2" 70 | }, 71 | { 72 | "contract": "Hash", 73 | "path": "contracts/Hash.sol", 74 | "label": "ipfsHash", 75 | "astId": 9, 76 | "type": "t_string", 77 | "src": "218:22:0" 78 | } 79 | ], 80 | "warnings": { 81 | "hasConstructor": false, 82 | "hasSelfDestruct": false, 83 | "hasDelegateCall": false, 84 | "hasInitialValuesInDeclarations": false, 85 | "uninitializedBaseContracts": [] 86 | } 87 | } 88 | }, 89 | "solidityLibs": {}, 90 | "proxies": { 91 | "ipfs-upload-dapp/Hash": [ 92 | { 93 | "address": "0xA1F9A5D9b347cCe621598ef228592808c2de59C8", 94 | "version": "1.0.2", 95 | "implementation": "0xAb01E7C17002f04CFF23f29f335bf7eE56097140", 96 | "admin": "0x9E901FC6A6CcC4077829D545Ff438f1d896a98Cc", 97 | "kind": "Upgradeable" 98 | } 99 | ] 100 | }, 101 | "manifestVersion": "2.2", 102 | "version": "1.0.2", 103 | "proxyAdmin": { 104 | "address": "0x9E901FC6A6CcC4077829D545Ff438f1d896a98Cc" 105 | } 106 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Zeppelin Solutions 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # IPFS file upload (D)app 2 | Uploads file to IPFS and stores corresponding hash on Ethereum without requiring user to spend gas. 3 | 4 | ## Architecture 5 | ![Diagram](./img/diagram.jpg) 6 | ## Getting started 7 | 8 | 9 | ### Development 10 | 1. Start local blockchain network: `ganache-cli --deterministic` 11 | 2. Create contract instance: `oz create` 12 | 3. Don't forget to initialize GSNRecipient contract: `oz send-tx`, `initalize()` 13 | 4. Run front ent locally: `npm run start` 14 | 5. Access at `http://localhost:3000/` 15 | 16 | ## Resources 17 | Based on this [tutorial](https://www.freecodecamp.org/news/hands-on-get-started-with-infura-and-ipfs-on-ethereum-b63635142af0/) 18 | with the following improvements/changes: 19 | - Add tests 20 | - **Use [Gas Station Network](https://gsn.openzeppelin.com/) to turn dapp into app** 21 | - Use Rimble UI for front end styling 22 | 23 | ### Tech stack 24 | - [Openzeppelin GSN Starter Kit](https://docs.openzeppelin.com/starter-kits/2.3/gsnkit) 25 | - [React](https://reactjs.org/) 26 | - [Rimble UI](https://rimble.consensys.design/) 27 | - [Infura](https://infura.io/): Ethereum|IPFS API & Gateway 28 | - [web3.js](https://github.com/ethereum/web3.js/): Ethereum JavaScript API 29 | - [Ganache](https://github.com/trufflesuite/ganache): Personal blockchain for Ethereum development 30 | -------------------------------------------------------------------------------- /client/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["react-app"], 3 | "plugins": ["prettier", "react-hooks"], 4 | "rules": { 5 | "prettier/prettier": "error", 6 | "react-hooks/rules-of-hooks": "error", 7 | "react-hooks/exhaustive-deps": "warn" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /client/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.* 17 | 18 | npm-debug.log* 19 | yarn-debug.log* 20 | yarn-error.log* 21 | -------------------------------------------------------------------------------- /client/.prettierrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | semi: true, 3 | trailingComma: 'all', 4 | singleQuote: true, 5 | printWidth: 120, 6 | tabWidth: 2, 7 | }; 8 | -------------------------------------------------------------------------------- /client/README.md: -------------------------------------------------------------------------------- 1 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 2 | 3 | ## Available Scripts 4 | 5 | In the project directory, you can run: 6 | 7 | ### `npm start` 8 | 9 | Runs the app in the development mode.
10 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 11 | 12 | The page will reload if you make edits.
13 | You will also see any lint errors in the console. 14 | 15 | ### `npm test` 16 | 17 | Launches the test runner in the interactive watch mode.
18 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 19 | 20 | ### `npm run build` 21 | 22 | Builds the app for production to the `build` folder.
23 | It correctly bundles React in production mode and optimizes the build for the best performance. 24 | 25 | The build is minified and the filenames include the hashes.
26 | Your app is ready to be deployed! 27 | 28 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 29 | 30 | ### `npm run eject` 31 | 32 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 33 | 34 | 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. 35 | 36 | 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. 37 | 38 | 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. 39 | 40 | ## Learn More 41 | 42 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 43 | 44 | To learn React, check out the [React documentation](https://reactjs.org/). 45 | 46 | ### Code Splitting 47 | 48 | This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting 49 | 50 | ### Analyzing the Bundle Size 51 | 52 | This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size 53 | 54 | ### Making a Progressive Web App 55 | 56 | This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app 57 | 58 | ### Advanced Configuration 59 | 60 | This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration 61 | 62 | ### Deployment 63 | 64 | This section has moved here: https://facebook.github.io/create-react-app/docs/deployment 65 | 66 | ### `npm run build` fails to minify 67 | 68 | This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify 69 | -------------------------------------------------------------------------------- /client/config-overrides.js: -------------------------------------------------------------------------------- 1 | /* config-overrides.js */ 2 | const { solidityLoader } = require('./config/webpack'); 3 | 4 | module.exports = function override(config, env) { 5 | //do stuff with the webpack config... 6 | 7 | // allow importing from outside of app/src folder, ModuleScopePlugin prevents this. 8 | const scope = config.resolve.plugins.findIndex(o => o.constructor.name === 'ModuleScopePlugin'); 9 | if (scope > -1) { 10 | config.resolve.plugins.splice(scope, 1); 11 | } 12 | 13 | // add solidity loader support 14 | // have to insert before last loader, because CRA user 'file-loader' as default one 15 | config.module.rules.splice(config.module.rules - 2, 0, solidityLoader); 16 | 17 | return config; 18 | }; 19 | -------------------------------------------------------------------------------- /client/config/webpack.js: -------------------------------------------------------------------------------- 1 | const solidityLoaderOptions = { 2 | network: 'development', 3 | // you can stop loader from automatic compile/push/updgrade 4 | // action by setting disabled flag to true, but it will still 5 | // serve .json files from file system 6 | disabled: true, 7 | }; 8 | 9 | module.exports = { 10 | solidityLoader: { 11 | test: /\.sol$/, 12 | use: [ 13 | { loader: 'json-loader' }, 14 | { 15 | loader: '@openzeppelin/solidity-loader', 16 | options: solidityLoaderOptions, 17 | }, 18 | ], 19 | }, 20 | solidityLoaderOptions, 21 | }; 22 | -------------------------------------------------------------------------------- /client/netlify.toml: -------------------------------------------------------------------------------- 1 | # The following redirect is intended for use with most SPAs that handle 2 | # routing internally. 3 | [[redirects]] 4 | from = "/*" 5 | to = "/index.html" 6 | status = 200 7 | -------------------------------------------------------------------------------- /client/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "client", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@openzeppelin/gsn-provider": "^0.1.6", 7 | "@openzeppelin/network": "^0.2.9", 8 | "@openzeppelin/solidity-loader": "^1.4.6", 9 | "classnames": "^2.2.6", 10 | "ipfs-http-client": "^40.0.0", 11 | "json-loader": "^0.5.7", 12 | "node-sass": "^4.12.0", 13 | "prop-types": "^15.7.2", 14 | "react": "^16.8.6", 15 | "react-app-rewired": "^2.1.0", 16 | "react-dom": "^16.8.6", 17 | "react-scripts": "^3.1.1", 18 | "rimble-ui": "^0.11.0", 19 | "styled-components": "^4.4.1", 20 | "web3": "^1.2.1" 21 | }, 22 | "scripts": { 23 | "start": "react-app-rewired start", 24 | "build": "react-app-rewired build", 25 | "test": "react-app-rewired test", 26 | "eject": "react-scripts eject", 27 | "lint": "prettier 'src/**/*.js' --write && eslint 'src/**/*.js' --fix", 28 | "pre-push": "", 29 | "pre-commit": "lint-staged" 30 | }, 31 | "lint-staged": { 32 | "*.js": [ 33 | "prettier --write", 34 | "eslint --fix", 35 | "git add" 36 | ], 37 | "*.scss": [ 38 | "prettier --write", 39 | "git add" 40 | ] 41 | }, 42 | "browserslist": [ 43 | ">0.2%", 44 | "not dead", 45 | "not ie <= 11", 46 | "not op_mini all" 47 | ], 48 | "devDependencies": { 49 | "eslint": "^6.2.2", 50 | "eslint-config-prettier": "^6.0.0", 51 | "eslint-plugin-import": "^2.18.2", 52 | "eslint-plugin-prettier": "^3.1.0", 53 | "eslint-plugin-react-hooks": "^2.0.1", 54 | "lint-staged": "^9.2.5", 55 | "prettier": "^1.18.2", 56 | "pretty-quick": "^1.11.1" 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /client/public/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fawaz404dev/ipfs-upload-dapp/592fa8920b249652386d6ef6deb8c7907663488d/client/public/favicon-32x32.png -------------------------------------------------------------------------------- /client/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 13 | 14 | 23 | Starter Kit Tutorial 24 | 25 | 26 | 27 |
28 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /client/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | } 10 | ], 11 | "start_url": ".", 12 | "display": "standalone", 13 | "theme_color": "#000000", 14 | "background_color": "#ffffff" 15 | } 16 | -------------------------------------------------------------------------------- /client/public/pic_bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fawaz404dev/ipfs-upload-dapp/592fa8920b249652386d6ef6deb8c7907663488d/client/public/pic_bg.png -------------------------------------------------------------------------------- /client/src/App.js: -------------------------------------------------------------------------------- 1 | import React, { useState } from 'react'; 2 | 3 | // eslint-disable-next-line no-unused-vars 4 | import { useWeb3Network, useEphemeralKey, useWeb3Injected } from '@openzeppelin/network/react'; 5 | 6 | import Header from './components/Header/index.js'; 7 | import Footer from './components/Footer/index.js'; 8 | import Web3Info from './components/Web3Info/index.js'; 9 | import Hash from './components/Hash/index.js'; 10 | 11 | import styles from './App.module.scss'; 12 | 13 | // eslint-disable-next-line no-unused-vars 14 | const infuraToken = process.env.REACT_APP_INFURA_TOKEN || '95202223388e49f48b423ea50a70e336'; 15 | 16 | function App() { 17 | // get ephemeralKey 18 | // eslint-disable-next-line no-unused-vars 19 | const signKey = useEphemeralKey(); 20 | 21 | // get GSN web3 22 | // const context = useWeb3Network(`wss://rinkeby.infura.io/ws/v3/${infuraToken}`, { 23 | // pollInterval: 15 * 1000, 24 | // gsn: { 25 | // signKey, 26 | // }, 27 | // }); 28 | 29 | const context = useWeb3Network('http://127.0.0.1:8545', { 30 | gsn: { 31 | dev: true, 32 | signKey, 33 | }, 34 | }); 35 | 36 | // load Hash json artifact 37 | let hashJSON; 38 | try { 39 | // see https://github.com/OpenZeppelin/solidity-loader 40 | hashJSON = require('../../contracts/Hash.sol'); 41 | } catch (e) { 42 | console.log(e); 43 | } 44 | 45 | // load Hash instance 46 | const [hashInstance, setHashInstance] = useState(undefined); 47 | let deployedNetwork; 48 | if (!hashInstance && context && hashJSON && hashJSON.networks && context.networkId) { 49 | deployedNetwork = hashJSON.networks[context.networkId.toString()]; 50 | if (deployedNetwork) { 51 | setHashInstance(new context.lib.eth.Contract(hashJSON.abi, deployedNetwork.address)); 52 | } 53 | } 54 | 55 | function renderNoWeb3() { 56 | return ( 57 |
58 |

Web3 Provider Not Found

59 |

Please, install and run Ganache.

60 |
61 | ); 62 | } 63 | 64 | return ( 65 |
66 |
67 |
68 | {!context.lib && renderNoWeb3()} 69 |
70 |

BUIDL with GSN Kit!

71 |
72 | 73 | 74 |
75 |
76 |
77 |
78 |
79 | ); 80 | } 81 | 82 | export default App; 83 | -------------------------------------------------------------------------------- /client/src/App.module.scss: -------------------------------------------------------------------------------- 1 | @import './layout/variables.scss'; 2 | 3 | .App { 4 | text-align: center; 5 | display: flex; 6 | flex-flow: column nowrap; 7 | justify-content: flex-start; 8 | align-items: center; 9 | } 10 | 11 | code { 12 | background: #fefefe; 13 | box-shadow: 0 0px 2px 0px #ccc; 14 | padding: 8px 16px; 15 | font-size: 14px; 16 | width: 100%; 17 | font-family: source-code-pro, Menlo, Monaco, Consolas, Courier New, monospace; 18 | } 19 | 20 | .wrapper { 21 | min-height: 80vh; 22 | width: 100%; 23 | display: flex; 24 | flex-flow: column nowrap; 25 | align-items: center; 26 | } 27 | 28 | .setup, 29 | .contracts { 30 | width: 100%; 31 | padding: 40px 0; 32 | display: flex; 33 | flex-flow: column nowrap; 34 | align-items: center; 35 | 36 | .notice { 37 | margin: 15px 0; 38 | 39 | p { 40 | padding: 10px; 41 | background: #ededed; 42 | box-shadow: 0 1px 1px 2px #ccc; 43 | border: 1px solid #ddd; 44 | color: #444; 45 | } 46 | } 47 | 48 | .widgets { 49 | display: flex; 50 | max-width: 800px; 51 | width: 100%; 52 | flex-flow: row wrap; 53 | justify-content: space-between; 54 | align-items: flex-start; 55 | margin: 20px 0; 56 | } 57 | } 58 | 59 | .loader { 60 | width: 100%; 61 | display: flex; 62 | flex-flow: column nowrap; 63 | align-items: center; 64 | justify-content: center; 65 | min-height: 80vh; 66 | padding: 40px 0; 67 | h3 { 68 | margin-top: 30px; 69 | } 70 | } 71 | 72 | @keyframes App-logo-spin { 73 | from { 74 | transform: rotate(0deg); 75 | } 76 | to { 77 | transform: rotate(360deg); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /client/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 | ReactDOM.unmountComponentAtNode(div); 9 | }); 10 | -------------------------------------------------------------------------------- /client/src/components/FileForm/FileForm.module.scss: -------------------------------------------------------------------------------- 1 | .form { 2 | width: 345px; 3 | } 4 | -------------------------------------------------------------------------------- /client/src/components/FileForm/index.js: -------------------------------------------------------------------------------- 1 | import { Form, Button } from 'rimble-ui'; 2 | import React from 'react'; 3 | 4 | import ipfs from '../../utils/ipfs'; 5 | import styles from './FileForm.module.scss'; 6 | 7 | class FileForm extends React.Component { 8 | constructor(props) { 9 | super(props); 10 | this.state = { validated: false, buffer: '', ipfsHash: '', txHash: '' }; 11 | this.handleSubmit = this.handleSubmit.bind(this); 12 | this.handleValidation = this.handleValidation.bind(this); 13 | } 14 | 15 | async componentDidMount() { 16 | const ipfsHash = await this.props.instance.methods.ipfsHash().call(); 17 | this.setState({ ipfsHash }); 18 | } 19 | 20 | //Take file input from user 21 | captureFile = event => { 22 | event.stopPropagation(); 23 | event.preventDefault(); 24 | const file = event.target.files[0]; 25 | let reader = new window.FileReader(); 26 | reader.readAsArrayBuffer(file); 27 | reader.onloadend = () => this.convertToBuffer(reader); 28 | }; 29 | 30 | //Convert the file to buffer to store on IPFS 31 | convertToBuffer = async reader => { 32 | //file is converted to a buffer for upload to IPFS 33 | const buffer = await Buffer.from(reader.result); 34 | //set this buffer-using es6 syntax 35 | this.setState({ buffer }); 36 | }; 37 | 38 | async handleSubmit(e) { 39 | e.preventDefault(); 40 | this.setState({ validated: true }); 41 | try { 42 | //save document to IPFS,return its hash, and set hash to state 43 | const results = await ipfs.add(this.state.buffer); 44 | this.setState({ ipfsHash: results[0].hash }); 45 | } catch (error) { 46 | this.setState({ errorMessage: error.message }); 47 | } 48 | // call Ethereum contract method "sendHash" and .send IPFS hash to ethereum contract 49 | //set transaction hash to state 50 | const tx = await this.props.instance.methods.setHash(this.state.ipfsHash).send({ from: this.props.accounts[0] }); 51 | this.setState({ txHash: tx.transactionHash }); 52 | } 53 | 54 | handleValidation(e) { 55 | e.target.parentNode.classList.add('was-validated'); 56 | this.captureFile(e); 57 | } 58 | 59 | render() { 60 | return ( 61 |
62 | 63 | 64 | 65 | Submission will upload file to IPFS and store the corresponding hash on Ethereum. 66 | 69 | File's hash stored in current contract state:  70 | 71 | {this.state.ipfsHash} 72 | 73 | {this.state.txHash ?

Transaction: {this.state.txHash}

: <>} 74 |
75 | ); 76 | } 77 | } 78 | 79 | export default FileForm; 80 | -------------------------------------------------------------------------------- /client/src/components/Footer/footer.module.scss: -------------------------------------------------------------------------------- 1 | @import '../../layout/variables.scss'; 2 | .footer { 3 | width: 100%; 4 | display: flex; 5 | flex-flow: row wrap; 6 | justify-content: space-between; 7 | align-items: flex-start; 8 | background: $white; 9 | border-top: 1px solid #d8d8d8; 10 | padding: 25px 100px; 11 | 12 | .brand { 13 | display: flex; 14 | flex-flow: column nowrap; 15 | color: $primary; 16 | .created { 17 | width: 100%; 18 | display: flex; 19 | flex-flow: row nowrap; 20 | justify-content: flex-start; 21 | align-items: center; 22 | width: 400px; 23 | color: $primary; 24 | 25 | img { 26 | width: 33px; 27 | margin-right: 14px; 28 | } 29 | 30 | a { 31 | color: $white; 32 | margin-top: 4px; 33 | } 34 | 35 | span { 36 | color: $white; 37 | margin-left: 60px; 38 | line-height: 30px; 39 | 40 | a { 41 | color: $purple-aux; 42 | } 43 | } 44 | } 45 | 46 | .copyright { 47 | font-size: 14px; 48 | margin-top: 10px; 49 | text-align: left; 50 | color: rgba(0, 0, 0, 0.6); 51 | } 52 | } 53 | 54 | .links { 55 | display: flex; 56 | flex-flow: row wrap; 57 | align-items: center; 58 | justify-content: flex-start; 59 | a { 60 | margin: 0 10px; 61 | } 62 | img { 63 | width: 21px; 64 | } 65 | } 66 | } 67 | 68 | @media only screen and (max-width: $screen-sm-max) { 69 | .footer { 70 | padding: 80px 40px; 71 | 72 | .links { 73 | margin-top: 20px; 74 | width: 100%; 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /client/src/components/Footer/github.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ic_github 5 | Created with Sketch. 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /client/src/components/Footer/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import styles from './footer.module.scss'; 3 | // import logo from './logo-red.png' 4 | import mail from './mail.svg'; 5 | import twitter from './twitter.svg'; 6 | import github from './github.svg'; 7 | import zeppelin from './zeppelin_logo.svg'; 8 | 9 | const Footer = () => ( 10 | 31 | ); 32 | 33 | export default Footer; 34 | -------------------------------------------------------------------------------- /client/src/components/Footer/logo-red.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fawaz404dev/ipfs-upload-dapp/592fa8920b249652386d6ef6deb8c7907663488d/client/src/components/Footer/logo-red.png -------------------------------------------------------------------------------- /client/src/components/Footer/mail.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ic_mail 5 | Created with Sketch. 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /client/src/components/Footer/pencil.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ic_medium 5 | Created with Sketch. 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /client/src/components/Footer/twitter.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ic_twitter 5 | Created with Sketch. 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /client/src/components/Footer/zeppelin_logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | OZ_logo_color 5 | Created with Sketch. 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /client/src/components/Hash/Hash.module.scss: -------------------------------------------------------------------------------- 1 | @import '../../layout/variables.scss'; 2 | 3 | .loader { 4 | } 5 | 6 | .code { 7 | width: 100%; 8 | display: flex; 9 | flex-flow: row nowrap; 10 | align-items: center; 11 | margin: 10px 0; 12 | 13 | code { 14 | background: rgba(231, 231, 238, 0.5); 15 | border-radius: 0px; 16 | } 17 | } 18 | 19 | .counter { 20 | padding: 40px 0; 21 | display: flex; 22 | flex-flow: column wrap; 23 | justify-content: flex-start; 24 | align-items: flex-start; 25 | width: 380px; 26 | height: auto; 27 | padding: 40px 20px; 28 | border: 1px solid #ccc; 29 | box-shadow: 0px 2px 2px #ccc; 30 | 31 | h3 { 32 | border-bottom: 1px dotted #ffbe44; 33 | padding-bottom: 5px; 34 | } 35 | 36 | .dataPoint { 37 | display: flex; 38 | flex-flow: column nowrap; 39 | align-items: flex-start; 40 | margin: 5px 0; 41 | width: 100%; 42 | 43 | .value { 44 | font-weight: bold; 45 | display: flex; 46 | flex-flow: row nowrap; 47 | justify-content: space-between; 48 | align-items: baseline; 49 | } 50 | } 51 | 52 | .buttons { 53 | display: flex; 54 | width: 100%; 55 | flex-flow: column nowrap; 56 | align-items: center; 57 | button { 58 | margin: 5px 0; 59 | width: 100%; 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /client/src/components/Hash/index.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useEffect, useCallback } from 'react'; 2 | import { EthAddress } from 'rimble-ui'; 3 | 4 | import styles from './Hash.module.scss'; 5 | import FileForm from '../FileForm'; 6 | import getTransactionReceipt from '../../utils/getTransactionReceipt'; 7 | import { utils } from '@openzeppelin/gsn-provider'; 8 | const { isRelayHubDeployedForRecipient, getRecipientFunds } = utils; 9 | 10 | export default function Hash(props) { 11 | const { instance, accounts, lib, networkName, networkId, providerName } = props; 12 | const { _address } = instance || {}; 13 | 14 | // GSN provider has only one key pair 15 | const isGSN = providerName === 'GSN'; 16 | 17 | const [balance, setBalance] = useState(0); 18 | 19 | const getBalance = useCallback(async () => { 20 | const balance = 21 | accounts && accounts.length > 0 ? lib.utils.fromWei(await lib.eth.getBalance(accounts[0]), 'ether') : 'Unknown'; 22 | setBalance(Number(balance)); 23 | }, [accounts, lib.eth, lib.utils]); 24 | 25 | useEffect(() => { 26 | if (!isGSN) getBalance(); 27 | }, [accounts, getBalance, isGSN, lib.eth, lib.utils, networkId]); 28 | 29 | const [, setIsDeployed] = useState(false); 30 | const [funds, setFunds] = useState(0); 31 | 32 | const getDeploymentAndFunds = useCallback(async () => { 33 | if (instance) { 34 | if (isGSN) { 35 | // if GSN check how much funds recipient has 36 | const isDeployed = await isRelayHubDeployedForRecipient(lib, _address); 37 | 38 | setIsDeployed(isDeployed); 39 | if (isDeployed) { 40 | const funds = await getRecipientFunds(lib, _address); 41 | setFunds(Number(funds)); 42 | } 43 | } 44 | } 45 | }, [_address, instance, isGSN, lib]); 46 | 47 | useEffect(() => { 48 | getDeploymentAndFunds(); 49 | }, [getDeploymentAndFunds, instance]); 50 | 51 | const [updating, setUpdating] = useState(false); 52 | const [transactionHash, setTransactionHash] = useState(''); 53 | 54 | const update = async text => { 55 | try { 56 | if (!updating) { 57 | setUpdating(true); 58 | 59 | const tx = await instance.methods.setHash(text).send({ from: accounts[0] }); 60 | const receipt = await getTransactionReceipt(lib, tx.transactionHash); 61 | setTransactionHash(receipt.transactionHash); 62 | 63 | getDeploymentAndFunds(); 64 | } 65 | } catch (e) { 66 | console.log(e); 67 | } 68 | }; 69 | 70 | function renderNoDeploy() { 71 | return ( 72 |
73 |

74 | Can't Load Deployed Counter Instance 75 |

76 |

Please, run `oz create` to deploy an counter instance.

77 |
78 | ); 79 | } 80 | 81 | function renderNoFunds() { 82 | return ( 83 |
84 |

85 | The recipient has no funds 86 |

87 |

Please, run:

88 |
89 | 90 | npx oz-gsn fund-recipient --recipient {_address} 91 | 92 |
93 |

to fund the recipient on local network.

94 |
95 | ); 96 | } 97 | 98 | function renderNoBalance() { 99 | return ( 100 |
101 |

102 | Fund your Metamask account 103 |

104 |

You need some ETH to be able to send transactions. Please, run:

105 |
106 | 107 | openzeppelin transfer --to {accounts[0]} 108 | 109 |
110 |

to fund your Metamask.

111 |
112 | ); 113 | } 114 | 115 | function renderTransactionHash() { 116 | return ( 117 |
118 |

119 | Transaction{' '} 120 | 125 | {transactionHash.substr(0, 6)} 126 | {' '} 127 | has been mined on {networkName} network. 128 |

129 |
130 | ); 131 | } 132 | 133 | return ( 134 |
135 |

Hash Instance

136 | {lib && !instance && renderNoDeploy()} 137 | {lib && instance && ( 138 | <> 139 |
140 |
Instance address:
141 |
142 | 143 |
144 |
145 | {isGSN && ( 146 |
147 |
Recipient Funds:
148 |
{lib.utils.fromWei(funds.toString(), 'ether')} ETH
149 |
150 | )} 151 | {isGSN && !funds && renderNoFunds()} 152 | {!isGSN && !balance && renderNoBalance()} 153 | 154 | {(!!funds || !!balance) && ( 155 | <> 156 |
157 | 158 |
159 | 160 | )} 161 | {transactionHash && networkName !== 'Private' && renderTransactionHash()} 162 | 163 | )} 164 |
165 | ); 166 | } 167 | -------------------------------------------------------------------------------- /client/src/components/Header/header.module.scss: -------------------------------------------------------------------------------- 1 | @import '../../layout/variables.scss'; 2 | 3 | .header { 4 | padding: 10px 0; 5 | width: 100%; 6 | background: #3c4653; 7 | border-bottom: 1px solid rgba(0, 0, 0, 0.1); 8 | height: auto; 9 | display: flex; 10 | justify-content: center; 11 | 12 | nav { 13 | width: 100%; 14 | max-width: 1180px; 15 | padding: 0 30px; 16 | display: flex; 17 | justify-content: space-between; 18 | align-items: center; 19 | 20 | .brand { 21 | display: flex; 22 | flex-flow: row nowrap; 23 | justify-content: flex-start; 24 | align-items: center; 25 | width: 300px; 26 | 27 | img { 28 | height: 1.5em; 29 | vertical-align: middle; 30 | } 31 | } 32 | 33 | ul { 34 | margin: 0; 35 | padding: 0; 36 | display: flex; 37 | flex-flow: row nowrap; 38 | height: 60px; 39 | list-style: none; 40 | 41 | li { 42 | padding: 15px; 43 | margin: 0; 44 | margin-right: 60px; 45 | text-decoration: none; 46 | a { 47 | color: $white; 48 | text-transform: uppercase; 49 | font-size: 14px; 50 | letter-spacing: 2px; 51 | text-decoration: none; 52 | font-family: 'Roboto Mono', monospace; 53 | letter-spacing: 0.8px; 54 | opacity: 0.8; 55 | 56 | &:hover { 57 | opacity: 1; 58 | text-decoration: none; 59 | border-bottom: 2px solid $white; 60 | } 61 | } 62 | } 63 | } 64 | } 65 | } 66 | 67 | @media only screen and (max-width: $screen-sm-max) { 68 | .header nav ul .brand { 69 | width: 100%; 70 | margin-right: 0px; 71 | justify-content: flex-start; 72 | } 73 | } 74 | @media only screen and (max-width: $screen-sm-min) { 75 | .header { 76 | nav { 77 | flex-flow: row wrap; 78 | margin-top: 10px; 79 | } 80 | 81 | nav ul { 82 | flex-flow: row wrap; 83 | height: auto; 84 | li { 85 | width: 100%; 86 | text-align: left; 87 | padding: 3px 0; 88 | } 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /client/src/components/Header/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import styles from './header.module.scss'; 3 | 4 | const Header = () => ( 5 |
6 | 13 |
14 | ); 15 | 16 | export default Header; 17 | -------------------------------------------------------------------------------- /client/src/components/Web3Info/Web3Info.module.scss: -------------------------------------------------------------------------------- 1 | @import '../../layout/variables.scss'; 2 | 3 | .web3 { 4 | padding: 40px 0; 5 | display: flex; 6 | flex-flow: column wrap; 7 | justify-content: flex-start; 8 | align-items: flex-start; 9 | width: 380px; 10 | height: auto; 11 | padding: 40px 20px; 12 | border: 1px solid #ccc; 13 | box-shadow: 0px 2px 2px #ccc; 14 | 15 | h3 { 16 | border-bottom: 1px dotted #ffbe44; 17 | padding-bottom: 5px; 18 | } 19 | 20 | .dataPoint { 21 | display: flex; 22 | flex-flow: column nowrap; 23 | align-items: flex-start; 24 | margin: 5px 0; 25 | width: 100%; 26 | 27 | .value { 28 | font-weight: bold; 29 | display: flex; 30 | flex-flow: row nowrap; 31 | justify-content: space-between; 32 | align-items: baseline; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /client/src/components/Web3Info/index.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useEffect, useCallback } from 'react'; 2 | import { EthAddress, Button } from 'rimble-ui'; 3 | import styles from './Web3Info.module.scss'; 4 | 5 | export default function Web3Info(props) { 6 | const { context } = props; 7 | const { networkId, networkName, accounts, providerName, lib } = context; 8 | 9 | const [balance, setBalance] = useState(0); 10 | 11 | const getBalance = useCallback(async () => { 12 | const balance = 13 | accounts && accounts.length > 0 ? lib.utils.fromWei(await lib.eth.getBalance(accounts[0]), 'ether') : 'Unknown'; 14 | setBalance(balance); 15 | }, [accounts, lib.eth, lib.utils]); 16 | 17 | useEffect(() => { 18 | getBalance(); 19 | }, [accounts, getBalance, networkId]); 20 | 21 | const requestAuth = async web3Context => { 22 | try { 23 | await web3Context.requestAuth(); 24 | } catch (e) { 25 | console.error(e); 26 | } 27 | }; 28 | 29 | return ( 30 |
31 |

{props.title}

32 |
33 |
Network:
34 |
{networkId ? `${networkId} – ${networkName}` : 'No connection'}
35 |
36 |
37 |
Your address:
38 |
39 | 40 |
41 |
42 |
43 |
Your ETH balance:
44 |
{balance}
45 |
46 |
47 |
Provider:
48 |
{providerName}
49 |
50 | {accounts && accounts.length ? ( 51 |
52 |
Accounts & Signing Status
53 |
Access Granted
54 |
55 | ) : !!networkId && providerName !== 'infura' ? ( 56 |
57 |
58 | 59 |
60 | ) : ( 61 |
62 | )} 63 |
64 | ); 65 | } 66 | -------------------------------------------------------------------------------- /client/src/images/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /client/src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './layout/index.scss'; 4 | import App from './App'; 5 | import * as serviceWorker from './serviceWorker'; 6 | 7 | ReactDOM.render(, document.getElementById('root')); 8 | 9 | // If you want your app to work offline and load faster, you can change 10 | // unregister() to register() below. Note this comes with some pitfalls. 11 | // Learn more about service workers: http://bit.ly/CRA-PWA 12 | serviceWorker.unregister(); 13 | -------------------------------------------------------------------------------- /client/src/layout/index.scss: -------------------------------------------------------------------------------- 1 | @import './variables.scss'; 2 | 3 | html { 4 | -ms-text-size-adjust: 100%; 5 | -webkit-text-size-adjust: 100%; 6 | } 7 | 8 | html, 9 | body { 10 | overflow-x: hidden; 11 | } 12 | 13 | body { 14 | margin: 0; 15 | padding: 0; 16 | font: 112.5%/1.45em 'Roboto', sans-serif; 17 | box-sizing: border-box; 18 | overflow-y: scroll; 19 | background: $white; 20 | color: $primary; 21 | } 22 | 23 | a { 24 | color: $blue; 25 | text-decoration: none; 26 | cursor: pointer; 27 | 28 | &:hover { 29 | text-decoration: underline; 30 | } 31 | } 32 | 33 | * { 34 | box-sizing: inherit; 35 | } 36 | *:before { 37 | box-sizing: inherit; 38 | } 39 | *:after { 40 | box-sizing: inherit; 41 | } 42 | 43 | body { 44 | color: hsla(0, 0%, 0%, 0.8); 45 | font-weight: normal; 46 | word-wrap: break-word; 47 | font-kerning: normal; 48 | -moz-font-feature-settings: 'kern', 'liga', 'clig', 'calt'; 49 | -ms-font-feature-settings: 'kern', 'liga', 'clig', 'calt'; 50 | -webkit-font-feature-settings: 'kern', 'liga', 'clig', 'calt'; 51 | font-feature-settings: 'kern', 'liga', 'clig', 'calt'; 52 | } 53 | 54 | img { 55 | max-width: 100%; 56 | margin-left: 0; 57 | margin-right: 0; 58 | margin-top: 0; 59 | padding-bottom: 0; 60 | padding-left: 0; 61 | padding-right: 0; 62 | padding-top: 0; 63 | margin-bottom: 0; 64 | } 65 | h1 { 66 | margin-left: 0; 67 | margin-right: 0; 68 | margin-top: 0; 69 | padding-bottom: 0; 70 | padding-left: 0; 71 | padding-right: 0; 72 | padding-top: 0; 73 | margin-bottom: 1.45rem; 74 | color: inherit; 75 | font-weight: bold; 76 | text-rendering: optimizeLegibility; 77 | line-height: 1.1; 78 | font-size: 2em; 79 | font-weight: 300; 80 | } 81 | h2 { 82 | margin-left: 0; 83 | margin-right: 0; 84 | margin-top: 0; 85 | padding-bottom: 0; 86 | padding-left: 0; 87 | padding-right: 0; 88 | padding-top: 0; 89 | margin-bottom: 1.45rem; 90 | color: inherit; 91 | font-weight: bold; 92 | text-rendering: optimizeLegibility; 93 | font-size: 1.62671rem; 94 | line-height: 1.1; 95 | } 96 | h3 { 97 | margin-left: 0; 98 | margin-right: 0; 99 | margin-top: 0; 100 | padding-bottom: 0; 101 | padding-left: 0; 102 | padding-right: 0; 103 | padding-top: 0; 104 | margin-bottom: 1.45rem; 105 | color: inherit; 106 | font-weight: bold; 107 | text-rendering: optimizeLegibility; 108 | font-size: 1.38316rem; 109 | line-height: 1.1; 110 | } 111 | h4 { 112 | margin-left: 0; 113 | margin-right: 0; 114 | margin-top: 0; 115 | padding-bottom: 0; 116 | padding-left: 0; 117 | padding-right: 0; 118 | padding-top: 0; 119 | margin-bottom: 1.45rem; 120 | color: inherit; 121 | font-weight: bold; 122 | text-rendering: optimizeLegibility; 123 | font-size: 1rem; 124 | line-height: 1.1; 125 | } 126 | h5 { 127 | margin-left: 0; 128 | margin-right: 0; 129 | margin-top: 0; 130 | padding-bottom: 0; 131 | padding-left: 0; 132 | padding-right: 0; 133 | padding-top: 0; 134 | margin-bottom: 1.45rem; 135 | color: inherit; 136 | font-weight: bold; 137 | text-rendering: optimizeLegibility; 138 | font-size: 0.85028rem; 139 | line-height: 1.1; 140 | } 141 | h6 { 142 | margin-left: 0; 143 | margin-right: 0; 144 | margin-top: 0; 145 | padding-bottom: 0; 146 | padding-left: 0; 147 | padding-right: 0; 148 | padding-top: 0; 149 | margin-bottom: 1.45rem; 150 | color: inherit; 151 | font-weight: bold; 152 | text-rendering: optimizeLegibility; 153 | font-size: 0.78405rem; 154 | line-height: 1.1; 155 | } 156 | 157 | button { 158 | box-shadow: none; 159 | outline: none; 160 | color: $white; 161 | padding: 10px 15px; 162 | border: 1px solid $white; 163 | font-size: 16px; 164 | font-weight: 400; 165 | cursor: pointer; 166 | 167 | &.purple { 168 | background: $primary; 169 | &:hover { 170 | background: $white; 171 | color: $primary; 172 | border-color: $primary; 173 | } 174 | } 175 | 176 | &.yellow { 177 | background: $yellow; 178 | &:hover { 179 | background: $white; 180 | color: $yellow; 181 | border-color: $yellow; 182 | } 183 | } 184 | 185 | &.pink { 186 | background: $pink; 187 | &:hover { 188 | background: $white; 189 | color: $pink; 190 | border-color: $pink; 191 | } 192 | } 193 | } 194 | 195 | input { 196 | width: 100%; 197 | border: 1px solid #ccc; 198 | padding: 5px; 199 | color: $primary; 200 | margin: 5px 0; 201 | } 202 | 203 | @media only screen and (max-width: 480px) { 204 | html { 205 | font-size: 100%; 206 | } 207 | } 208 | -------------------------------------------------------------------------------- /client/src/layout/variables.scss: -------------------------------------------------------------------------------- 1 | // Colors 2 | $primary: #3c4653; 3 | $blue: #39e6e0; 4 | $purple: #4420d8; 5 | $purple-aux: #917dff; 6 | $yellow: #ffbe44; 7 | $pink: #ff2972; 8 | $white: #fff; 9 | $black: #000; 10 | 11 | // Fonts (use typography.js) 12 | $font-size-base: 16px; 13 | $font-size-h1: 3.375em; 14 | // $font-family-sans-serif: 'Open Sans', sans-serif; 15 | $line-height-base: 1.42; 16 | 17 | // Responsive 18 | $screen-xs: 576px; 19 | $screen-sm-min: 768px; 20 | $screen-sm-max: 992px; 21 | $screen-md-max: 1280px; 22 | -------------------------------------------------------------------------------- /client/src/serviceWorker.js: -------------------------------------------------------------------------------- 1 | // This optional code is used to register a service worker. 2 | // register() is not called by default. 3 | 4 | // This lets the app load faster on subsequent visits in production, and gives 5 | // it offline capabilities. However, it also means that developers (and users) 6 | // will only see deployed updates on subsequent visits to a page, after all the 7 | // existing tabs open on the page have been closed, since previously cached 8 | // resources are updated in the background. 9 | 10 | // To learn more about the benefits of this model and instructions on how to 11 | // opt-in, read http://bit.ly/CRA-PWA 12 | 13 | const isLocalhost = Boolean( 14 | window.location.hostname === 'localhost' || 15 | // [::1] is the IPv6 localhost address. 16 | window.location.hostname === '[::1]' || 17 | // 127.0.0.1/8 is considered localhost for IPv4. 18 | window.location.hostname.match(/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/), 19 | ); 20 | 21 | export function register(config) { 22 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) { 23 | // The URL constructor is available in all browsers that support SW. 24 | const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href); 25 | if (publicUrl.origin !== window.location.origin) { 26 | // Our service worker won't work if PUBLIC_URL is on a different origin 27 | // from what our page is served on. This might happen if a CDN is used to 28 | // serve assets; see https://github.com/facebook/create-react-app/issues/2374 29 | return; 30 | } 31 | 32 | window.addEventListener('load', () => { 33 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`; 34 | 35 | if (isLocalhost) { 36 | // This is running on localhost. Let's check if a service worker still exists or not. 37 | checkValidServiceWorker(swUrl, config); 38 | 39 | // Add some additional logging to localhost, pointing developers to the 40 | // service worker/PWA documentation. 41 | navigator.serviceWorker.ready.then(() => { 42 | console.log( 43 | 'This web app is being served cache-first by a service ' + 44 | 'worker. To learn more, visit http://bit.ly/CRA-PWA', 45 | ); 46 | }); 47 | } else { 48 | // Is not localhost. Just register service worker 49 | registerValidSW(swUrl, config); 50 | } 51 | }); 52 | } 53 | } 54 | 55 | function registerValidSW(swUrl, config) { 56 | navigator.serviceWorker 57 | .register(swUrl) 58 | .then(registration => { 59 | registration.onupdatefound = () => { 60 | const installingWorker = registration.installing; 61 | if (installingWorker == null) { 62 | return; 63 | } 64 | installingWorker.onstatechange = () => { 65 | if (installingWorker.state === 'installed') { 66 | if (navigator.serviceWorker.controller) { 67 | // At this point, the updated precached content has been fetched, 68 | // but the previous service worker will still serve the older 69 | // content until all client tabs are closed. 70 | console.log( 71 | 'New content is available and will be used when all ' + 72 | 'tabs for this page are closed. See http://bit.ly/CRA-PWA.', 73 | ); 74 | 75 | // Execute callback 76 | if (config && config.onUpdate) { 77 | config.onUpdate(registration); 78 | } 79 | } else { 80 | // At this point, everything has been precached. 81 | // It's the perfect time to display a 82 | // "Content is cached for offline use." message. 83 | console.log('Content is cached for offline use.'); 84 | 85 | // Execute callback 86 | if (config && config.onSuccess) { 87 | config.onSuccess(registration); 88 | } 89 | } 90 | } 91 | }; 92 | }; 93 | }) 94 | .catch(error => { 95 | console.error('Error during service worker registration:', error); 96 | }); 97 | } 98 | 99 | function checkValidServiceWorker(swUrl, config) { 100 | // Check if the service worker can be found. If it can't reload the page. 101 | fetch(swUrl) 102 | .then(response => { 103 | // Ensure service worker exists, and that we really are getting a JS file. 104 | const contentType = response.headers.get('content-type'); 105 | if (response.status === 404 || (contentType != null && contentType.indexOf('javascript') === -1)) { 106 | // No service worker found. Probably a different app. Reload the page. 107 | navigator.serviceWorker.ready.then(registration => { 108 | registration.unregister().then(() => { 109 | window.location.reload(); 110 | }); 111 | }); 112 | } else { 113 | // Service worker found. Proceed as normal. 114 | registerValidSW(swUrl, config); 115 | } 116 | }) 117 | .catch(() => { 118 | console.log('No internet connection found. App is running in offline mode.'); 119 | }); 120 | } 121 | 122 | export function unregister() { 123 | if ('serviceWorker' in navigator) { 124 | navigator.serviceWorker.ready.then(registration => { 125 | registration.unregister(); 126 | }); 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /client/src/utils/getTransactionReceipt.js: -------------------------------------------------------------------------------- 1 | import sleep from './sleep'; 2 | 3 | export default async function getTransactionReceipt(web3, hash, pollInterval = 500) { 4 | let receipt = null; 5 | while (receipt === null) { 6 | // we are going to check every second if transation is mined or not, once it is mined we'll leave the loop 7 | receipt = await getTransactionReceiptPromise(web3, hash); 8 | await sleep(pollInterval); 9 | } 10 | return receipt; 11 | } 12 | 13 | function getTransactionReceiptPromise(web3, hash) { 14 | // here we just promisify getTransactionReceipt function for convenience 15 | return new Promise((resolve, reject) => { 16 | web3.eth.getTransactionReceipt(hash, function(err, data) { 17 | if (err !== null) reject(err); 18 | else resolve(data); 19 | }); 20 | }); 21 | } 22 | -------------------------------------------------------------------------------- /client/src/utils/ipfs.js: -------------------------------------------------------------------------------- 1 | import IPFS from 'ipfs-http-client'; 2 | 3 | export default new IPFS({ 4 | host: 'ipfs.infura.io', 5 | port: 5001, 6 | protocol: 'https', 7 | }); 8 | -------------------------------------------------------------------------------- /client/src/utils/sleep.js: -------------------------------------------------------------------------------- 1 | export default function sleep(ms) { 2 | return new Promise(resolve => setTimeout(resolve, ms)); 3 | } 4 | -------------------------------------------------------------------------------- /contracts/Hash.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | import "@openzeppelin/contracts-ethereum-package/contracts/GSN/GSNRecipient.sol"; 4 | import "@openzeppelin/upgrades/contracts/Initializable.sol"; 5 | 6 | contract Hash is Initializable, GSNRecipient { 7 | string public ipfsHash; 8 | 9 | // --------- Make contract GSN-capable 10 | function initialize() public initializer { 11 | GSNRecipient.initialize(); 12 | } 13 | 14 | // accept all requests 15 | function acceptRelayedCall( 16 | address, 17 | address, 18 | bytes calldata, 19 | uint256, 20 | uint256, 21 | uint256, 22 | uint256, 23 | bytes calldata, 24 | uint256 25 | ) external view returns (uint256, bytes memory) { 26 | return _approveRelayedCall(); 27 | } 28 | 29 | function _preRelayedCall(bytes memory context) internal returns (bytes32) { 30 | } 31 | 32 | function _postRelayedCall(bytes memory context, bool, uint256 actualCharge, bytes32) internal { 33 | } 34 | 35 | function setRelayHubAddress() public { 36 | if(getHubAddr() == address(0)) { 37 | _upgradeRelayHub(0xD216153c06E857cD7f72665E0aF1d7D82172F494); 38 | } 39 | } 40 | 41 | function getRecipientBalance() public view returns (uint) { 42 | return IRelayHub(getHubAddr()).balanceOf(address(this)); 43 | } 44 | // -------------------- 45 | // Hash contract stuff 46 | function setHash(string memory x) public { 47 | ipfsHash = x; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /img/diagram.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fawaz404dev/ipfs-upload-dapp/592fa8920b249652386d6ef6deb8c7907663488d/img/diagram.jpg -------------------------------------------------------------------------------- /img/ipfs-dapp-architecture.drawio: -------------------------------------------------------------------------------- 1 | 7V3bcuLIsv2ajvM0Hbra5hEjsOVNSY0RpsXLCRC0QFy3ASPp60+uLAlKgLs9c7p7T0zsiZgxKklVWSuvVZml+WQ2lunD63AzFevxZPHJ0MbpJ9P5ZBi6pd3RH7RksuWmZsiG+HU2Lh46NXRn+aRo1IrW/Ww82VYe3K3Xi91sU22M1qvVJNpV2oavr+tD9bFv60V11M0wnlw0dKPh4rK1PxvvprL1ztZO7Y+TWTwtR9a14s5yWD5cNGynw/H6oDSZzU9m43W93slfy7QxWQC8Ehf5Xuudu0fCXier3U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kXloUQRKNvQOOA6V9HJZcLpRvZI0cHOYft7xk0CJeVw+Xzgf9QY4Wzqq0ZN/y0wTedvi1fpBZlqdFaHbisbFQvtbO2RnssTXcePjwshkYU42/Il1QgHHHxnQzfuiV31HjzE4Ph+Icvj6Orlhu0zP4YGSZG7xIBF5JF76fG/xQ3bT+G7OD11LJ//HsYPXY0evw8Dme7ab70X47eY3Wqx2h/TmifoyWv5msBpPNZrJApVNrTZd5cVk8sRxukSI2Wtw5TibNqIvPm1X8i1hq2Je11saV6tKf8a2oqyy9rF+soqRdlos9DHGsoVv8v3QMzZvsDuvX+d80Y/8TuHZ7UT50c+W8ifUbFdH+sSIqNWEFqt8tCFO58Mkwv91Fkyi6YBndub/THO32COxZideHYP09VV+2cb0Q508f9dLOOtLOOvrL5V4wV8f/UZl8/PS/ezOb/wc= -------------------------------------------------------------------------------- /migrations/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fawaz404dev/ipfs-upload-dapp/592fa8920b249652386d6ef6deb8c7907663488d/migrations/.gitkeep -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "starter-kit-gsn", 3 | "version": "1.0.2", 4 | "description": "An OpenZeppelin starter kit focused on GSN.", 5 | "main": "index.js", 6 | "scripts": { 7 | "build-contracts": "openzeppelin compile", 8 | "test": "echo \"Error: no test specified\" && exit 1", 9 | "pre-push": "cd client && npm run pre-push", 10 | "pre-commit": "cd client && npm run pre-commit" 11 | }, 12 | "husky": { 13 | "hooks": { 14 | "pre-push": "npm run pre-push", 15 | "pre-commit": "npm run pre-commit" 16 | } 17 | }, 18 | "repository": { 19 | "type": "git", 20 | "url": "git+https://github.com/OpenZeppelin/starter-kit-gsn" 21 | }, 22 | "keywords": [ 23 | "openzeppelin", 24 | "truffle", 25 | "react", 26 | "dapp", 27 | "infura", 28 | "metamask", 29 | "web3", 30 | "ganache", 31 | "web3js", 32 | "ethereum", 33 | "smart-contracts" 34 | ], 35 | "author": "Igor Yalovoy ", 36 | "license": "MIT", 37 | "bugs": { 38 | "url": "https://github.com/OpenZeppelin/starter-kit-gsn/issues" 39 | }, 40 | "homepage": "https://github.com/OpenZeppelin/starter-kit-gsn#readme", 41 | "dependencies": { 42 | "@openzeppelin/contracts-ethereum-package": "^2.4.0", 43 | "@openzeppelin/upgrades": "^2.5.3", 44 | "dotenv": "^6.2.0", 45 | "truffle-hdwallet-provider": "^1.0.3" 46 | }, 47 | "devDependencies": { 48 | "@openzeppelin/cli": "^2.5.3", 49 | "@openzeppelin/gsn-helpers": "^0.1.9", 50 | "chai": "^4.2.0", 51 | "husky": "^3.0.4", 52 | "openzeppelin-test-helpers": "^0.4.3" 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /solhint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "default", 3 | "rules": { 4 | "indent": ["error", 4], 5 | 6 | "bracket-align": false, 7 | "compiler-fixed": false, 8 | "no-simple-event-func-name": false, 9 | "two-lines-top-level-separator": false 10 | } 11 | } -------------------------------------------------------------------------------- /test/hash.js: -------------------------------------------------------------------------------- 1 | const { 2 | BN, 3 | constants, 4 | expectEvent, 5 | shouldFail 6 | } = require('openzeppelin-test-helpers') 7 | const should = require('chai').should() 8 | 9 | const Hash = artifacts.require('Hash') 10 | 11 | contract('hash', async ([_, ...otherAccounts]) => { 12 | let hash 13 | 14 | beforeEach(async function () { 15 | hash = await Hash.new() 16 | hash.initialize() 17 | }) 18 | 19 | it('should have proper default value', async () => { 20 | const ipfsHash = await hash.ipfsHash.call() 21 | ipfsHash.should.equal('') 22 | }) 23 | 24 | it('should update ipfsHash value', async () => { 25 | const testString = 'test' 26 | await hash.setHash(testString); 27 | (await hash.ipfsHash()).should.equal(testString) 28 | }) 29 | }) 30 | -------------------------------------------------------------------------------- /truffle-config.js: -------------------------------------------------------------------------------- 1 | require('dotenv').config(); 2 | const mnemonic = process.env.MNEMONIC; 3 | const HDWalletProvider = require("truffle-hdwallet-provider"); 4 | // Create your own key for Production environments (https://infura.io/) 5 | const INFURA_ID = process.env.INFURA_ID || 'd6760e62b67f4937ba1ea2691046f06d'; 6 | 7 | 8 | const configNetwok = (network, networkId, path = "m/44'/60'/0'/0/", gas = 4465030, gasPrice = 1e10) => ({ 9 | provider: () => new HDWalletProvider( 10 | mnemonic, `https://${network}.infura.io/v3/${INFURA_ID}`, 11 | 0, 1, true, path 12 | ), 13 | networkId, 14 | gas, 15 | gasPrice, 16 | }); 17 | 18 | module.exports = { 19 | // See 20 | // to customize your Truffle configuration! 21 | networks: { 22 | development: { 23 | host: "127.0.0.1", 24 | port: 8545, 25 | network_id: "*", 26 | }, 27 | ropsten: configNetwok('ropsten', 3), 28 | kovan: configNetwok('kovan', 42), 29 | rinkeby: configNetwok('rinkeby', 4), 30 | main: configNetwok('mainnet', 1), 31 | }, 32 | }; 33 | --------------------------------------------------------------------------------