cosmos-sdk/docs/guide/basecoin-tool.md

154 lines
4.3 KiB
Markdown
Raw Normal View History

2017-03-13 17:20:07 -07:00
# The Basecoin Tool
In previous tutorials we learned the [basics of the `basecoin` CLI](/docs/guides/basecoin-basics)
and [how to implement a plugin](/docs/guides/example-plugin).
In this tutorial, we provide more details on using the `basecoin` tool.
2017-03-14 11:29:12 -07:00
# Data Directory
By default, `basecoin` works out of `~/.basecoin`. To change this, set the `BCHOME` environment variable:
```
export BCHOME=~/.my_basecoin_data
basecoin init
basecoin start
```
or
```
BCHOME=~/.my_basecoin_data basecoin init
BCHOME=~/.my_basecoin_data basecoin start
```
2017-03-13 17:20:07 -07:00
# ABCI Server
So far we have run Basecoin and Tendermint in a single process.
However, since we use ABCI, we can actually run them in different processes.
2017-03-14 11:29:12 -07:00
First, initialize them:
2017-03-13 17:20:07 -07:00
```
basecoin init
```
2017-03-14 11:29:12 -07:00
This will create a single `genesis.json` file in `~/.basecoin` with the information for both Basecoin and Tendermint.
Now, In one window, run
2017-03-13 17:20:07 -07:00
```
2017-03-13 22:47:10 -07:00
basecoin start --without-tendermint
2017-03-13 17:20:07 -07:00
```
and in another,
```
2017-03-14 11:29:12 -07:00
TMROOT=~/.basecoin tendermint node
2017-03-13 17:20:07 -07:00
```
You should see Tendermint start making blocks!
2017-03-14 11:29:12 -07:00
Alternatively, you could ignore the Tendermint details in `~/.basecoin/genesis.json` and use a separate directory by running:
```
tendermint init
tendermint node
```
For more details on using `tendermint`, see [the guide](https://tendermint.com/docs/guides/using-tendermint).
2017-03-13 17:20:07 -07:00
# Keys and Genesis
In previous tutorials we used `basecoin init` to initialize `~/.basecoin` with the default configuration.
2017-03-14 11:29:12 -07:00
This command creates files both for Tendermint and for Basecoin, and a single `genesis.json` file for both of them.
2017-03-13 17:20:07 -07:00
For more information on these files, see the [guide to using tendermint](https://tendermint.com/docs/guides/using-tendermint).
Now let's make our own custom Basecoin data.
First, create a new directory:
```
mkdir example-data
```
2017-03-13 22:50:10 -07:00
We can tell `basecoin` to use this directory by exporting the `BCHOME` environment variable:
2017-03-13 17:20:07 -07:00
```
2017-03-13 22:50:10 -07:00
export BCHOME=$(pwd)/example-data
2017-03-13 17:20:07 -07:00
```
If you're going to be using multiple terminal windows, make sure to add this variable to your shell startup scripts (eg. `~/.bashrc`).
Now, let's create a new private key:
```
2017-03-13 22:50:10 -07:00
basecoin key new > $BCHOME/key.json
2017-03-13 17:20:07 -07:00
```
2017-03-14 14:28:49 -07:00
Here's what my `key.json looks like:
2017-03-13 17:20:07 -07:00
```json
{
2017-03-14 11:29:12 -07:00
"address": "4EGEhnqOw/gX326c7KARUkY1kic=",
"pub_key": {
"type": "ed25519",
"data": "a20d48b5caff42892d0ac67ccdeee38c1dcbbe42b15b486057d16244541e8141"
},
"priv_key": {
"type": "ed25519",
"data": "654c845f4b36d1a881deb0ff09381165d3ccd156b4aabb5b51267e91f1d024a5a20d48b5caff42892d0ac67ccdeee38c1dcbbe42b15b486057d16244541e8141"
}
2017-03-13 17:20:07 -07:00
}
```
Yours will look different - each key is randomly derrived.
Now we can make a `genesis.json` file and add an account with our public key:
```json
2017-03-14 11:29:12 -07:00
{
"chain_id": "example-chain",
"app_options": {
"accounts": [{
"pub_key": {
"type": "ed25519",
"data": "a20d48b5caff42892d0ac67ccdeee38c1dcbbe42b15b486057d16244541e8141"
},
"coins": [
{
"denom": "gold",
"amount": 1000000000
}
]
}]
2017-03-13 17:20:07 -07:00
}
2017-03-14 11:29:12 -07:00
}
2017-03-13 17:20:07 -07:00
```
Here we've granted ourselves `1000000000` units of the `gold` token.
2017-03-14 11:29:12 -07:00
Note that we've also set the `chain_id` to be `example-chain`.
2017-03-13 17:20:07 -07:00
All transactions must therefore include the `--chain_id example-chain` in order to make sure they are valid for this chain.
Previously, we didn't need this flag because we were using the default chain ID ("test_chain_id").
Now that we're using a custom chain, we need to specify the chain explicitly on the command line.
2017-03-14 11:29:12 -07:00
Note we have also left out the details of the tendermint genesis. These are documented in the [tendermint guide](https://tendermint.com/docs/guides/using-tendermint).
2017-03-13 17:20:07 -07:00
# Reset
You can reset all blockchain data by running:
```
basecoin unsafe_reset_all
```
2017-04-26 21:51:44 -07:00
# Genesis
Any required plugin initialization should be constructed using `SetOption` on genesis.
When starting a new chain for the first time, `SetOption` will be called for each item the genesis file.
Within genesis.json file entries are made in the format: `"<plugin>/<key>", "<value>"`, where `<plugin>` is the plugin name,
and `<key>` and `<value>` are the strings passed into the plugin SetOption function.
This function is intended to be used to set plugin specific information such
as the plugin state.