-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update all examples - major overhaul #87
Changes from 2 commits
2812b28
f894376
f41e8a8
fb2e020
8e0c95b
3727fad
d8edac8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,12 +3,12 @@ | |
## Default Listeners | ||
```shell--visible | ||
# With curl you just send HTTP Requests based on further docs | ||
# Only thing to have in mind is Authentication, which is described in Auth section. | ||
# Only thing to keep in mind is authentication, which is described in the "Authentication" section. | ||
|
||
curl http://127.0.0.1:18332/ # will get info from testnet | ||
curl http://127.0.0.1:48332/ # will get info from regtest | ||
``` | ||
|
||
By default API listens on these addresses: | ||
By default the API server listens on these `localhost` ports: | ||
|
||
Network | API Port | ||
--------- | ----------- | ||
|
@@ -17,94 +17,99 @@ testnet | 18332 | |
regtest | 48332 | ||
simnet | 18556 | ||
|
||
You can interact with bcoin with REST Api as well as RPC, | ||
there are couple of ways you can use API. | ||
You can interact with bcoin with its REST API as well as with RPC. | ||
There are couple of ways you can use the API: | ||
|
||
- `bcoin-cli` - has almost all methods described to be used. | ||
- `javascript` - Clients used by `bcoin-cli` can be used directly from javascript | ||
- `curl` - or you can use direct HTTP calls for invoking REST/RPC API calls. | ||
- `bcoin-cli` - methods built specifically into bcoin by its developers | ||
- `bcoin-cli rpc` - adds functionality that mimics Bitcoin Core RPC | ||
- `javascript` - methods used by `bcoin-cli` can be accessed directly from javascript | ||
- `curl` - you can use direct HTTP calls for invoking both REST and RPC API calls | ||
|
||
## Configuring BCOIN CLI | ||
## Configuring bcoin-cli | ||
|
||
```shell--visible | ||
# You can use config file | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should still be possible to use a conf file and will be looked for by bclient. We should also include some information about how the wallet will look for a separate conf file (this should be documented in the changelog) |
||
bcoin-cli --config /full/path/to/bcoin.conf | ||
|
||
# Or with prefix (which will later load bcoin.conf file from the directory) | ||
bcoin-cli --prefix /full/path/to/bcoin/dir | ||
|
||
# You can configure it by passing arguments: | ||
bcoin-cli --network=regtest info | ||
bcoin-cli info --network=regtest | ||
|
||
# Or use ENV variables (Starting with BCOIN_) | ||
# Or use environment variables (Starting with BCOIN_) | ||
export BCOIN_NETWORK=regtest | ||
export BCOIN_API_KEY=yoursecret | ||
export BCOIN_API_KEY=api-key | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe preface with a |
||
bcoin-cli info | ||
``` | ||
|
||
Install `bcoin-cli` and `bwallet-cli` command line tools with the `bclient` package. | ||
Included with `bcoin` by default, but can be installed separately: | ||
`npm install bclient` | ||
`npm install -g bclient` | ||
|
||
`bcoin-cli` params: | ||
|
||
### General configurations are: | ||
|
||
Config | Options | Description | ||
--------- | ----------- | ----------- | ||
prefix | dir path | This accepts directory where DBs and `bcoin.conf` are located. | ||
network | `main`, `testnet`, `regtest` | This will configure which network to load, also where to look for config file | ||
network | `main`, `testnet`, `regtest` | This will configure which network to load, also where to look for `bcoin.conf` file | ||
uri, url | Base HTTP URI | This can be used for custom port | ||
api-key | secret | Secret used by RPC for auth. | ||
api-key | _string_ | Secret used by RPC for authorization | ||
|
||
### Wallet Specific | ||
|
||
Config | Options | Description | ||
--------- | ----------- | ----------- | ||
id | primary, custom | specify which account to use by default | ||
token | token str | Token specific wallet | ||
id | _string_ | specify which account to use by default | ||
token | _string_ | Token specific wallet | ||
|
||
|
||
```shell--visible | ||
# Example bcoin.conf syntax: | ||
network: main | ||
prefix: ~/.bcoin | ||
api-key: bikeshed | ||
``` | ||
|
||
### bcoin.conf file | ||
|
||
[A sample bcoin.conf file is included in the code repository](https://github.com/bcoin-org/bcoin/blob/master/etc/sample.conf) | ||
|
||
|
||
|
||
|
||
<aside class="notice"> | ||
Some commands might accept additional parameters. | ||
</aside> | ||
|
||
## Using Javascript Client | ||
## Using Javascript Clients | ||
|
||
```javascript--visible | ||
const bcoin = require('bcoin'); | ||
const Client = bcoin.http.Client; | ||
const Wallet = bcoin.http.Wallet; | ||
|
||
const client = new Client({ | ||
network: 'testnet', | ||
uri: 'http://localhost:18332' | ||
}); | ||
|
||
const wallet = new Wallet({ | ||
network: 'testnet', | ||
uri: 'http://localhost:18332', | ||
id: 'primary' | ||
}); | ||
const {NodeClient, WalletClient} = require('bclient'); | ||
const {Network} = require('bcoin'); | ||
const network = Network.get('regtest'); | ||
|
||
const clientOptions = { | ||
network: network.type, | ||
port: network.rpcPort, | ||
apiKey: 'api-key' | ||
} | ||
|
||
const walletOptions = { | ||
network: network.type, | ||
port: network.walletPort, | ||
apiKey: 'api-key' | ||
} | ||
|
||
const client = new NodeClient(clientOptions); | ||
const wallet = new WalletClient(walletOptions); | ||
``` | ||
|
||
You can also use api with Javascript Library (used by `bcoin-cli`). | ||
There are two objects: `bcoin.http.Client` for general API and `bcoin.http.Wallet` for wallet API. | ||
You can also use the API with a Javascript library (used by `bcoin-cli`). | ||
There are two objects: `NodeClient` for general API and `WalletClient` for wallet API. | ||
`bcoin` also provides an object `Network` and its method `get` which will return the appropriate configuration paramaters for a specified network. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "default configuration" might be better than "appropriate" since you can actually use different ports for example than what is set by default. |
||
|
||
`bcoin.http.Client` options: | ||
`NodeClient` and `WalletClient` options: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch! You're really digging deep :) |
||
|
||
Config | Type | Description | ||
--------- | ----------- | ----------- | ||
network | `main`, `testnet`, `regtest` | Network to use (doesn't lookup configs by itself) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Type should still be string as this is indicating primitive type that it's expecting. Then in the description you can something like "should be one of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
uri | String | URI of the service | ||
apiKey | String | api secret | ||
|
||
`bcoin.http.Wallet` options: | ||
port | _int_ | bcoin socket port (specific for each network) | ||
apiKey | _string_ | API secret | ||
|
||
Config | Type | Description | ||
--------- | ----------- | ----------- | ||
network | `main`, `testnet`, `regtest` | Network to use (doesn't lookup configs by itself) | ||
uri | String | URI of the service | ||
apiKey | String | api secret | ||
id | primary, custom | specify which account to use by default | ||
token | token str | Token specific wallet |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we add a link to the Authentication section?