<commit_before>Bytom
=====
[![Build Status](https://travis-ci.org/Bytom/bytom.svg)](https://travis-ci.org/Bytom/bytom)
[![AGPL v3](https://img.shields.io/badge/license-AGPL%20v3-brightgreen.svg)](./LICENSE)

## Table of Contents
<!-- vim-markdown-toc GFM -->

* [What is Bytom?](#what-is-bytom)
* [Build from source](#build-from-source)
  * [Requirements](#requirements)
  * [Installation](#installation)
    * [Get the source code](#get-the-source-code)
    * [Build](#build)
* [Example](#example)
  * [Create and launch a single node](#create-and-launch-a-single-node)
    * [Create an account](#create-an-account)
    * [Create an asset](#create-an-asset)
    * [Issue an asset](#issue-an-asset)
    * [Transfer an asset](#transfer-an-asset)
    * [Transfer btm](#transfer-btm)
  * [Set up a wallet and manage the key](#set-up-a-wallet-and-manage-the-key)
  * [Multiple node](#multiple-node)
* [Running Bytom in Docker](#running-bytom-in-docker)
* [Contributing](#contributing)
* [License](#license)

<!-- vim-markdown-toc -->

## What is Bytom?

Bytom is software designed to operate and connect to highly scalable blockchain networks confirming to the Bytom Blockchain Protocol, which allows partipicants to define, issue and transfer digitial assets on a multi-asset shared ledger. Please refer to the [White Paper](https://github.com/Bytom/wiki/blob/master/White-Paper/%E6%AF%94%E5%8E%9F%E9%93%BE%E6%8A%80%E6%9C%AF%E7%99%BD%E7%9A%AE%E4%B9%A6-%E8%8B%B1%E6%96%87%E7%89%88.md) for more details.

In the current state `bytom` is able to:

- Issue assets
- Manage account as well as asset
- Spend assets

## Build from source

### Requirements

- [Go](https://golang.org/doc/install) version 1.8 or higher, with `$GOPATH` set to your preferred directory

### Installation

Ensure Go with the supported version is installed properly:

```bash
$ go version
$ go env GOROOT GOPATH
```

#### Get the source code

``` bash
$ git clone https://github.com/Bytom/bytom $GOPATH/src/github.com/bytom
```

#### Build

``` bash
$ cd $GOPATH/src/github.com/bytom
$ make bytomd    # build bytomd
$ make bytomcli  # build bytomcli
```

## Example

Currently, bytom is still in active development and a ton of work needs to be done, but we also provide the following content for these eager to do something with `bytom`.

### Create and launch a single node

When successfully building the project, the `bytom` and `bytomcli` binary should be present in `cmd/bytomd` and `cmd/bytomcli` directory, respectively. The next step is to initialize the node:

```bash
$ cd ./cmd/bytomd
$ ./bytomd init --chain_id testnet
```

After that, you'll see `.bytom` generated in current directory, then launch the single node:

``` bash
$ ./bytomd node --wallet.enable
```

Given the `bytom` node is running, the general workflow is as follows:

- create an account
- create an asset
- create/sign/submit a transaction to transfer an asset
- query the assets on-chain


#### Create an account

Create an account named `alice`:

```bash
$ ./bytomcli create-account alice
xprv:<alice_account_private_key>
responses:<create-account-responses>
account id:<alice_account_id>
```

Check out the new created account:

```bash
$ ./bytomcli list-accounts
```

#### Create an asset

Create an asset named `gold`:

```bash
$ ./bytomcli create-asset gold
xprv:<gold_asset_private_key>
xpub:<gold_asset_public_key>
responses:<create-asset-responses>
asset id:<gold_asset_id>
```

Check out the new created asset:

```bash
$ ./bytomcli list-assets
```

#### Issue an asset

Since the account alice and the asset `gold` are ready, issue `gold` to alice:

```bash
$ ./bytomcli create-account bob
```

Firstly, Alice issue `<issue_amount>`, e.g., 10000, `gold`:

```bash
$ ./bytomcli sub-create-issue-tx <alice_account_id> <gold_asset_id> <issue_amount> <gold_asset_private_key> <account_private_key>
```

When the transaction is on-chain, query the balances:

```bash
# Alice should have 10000 gold now
$ ./bytomcli list-balances
```

#### Transfer an asset

Alice pays Bob `<payment_amount>`, e.g., 1000, `gold`:
- Bob creates receiver program
```bash
$./bytomcli create-account-receiver bob 
```
- off-chain transfers receiver program to alice
- Alice builds transaction and then makes this transacion on-chain
```bash
$./bytomcli sub-control-receiver-tx <account_xprv> <account_id> <asset_id> <spend_amount> <control_program>
```
- list balance
```bash
$./bytomcli list-balances
```

#### Transfer btm
As above, just `btm_asset_id`=ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
```bash
$./bytomcli sub-control-receiver-tx <account_xprv> <account_id> <btm_asset_id> <spend_amount> <control_program>
```
### Set up a wallet and manage the key

If you have started a bytom node, then you can create an account via `create-key password`, which will generate a `keystore` directory containing the keys under the project directory.

```bash
$ ./bytomcli create-key account_name password   # Create an account named account_name using password<commit_msg>Update README.md (#157)<commit_after>Bytom
=====
[![Build Status](https://travis-ci.org/Bytom/bytom.svg)](https://travis-ci.org/Bytom/bytom)
[![AGPL v3](https://img.shields.io/badge/license-AGPL%20v3-brightgreen.svg)](./LICENSE)

## Table of Contents
<!-- vim-markdown-toc GFM -->

* [What is Bytom?](#what-is-bytom)
* [Build from source](#build-from-source)
  * [Requirements](#requirements)
  * [Installation](#installation)
    * [Get the source code](#get-the-source-code)
    * [Build](#build)
* [Example](#example)
  * [Create and launch a single node](#create-and-launch-a-single-node)
    * [Create an account](#create-an-account)
    * [Create an asset](#create-an-asset)
    * [Issue an asset](#issue-an-asset)
    * [Transfer an asset](#transfer-an-asset)
    * [Transfer btm](#transfer-btm)
  * [Set up a wallet and manage the key](#set-up-a-wallet-and-manage-the-key)
  * [Multiple node](#multiple-node)
* [Running Bytom in Docker](#running-bytom-in-docker)
* [Contributing](#contributing)
* [License](#license)

<!-- vim-markdown-toc -->

## What is Bytom?

Bytom is software designed to operate and connect to highly scalable blockchain networks confirming to the Bytom Blockchain Protocol, which allows partipicants to define, issue and transfer digitial assets on a multi-asset shared ledger. Please refer to the [White Paper](https://github.com/Bytom/wiki/blob/master/White-Paper/%E6%AF%94%E5%8E%9F%E9%93%BE%E6%8A%80%E6%9C%AF%E7%99%BD%E7%9A%AE%E4%B9%A6-%E8%8B%B1%E6%96%87%E7%89%88.md) for more details.

In the current state `bytom` is able to:

- Issue assets
- Manage account as well as asset
- Spend assets

## Build from source

### Requirements

- [Go](https://golang.org/doc/install) version 1.8 or higher, with `$GOPATH` set to your preferred directory

### Installation

Ensure Go with the supported version is installed properly:

```bash
$ go version
$ go env GOROOT GOPATH
```

#### Get the source code

``` bash
$ git clone https://github.com/Bytom/bytom $GOPATH/src/github.com/bytom
```

#### Build

``` bash
$ cd $GOPATH/src/github.com/bytom
$ make bytomd    # build bytomd
$ make bytomcli  # build bytomcli
```

## Example

Currently, bytom is still in active development and a ton of work needs to be done, but we also provide the following content for these eager to do something with `bytom`.

### Create and launch a single node

When successfully building the project, the `bytom` and `bytomcli` binary should be present in `cmd/bytomd` and `cmd/bytomcli` directory, respectively. The next step is to initialize the node:

```bash
$ cd ./cmd/bytomd
$ ./bytomd init --chain_id testnet
```

After that, you'll see `.bytom` generated in current directory, then launch the single node:

``` bash
$ ./bytomd node --wallet.enable
```

Given the `bytom` node is running, the general workflow is as follows:

- create an account
- create an asset
- create/sign/submit a transaction to transfer an asset
- query the assets on-chain


#### Create an account

Create an account named `alice`:

```bash
$ ./bytomcli create-account alice
xprv:<alice_account_private_key>
responses:<create-account-responses>
account id:<alice_account_id>
```

Check out the new created account:

```bash
$ ./bytomcli list-accounts
```

#### Create an asset

Create an asset named `gold`:

```bash
$ ./bytomcli create-asset gold
xprv:<gold_asset_private_key>
xpub:<gold_asset_public_key>
responses:<create-asset-responses>
asset id:<gold_asset_id>
```

Check out the new created asset:

```bash
$ ./bytomcli list-assets
```

#### Issue an asset

Since the account alice and the asset `gold` are ready, issue `gold` to alice:

```bash
$ ./bytomcli create-account bob
```

Firstly, Alice issue `<issue_amount>`, e.g., 10000, `gold`:

```bash
$ ./bytomcli sub-create-issue-tx <alice_account_id> <gold_asset_id> <issue_amount> <gold_asset_private_key> <account_private_key>
```

When the transaction is on-chain, query the balances:

```bash
# Alice should have 10000 gold now
$ ./bytomcli list-balances
```

#### Transfer an asset

Alice pays Bob `<payment_amount>`, e.g., 1000, `gold`:
- Bob creates receiver program
```bash
$./bytomcli create-account-receiver bob
```
responses like this:
```
responses:map[control_program:766baa207b73a71a9e8a77ace69bdd5d68fdfacc841bfdd5d6e0057a331846c24ac222e35151ad696c00c0 expires_at:2017-12-30T17:10:01.915062361+08:00]
```
- off-chain transfers receiver program to alice
- Alice builds transaction and then makes this transacion on-chain
```bash
$./bytomcli sub-control-receiver-tx <account_xprv> <account_id> <asset_id> <spend_amount> <control_program>
```
- list balance
```bash
$./bytomcli list-balances
```

#### Transfer btm
As above, just `btm_asset_id`=ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
```bash
$./bytomcli sub-control-receiver-tx <account_xprv> <account_id> <btm_asset_id> <spend_amount> <control_program>
```
### Set up a wallet and manage the key

If you have started a bytom node, then you can create an account via `create-key password`, which will generate a `keystore` directory containing the keys under the project directory.

```bash
$ ./bytomcli create-key account_name password   # Create an account named account_name using password
{'fraction_non_alphanumeric': 0.13625280405734908, 'fraction_numerical': 0.018726226470301376, 'mean_word_length': 4.757439640651319, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 55, 'https://': 12, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3967314', 'n_tokens_mistral': 3692, 'n_tokens_neox': 3403, 'n_words': 1028}