|
| 1 | +# ARK Core - dApp Template Project |
| 2 | + |
| 3 | +This is a basic template project for ARK core dApp development. Create a new project based on this template and load your plugin into the corresponding network configuration by following the steps below. |
| 4 | + |
| 5 | +> This Example is currently operational only on our `core/develop` branch! |
| 6 | +
|
| 7 | +This template project provides initial structure for your dApp development. |
| 8 | + |
| 9 | +## dApp Creation Steps |
| 10 | + |
| 11 | +### STEP 0: Create New Project Based On This Template |
| 12 | + |
| 13 | +### STEP 1: Checkout Your New dApp Project As a GitSubmodule in `core/plugins` |
| 14 | + |
| 15 | +You should already have a running core and a local testnet running. If not head over to https://learn.ark.dev/core-getting-started/spinning-up-your-first-testnet#step-2-testnet-network-boot. |
| 16 | + |
| 17 | +```bash |
| 18 | +cd plugins/ #location for loading of custom non-core dApps |
| 19 | +git submodule add -f https://github.com/your-gh-handle/your-dapp-name |
| 20 | +cd your-dapp-name |
| 21 | +``` |
| 22 | + |
| 23 | +### STEP 2: Load The dApp In The Corresponding Network Configurations. |
| 24 | + |
| 25 | +We will enable our dApp `@vendorname/dappname` in the testnet network configuration. dApp name is taken from `node` package name as defined in package.json. |
| 26 | +You can change it to your needs. |
| 27 | + |
| 28 | +Go to: |
| 29 | +`core/packages/core/bin/testnet` |
| 30 | + |
| 31 | +```bash |
| 32 | +cd packages/core/bin/config/testnet |
| 33 | +``` |
| 34 | + |
| 35 | +Locate file `plugins.js`. We will add our dApp name to end of the list of the loaded plugins. This means that core will pickup the dapp and load it for a specific network configuration. |
| 36 | + |
| 37 | +Add line `"@arkecosystem/dappname": {}`: to the end of the `plugins.js` file, so it looks something like this: |
| 38 | + |
| 39 | +```javascript |
| 40 | + "@arkecosystem/core-exchange-json-rpc": { |
| 41 | + enabled: process.env.CORE_EXCHANGE_JSON_RPC_ENABLED, |
| 42 | + host: process.env.CORE_EXCHANGE_JSON_RPC_HOST || "0.0.0.0", |
| 43 | + port: process.env.CORE_EXCHANGE_JSON_RPC_PORT || 8080, |
| 44 | + allowRemote: false, |
| 45 | + whitelist: ["127.0.0.1", "::ffff:127.0.0.1"], |
| 46 | + }, |
| 47 | + "@arkecosystem/core-snapshots": {}, |
| 48 | + "@vendorname/dappname": {}, //our application hook (here we load the plugin/dapp, as defined in your dapp package.json) |
| 49 | +``` |
| 50 | + |
| 51 | +> Make sure to run `yarn setup` from the `core` root folder when you change or add code to `core/plugins` |
| 52 | +
|
| 53 | +After `yarn setup` completes, you should see the following log |
| 54 | + |
| 55 | +```bash |
| 56 | +lerna success - @arkecosystem/core-vote-report |
| 57 | +lerna success - @arkecosystem/core-wallet-api |
| 58 | +lerna success - @arkecosystem/core-webhooks |
| 59 | +lerna success - @arkecosystem/core |
| 60 | +lerna success - @arkecosystem/crypto |
| 61 | +lerna success - @vendorname/dappname |
| 62 | +``` |
| 63 | + |
| 64 | +Last line showing that your dApp was detected and compiled. |
| 65 | + |
| 66 | +### STEP 3: Start Local Testnet Blockchain |
| 67 | + |
| 68 | +Start local blockchain with testnet running on your developer computer. Follow steps defined in here: |
| 69 | +https://learn.ark.dev/core-getting-started/spinning-up-your-first-testnet#step-2-testnet-network-boot |
| 70 | + |
| 71 | +If you already have running and compiled core, you should go to `core/packages/core` and run command `yarn full:testnet`. |
| 72 | + |
| 73 | +After local testnet starts, the log should show that dApp was loaded. It should look like this (if you haven't changed the source code): |
| 74 | + |
| 75 | +```bash |
| 76 | +[2019-10-22 11:13:27.161] INFO : Starting dApp |
| 77 | +[2019-10-22 11:13:27.161] INFO : Initialization of dApp |
| 78 | +``` |
| 79 | + |
| 80 | +> Congratulations. Your first distributed blockchain application is loaded and working and compatible with any ARK Core based blockchain. |
| 81 | +
|
| 82 | +Feel free to look into `common/base-service.ts` class that exposes important Core Platform classes that you can work with. Your newly developed classes can extend this class and gain access to: |
| 83 | + |
| 84 | +- wallets and state |
| 85 | +- transaction pool |
| 86 | +- blockchain protocol |
| 87 | +- events |
| 88 | +- database |
| 89 | + -... actually any module :) |
| 90 | + |
| 91 | +> Also check other packages/modules as they follow the same dApp structure. |
| 92 | +
|
| 93 | +## Use Block Explorer To View Local Running Testnet |
| 94 | + |
| 95 | +The following code instructions will run a local copy of ARK Explorer and connect to local node. |
| 96 | + |
| 97 | +```bash |
| 98 | +git clone https://github.com/arkecosystem/explorer |
| 99 | +cd explorer |
| 100 | + |
| 101 | +yarn install |
| 102 | + |
| 103 | +yarn serve:testnet |
| 104 | +``` |
| 105 | + |
| 106 | +After running `yarn serve:testnet` you should see the following: |
| 107 | + |
| 108 | +```bash |
| 109 | +DONE Compiled successfully in 11030ms 11:07:14 AM |
| 110 | + |
| 111 | +No type errors found |
| 112 | +Version: typescript 3.6.3 |
| 113 | +Time: 6973ms |
| 114 | + |
| 115 | + App running at: |
| 116 | + - Local: http://localhost:8080/ |
| 117 | + - Network: http://192.168.0.178:8080/ |
| 118 | + |
| 119 | + Note that the development build is not optimized. |
| 120 | + To create a production build, run yarn build. |
| 121 | +``` |
| 122 | + |
| 123 | +Head over to http://localhost:8080/ to view contents of local running blockchain with Testnet environment setup. |
| 124 | + |
| 125 | +--- |
| 126 | + |
| 127 | +> Congrats, your dapp is loaded. Now look at the resources below to understand more about our dapp development. |
| 128 | +
|
| 129 | +- [Learn Development With ARK](https://learn.ark.dev) |
| 130 | + |
| 131 | +## Security |
| 132 | + |
| 133 | +If you discover a security vulnerability within this package, please send an e-mail to [email protected]. All security vulnerabilities will be promptly addressed. |
| 134 | + |
| 135 | +## License |
| 136 | + |
| 137 | +[MIT](LICENSE) © [ArkEcosystem](https://ark.io) |
0 commit comments