2017-02-02 17:23:08 +03:00
# Status CLI
Additional tools for DApps developers. These tools allows to speed up the process of developing DApps for Status.
## Requirements
2017-02-08 17:35:30 +03:00
1. adb (from Android SDK);
2017-03-02 20:46:20 +03:00
2. Node.js;
3. NPM;
4. Watchman (https://facebook.github.io/watchman/docs/install.html).
2017-02-02 17:23:08 +03:00
2017-02-26 09:26:51 +02:00
## Installing
2017-02-02 17:23:08 +03:00
```
2017-02-26 09:26:51 +02:00
npm i -g status-dev-cli
2017-02-02 17:23:08 +03:00
```
2017-03-11 17:52:41 -05:00
## Command Line
2017-03-06 17:29:20 +03:00
**Common additional parameters:**
* `--ip <device-ip>` to specify your device's IP address.
2017-05-15 23:56:35 +03:00
#### 1. Adding a contact (DApp or bot)
2017-03-06 17:29:20 +03:00
2017-05-15 23:56:35 +03:00
`status-dev-cli add [contact]`
2017-03-06 17:29:20 +03:00
2017-05-15 23:56:35 +03:00
* `contact` — JSON containing contact information. It is not required if you develop a DApp and this DApp contains `package.json` file. Otherwise, this map should contain `whisper-identity` , `name` and `dapp-url` or `bot-url` fields (see the example in **Scenario** section)
2017-03-06 17:29:20 +03:00
You can additionally specify `--dapp-port <port>` if your DApp uses port other than 8080 and you don't specify a `dapp` JSON.
2017-05-15 23:56:35 +03:00
#### 2. Removing a contact (DApp or bot)
2017-03-06 17:29:20 +03:00
2017-05-15 23:56:35 +03:00
`status-dev-cli remove [contact]`
2017-03-06 17:29:20 +03:00
2017-05-15 23:56:35 +03:00
* `dapp` — JSON containing `whisper-identity` field. It is not required if you develop a DApp and this DApp contains `package.json` file.
2017-03-06 17:29:20 +03:00
#### 3. Refreshing a DApp automatically
2017-05-15 23:56:35 +03:00
`status-dev-cli watch [dir] [contact]`
2017-03-06 17:29:20 +03:00
2017-05-15 23:56:35 +03:00
* `dir` — dir that should be observed. Not required;
* `contact` — JSON containing `whisper-identity` field. It is not required if you develop a DApp and this DApp contains `package.json` file.
2017-03-06 17:29:20 +03:00
2017-03-10 12:16:17 +03:00
#### 4. Refreshing a DApp manually
***Requires status-dev-cli 2.2.1+!***
This command simply reloads the DApp
2017-05-15 23:56:35 +03:00
`status-dev-cli refresh [dapp]`
2017-03-10 12:16:17 +03:00
* `dapp` — JSON containing `whisper-identity` field. It is not required if your DApp contains `package.json` file.
#### 5. Switching network
2017-03-06 17:29:20 +03:00
***Requires Status 0.9.4+ & status-dev-cli 2.2.0+!***
Typically when developing DApps, a developer uses his own private chain or a simulator.
Status inserts its own web3 object into the DApp, however, this web3 object is connected to a different network than the development one.
This command allows to switch a network. Next time you login the network will be switched back.
`status-dev-cli switch-node <url>`
* `url` (required) — the network that will be used instead of `http://localhost:8545`
2017-03-11 17:52:41 -05:00
## Library
```
var StatusDev = require('status-dev-cli');
var statusDev = new StatusDev({ip: 'you-device-ip'});
```
#### dappData
```
dataData = {
"whisper-identity": "dapp-MyAppName",
"dapp-url": "http://your-server-ip:port",
"name": "My App Name"
}
```
#### 1. Adding a DApp
```
statusDev.addDapp(dappData, function(error, result) {});
```
#### 2. Refreshing a DApp
```
statusDev.refreshDapp(dappData, function(error, result) {});
```
#### 3. Removing a DApp
```
statusDev.removeDapp(dappData, function(error, result) {});
```
#### 4. Switching network
```
statusDev.switchNode(rpcUrl, function(error, result) {});
```
2017-03-06 17:29:20 +03:00
## DApp development
2017-02-09 14:53:04 +03:00
To make debugging work we run a web server on your device. It runs on port 5561 on both iOS and Android, but only if you need it.
To start a server you need to:
1. Connect your device to computer;
2. In the case you're developing for Android, you need to use a port forwarding.
Execute `adb forward tcp:5561 tcp:5561` ;
3. Open Status application and log in;
4. Open `Console` chat and execute `/debug` command providing "On" as the argument.
You can also easily turn the server off from here.
**Note:** if you turn the server on, it will start automatically the next time you log in.
### Scenario
Imagine you are developing a DApp on your computer. You have a directory where all DApp files are placed,
and there is a server running on your computer. Let's say it is running on port 8080, so you can access
your DApp by typing http://localhost:8080 in your browser.
2017-05-15 23:56:35 +03:00
1. Add a DApp to Status by executing `status-dev-cli add '{"whisper-identity": "dapp-test", "dapp-url": "http://localhost:8080/", "name": "My Dapp"}'` ;
2017-02-09 14:53:04 +03:00
2. Open the "My Dapp" on your device;
2017-02-26 09:26:51 +02:00
3. Optional: Execute `status-dev-cli watch-dapp . '{"whisper-identity": "dapp-test"}'` to start automatically refreshing your DApp in Status browser when you change the DApp's code.