README.md 17.1 KB
Newer Older
N
Nathan Hourt 已提交
1 2
# Eos

peterwillcn's avatar
peterwillcn 已提交
3 4
[![Build Status](https://travis-ci.org/EOSIO/eos.svg?branch=master)](https://travis-ci.org/EOSIO/eos)

5
Welcome to the EOS.IO source code repository!
N
Nathan Hourt 已提交
6

7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
# Table of contents

1. [Getting Started](#gettingstarted)
2. [Setting up a buid/development environment](#setup)
	1. [Clean install Ubuntu](#ubuntu)
	2. [macOS Sierra 10.12.6](#macos)
3. [Building and running a node](#runanode)
	1. [Getting the code](#getcode)
	2. [Building from source code](#build)
	3. [Creating and launching a single-node testnet](#singlenode)
4. [Accounts and smart contracts](#accountssmartcontracts)
	1. [Example smart contracts](#smartcontractexample)
	2. [Setting up a wallet and importing account key](#walletimport)
	3. [Creating accounts for your smart contracts](#createaccounts)
	4. [Upload sample contract to blockchain](#uploadsmartcontract)
	5. [Push a message to a sample contract](#pushamessage)
	6. [Reading Currency Contract Balance](#readingcontract)
5. [Running local testnet](#localtestnet)
6. [Running EOS in Docker](#docker)
	1. [Run contract in docker example](#dockercontract)

## Getting Started <a href="gettingstarted"></a>
29
The following instructions overview the process of getting the software, building it, running a simple test network that produces blocks, account creation and uploading a sample contract to the blockchain.
N
Nathan Hourt 已提交
30

31
## Setting up a build/development environment <a href="setup"></a>
32
This project is written primarily in C++14 and uses CMake as its build system. An up-to-date Clang and the latest version of CMake is recommended.
N
Nathan Hourt 已提交
33

34
Dependencies:
S
Serg Metelin 已提交
35

36
* Clang 4.0.0
37 38
* CMake 3.5.1
* Boost 1.64
S
Serg Metelin 已提交
39
* OpenSSL
40 41
* LLVM 4.0
* [secp256k1-zkp (Cryptonomex branch)](https://github.com/cryptonomex/secp256k1-zkp.git)
S
Serg Metelin 已提交
42
* [binaryen](https://github.com/WebAssembly/binaryen.git)
43

44
### Clean install Ubuntu 16.10 <a href="ubuntu"></a>
45 46 47

Install the development toolkit:

48
```commandline
49
sudo apt-get update
50 51 52
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add -
sudo apt-get install clang-4.0 lldb-4.0 cmake make \
                     libbz2-dev libssl-dev libgmp3-dev \
53
                     autotools-dev build-essential \
54
                     libbz2-dev libicu-dev python-dev \
55 56 57 58 59
                     autoconf libtool git
```

Install Boost 1.64:

60
```commandline
61 62 63 64
cd ~
wget -c 'https://sourceforge.net/projects/boost/files/boost/1.64.0/boost_1_64_0.tar.bz2/download' -O boost_1.64.0.tar.bz2
tar xjf boost_1.64.0.tar.bz2
cd boost_1_64_0/
S
Serg Metelin 已提交
65 66
echo "export BOOST_ROOT=$HOME/opt/boost_1_64_0" >> ~/.bash_profile
source ~/.bash_profile
67 68
./bootstrap.sh "--prefix=$BOOST_ROOT"
./b2 install
S
Serg Metelin 已提交
69
source ~/.bash_profile
70 71
```

72 73 74 75 76 77 78 79 80 81 82 83
Install [secp256k1-zkp (Cryptonomex branch)](https://github.com/cryptonomex/secp256k1-zkp.git):
        
```commandline
cd ~
git clone https://github.com/cryptonomex/secp256k1-zkp.git
cd secp256k1-zkp
./autogen.sh
./configure
make
sudo make install
```

84
To use the WASM compiler, EOS has an external dependency on [binaryen](https://github.com/WebAssembly/binaryen.git):
S
Serg Metelin 已提交
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100

```commandline
cd ~
git clone https://github.com/WebAssembly/binaryen.git
cd ~/binaryen
git checkout tags/1.37.14
cmake . && make

```

Add BINARYEN_ROOT to your .bash_profile:

```commandline
echo "export BINARYEN_ROOT=~/binaryen" >> ~/.bash_profile
source ~/.bash_profile
```
D
Daniel Larimer 已提交
101

S
Serg Metelin 已提交
102
By default LLVM and clang do not include the WASM build target, so you will have to build it yourself:
103

104 105 106 107 108 109 110 111 112 113 114
```commandline
mkdir  ~/wasm-compiler
cd ~/wasm-compiler
git clone --depth 1 --single-branch --branch release_40 https://github.com/llvm-mirror/llvm.git
cd llvm/tools
git clone --depth 1 --single-branch --branch release_40 https://github.com/llvm-mirror/clang.git
cd ..
mkdir build
cd build
cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=.. -DLLVM_TARGETS_TO_BUILD= -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=WebAssembly -DCMAKE_BUILD_TYPE=Release ../
make -j4 install
115
```
116

117
### macOS Sierra 10.12.6 <a href="macos"></a>
118 119

macOS additional Dependencies:
S
Serg Metelin 已提交
120

121 122 123 124 125 126 127
* Brew
* Newest XCode

Upgrade your XCode to the newest version:

```commandline
xcode-select --install
128 129
```

130
Install homebrew:
131 132

```commandline
133 134 135 136 137 138 139 140
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
```

Install the dependencies:

```commandline
brew update
brew install git automake libtool boost openssl llvm
141
```
142

143 144 145 146 147 148 149 150 151 152
Install [secp256k1-zkp (Cryptonomex branch)](https://github.com/cryptonomex/secp256k1-zkp.git):
        
```commandline
cd ~
git clone https://github.com/cryptonomex/secp256k1-zkp.git
cd secp256k1-zkp
./autogen.sh
./configure
make
sudo make install
153
```
154

S
Serg Metelin 已提交
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
Install [binaryen v1.37.14](https://github.com/WebAssembly/binaryen.git):

```commandline
cd ~
git clone https://github.com/WebAssembly/binaryen.git
cd ~/binaryen
git checkout tags/1.37.14
cmake . && make
```

Add BINARYEN_ROOT to your .bash_profile:

```commandline
echo "export BINARYEN_ROOT=~/binaryen" >> ~/.bash_profile
source ~/.bash_profile
```


173 174 175
Build LLVM and clang for WASM:

```commandline
176 177 178 179 180 181 182 183 184 185 186 187
mkdir  ~/wasm-compiler
cd ~/wasm-compiler
git clone --depth 1 --single-branch --branch release_40 https://github.com/llvm-mirror/llvm.git
cd llvm/tools
git clone --depth 1 --single-branch --branch release_40 https://github.com/llvm-mirror/clang.git
cd ..
mkdir build
cd build
cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=.. -DLLVM_TARGETS_TO_BUILD= -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=WebAssembly -DCMAKE_BUILD_TYPE=Release ../
make -j4 install
```

188 189 190 191 192
Add WASM_LLVM_CONFIG and LLVM_DIR to your .bash_profile:

```commandline
echo "export WASM_LLVM_CONFIG=~/wasm-compiler/llvm/bin/llvm-config" >> ~/.bash_profile
echo "export LLVM_DIR=/usr/local/Cellar/llvm/4.0.1/lib/cmake/llvm" >> ~/.bash_profile
S
Serg Metelin 已提交
193
source ~/.bash_profile
194 195
```

196
## Building and running a node <a href="runanode"></a>
S
Serg Metelin 已提交
197

198
### Getting the code <a href="getcode"></a>
S
Serg Metelin 已提交
199

200
To download all of the code, download EOS source code and a recursion or two of submodules. The easiest way to get all of this is to do a recursive clone:
N
Nathan Hourt 已提交
201 202 203 204 205 206 207

`git clone https://github.com/eosio/eos --recursive`

If a repo is cloned without the `--recursive` flag, the submodules can be retrieved after the fact by running this command from within the repo:

`git submodule update --init --recursive`

208
### Building from source code <a href="build"></a>
209

210 211
The *WASM_LLVM_CONFIG* environment variable is used to find our recently built WASM compiler.
This is needed to compile the example contracts inside `eos/contracts` folder and their respective tests.
212

213
```commandline
S
Serg Metelin 已提交
214
cd ~
215
git clone https://github.com/eosio/eos --recursive
S
Serg Metelin 已提交
216 217
mkdir -p ~/eos/build && cd ~/eos/build
cmake -DBINARYEN_BIN=~/binaryen/bin ..
218 219 220 221
make -j4
```

Out-of-source builds are also supported. To override clang's default choice in compiler, add these flags to the CMake command:
N
Nathan Hourt 已提交
222 223 224 225 226

`-DCMAKE_CXX_COMPILER=/path/to/c++ -DCMAKE_C_COMPILER=/path/to/cc`

For a debug build, add `-DCMAKE_BUILD_TYPE=Debug`. Other common build types include `Release` and `RelWithDebInfo`.

227
To run the test suite after building, run the `chain_test` executable in the `tests` folder.
N
Nathan Hourt 已提交
228

S
Serg Metelin 已提交
229 230 231 232 233
EOS comes with a number of programs you can find in `~/eos/build/programs`. They are listed below:

* eosd - server-side blockchain node component
* eosc - command line interface to interact with the blockchain
* eos-walletd - EOS wallet
S
Serg Metelin 已提交
234
* launcher - application for nodes network composing and deployment; [more on launcher](https://github.com/EOSIO/eos/blob/master/testnet.md)
S
Serg Metelin 已提交
235

236
### Creating and launching a single-node testnet <a href="singlenode"></a>
S
Serg Metelin 已提交
237

238
After successfully building the project, the `eosd` binary should be present in the `programs/eosd` directory. Go ahead and run `eosd` -- it will probably exit with an error, but if not, close it immediately with `Ctrl-C`. Note that `eosd` created a directory named `data-dir` containing the default configuration (`config.ini`) and some other internals. This default data storage path can be overridden by passing `--data-dir /path/to/data` to `eosd`.
N
Nathan Hourt 已提交
239

N
Nathan Hourt 已提交
240
Edit the `config.ini` file, adding the following settings to the defaults already in place:
N
Nathan Hourt 已提交
241 242

```
N
Nathan Hourt 已提交
243 244 245 246 247
# Load the testnet genesis state, which creates some initial block producers with the default key
genesis-json = /path/to/eos/source/genesis.json
# Enable production on a stale chain, since a single-node test chain is pretty much always stale
enable-stale-production = true
# Enable block production with the testnet producers
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
producer-name = inita
producer-name = initb
producer-name = initc
producer-name = initd
producer-name = inite
producer-name = initf
producer-name = initg
producer-name = inith
producer-name = initi
producer-name = initj
producer-name = initk
producer-name = initl
producer-name = initm
producer-name = initn
producer-name = inito
producer-name = initp
producer-name = initq
producer-name = initr
producer-name = inits
producer-name = initt
producer-name = initu
S
Serg Metelin 已提交
269
# Load the block producer plugin, so you can produce blocks
N
Nathan Hourt 已提交
270
plugin = eos::producer_plugin
S
Serg Metelin 已提交
271
# Wallet plugin
272
plugin = eos::wallet_api_plugin
S
Serg Metelin 已提交
273
# As well as API and HTTP plugins
274 275
plugin = eos::chain_api_plugin
plugin = eos::http_plugin
N
Nathan Hourt 已提交
276 277
```

J
Joel Smith 已提交
278
Now it should be possible to run `eosd` and see it begin producing blocks. At present, the P2P code is not implemented, so only single-node configurations are possible. When the P2P networking is implemented, these instructions will be updated to show how to create an example multi-node testnet.
peterwillcn's avatar
peterwillcn 已提交
279

S
Serg Metelin 已提交
280 281 282 283 284 285 286 287 288 289 290 291 292 293
When running `eosd` you should get log messages similar to below. It means the blocks are successfully produced.

```
1575001ms thread-0   chain_controller.cpp:235      _push_block          ] initm #1 @2017-09-04T04:26:15  | 0 trx, 0 pending, exectime_ms=0
1575001ms thread-0   producer_plugin.cpp:207       block_production_loo ] initm generated block #1 @ 2017-09-04T04:26:15 with 0 trxs  0 pending
1578001ms thread-0   chain_controller.cpp:235      _push_block          ] initc #2 @2017-09-04T04:26:18  | 0 trx, 0 pending, exectime_ms=0
1578001ms thread-0   producer_plugin.cpp:207       block_production_loo ] initc generated block #2 @ 2017-09-04T04:26:18 with 0 trxs  0 pending
1581001ms thread-0   chain_controller.cpp:235      _push_block          ] initd #3 @2017-09-04T04:26:21  | 0 trx, 0 pending, exectime_ms=0
1581001ms thread-0   producer_plugin.cpp:207       block_production_loo ] initd generated block #3 @ 2017-09-04T04:26:21 with 0 trxs  0 pending
1584000ms thread-0   chain_controller.cpp:235      _push_block          ] inite #4 @2017-09-04T04:26:24  | 0 trx, 0 pending, exectime_ms=0
1584000ms thread-0   producer_plugin.cpp:207       block_production_loo ] inite generated block #4 @ 2017-09-04T04:26:24 with 0 trxs  0 pending
1587000ms thread-0   chain_controller.cpp:235      _push_block          ] initf #5 @2017-09-04T04:26:27  | 0 trx, 0 pending, exectime_ms=0
```

294
## Accounts and smart contracts <a href="accountssmartcontracts"></a>
S
Serg Metelin 已提交
295

296
EOS comes with example contracts that can be uploaded and run for testing purposes. To upload and test them, follow the steps below.
S
Serg Metelin 已提交
297

298
### Example smart contracts <a href="smartcontractexample"></a>
299 300 301

To publish sample smart contracts you need to create accounts for them.

S
Serg Metelin 已提交
302 303 304 305
Run the node:

```commandline
cd ~/eos/build/programs/eosd/
S
Serg Metelin 已提交
306
./eosd
S
Serg Metelin 已提交
307
```
308

309
### Setting up a wallet and importing account key <a href="walletimport"></a>
S
Serg Metelin 已提交
310

311
Before running API commands you need to import the private key of an account you will be authorizing the transactions under into the EOS wallet.
S
Serg Metelin 已提交
312

313
As you've previously added `plugin = eos::wallet_api_plugin` into `config.ini`, EOS wallet will be running as a part of `eosd` process.
S
Serg Metelin 已提交
314

315
For testing purposes you can use a pre-created account `inita` from the `genesis.json` file.
S
Serg Metelin 已提交
316 317 318 319 320

To login you need to run a command importing an active (not owner!) private key from `inita` account (you can find it in `~/eos/build/programs/eosd/data-dir/config.ini`) to the wallet.

```commandline
cd ~/eos/build/programs/eosc/
321 322
./eosc wallet create # Outputs a password that you need to save to be able to lock/unlock the wallet
./eosc wallet import 5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3
S
Serg Metelin 已提交
323 324
```

325
Now you can issue API commands under `inita` authority.
S
Serg Metelin 已提交
326

327
### Creating accounts for your smart contracts <a href="createaccounts"></a>
S
Serg Metelin 已提交
328

329
First, generate public/private key pairs for the `owner_key` and `active_key`. You will need them to create an account:
330 331 332 333 334 335 336 337 338 339 340 341 342 343

```commandline
cd ~/eos/build/programs/eosc/
./eosc create key
./eosc create key
```

You will get two pairs of a public and private key:

```
Private key: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Public key:  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
```

344
**Warning:**
345
Save the values for future reference.
346
{: .warning}
347 348 349 350

Run `create` command where `PUBLIC_KEY_1` and `PUBLIC_KEY_2` are the values generated by the `create key` command:

```commandline
351
./eosc create account inita currency PUBLIC_KEY_1 PUBLIC_KEY_2 
352 353 354 355
```

You should get a json response back with a transaction ID confirming it was executed successfully.

356 357 358
Check that account was successfully created: 

```commandline
S
Serg Metelin 已提交
359
./eosc get account currency
360 361 362 363 364 365
```

You should get a response similar to this:

```json
{
S
Serg Metelin 已提交
366
  "name": "currency",
367 368 369 370 371 372 373
  "eos_balance": 0,
  "staked_balance": 1,
  "unstaking_balance": 0,
  "last_unstaking_time": "2106-02-07T06:28:15"
}
```

374
### Upload sample contract to blockchain <a href="uploadsmartcontract"></a>
375

376
Before uploading a contract, you can verify that there is no current contract:
D
Daniel Larimer 已提交
377 378 379 380 381 382

```commandline
./eosc get code currency 
code hash: 0000000000000000000000000000000000000000000000000000000000000000
```

383
With an account for a contract created, you can upload a sample contract:
384 385

```commandline
386
./eosc set contract currency ../../contracts/currency/currency.wast ../../contracts/currency/currency.abi
S
Serg Metelin 已提交
387 388 389 390
```

As a response you should get a json with a `transaction_id` field. Your contract was successfully uploaded!

391
You can also verify that the code has been set:
D
Daniel Larimer 已提交
392 393 394 395 396 397

```commandline
./eosc get code currency
code hash: 9b9db1a7940503a88535517049e64467a6e8f4e9e03af15e9968ec89dd794975
```

398
Next you can verify that the currency contract has the proper initial balance:
D
Daniel Larimer 已提交
399 400 401 402 403 404 405 406 407 408 409 410 411

```commandline
./eosc get table currency currency account
{
  "rows": [{
     "account": "account",
     "balance": 1000000000
     }
  ],
  "more": false
}
```

412
### Push a message to a sample contract <a href="pushamessage"></a>
S
Serg Metelin 已提交
413

414
To send a message to a contract you need to create a new user account who will be sending the message.
S
Serg Metelin 已提交
415 416 417 418 419 420 421

Firstly, generate the keys for the account:

```commandline
cd ~/eos/build/programs/eosc/
./eosc create key
./eosc create key
422 423
```

S
Serg Metelin 已提交
424 425 426
And then create the `tester` account:

```commandline
427
./eosc create account inita tester PUBLIC_USER_KEY_1 PUBLIC_USER_KEY_2 
S
Serg Metelin 已提交
428 429
```

430
After this you can send a message to the contract:
S
Serg Metelin 已提交
431 432

```commandline
433
./eosc push message currency transfer '{"from":"currency","to":"inita","amount":50}' --scope currency,inita --permission currency@active
D
Daniel Larimer 已提交
434 435 436 437
```

As a confirmation of a successfully submitted transaction you will get a json with a `transaction_id` field.

438
### Reading Currency Contract Balance <a href="readingcontract"></a>
D
Daniel Larimer 已提交
439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458

```commandline
./eosc get table inita currency account
{
  "rows": [{
      "account": "account",
      "balance": 50 
       }
    ],
  "more": false
}
./eosc get table currency currency account
{
  "rows": [{
      "account": "account",
      "balance": 999999950
    }
  ],
  "more": false
}
S
Serg Metelin 已提交
459 460
```

461
## Running local testnet <a href="localtestnet"></a>
S
Serg Metelin 已提交
462

S
Serg Metelin 已提交
463
To run a local testnet you can use a `launcher` application provided in `~/eos/build/programs/launcher` folder.
S
Serg Metelin 已提交
464

S
Serg Metelin 已提交
465
For testing purposes you will run 2 local production nodes talking to each other.
S
Serg Metelin 已提交
466 467 468 469

```commandline
cd ~/eos/build
cp ../genesis.json ./
470
./programs/launcher/launcher -p2 -s testnet.json --skip-signature -l local
S
Serg Metelin 已提交
471 472
```

S
Serg Metelin 已提交
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491
This command will generate 2 data folder for each instance of the node: `tn_data_0` and `tn_data_1`, as well as `testnet.json` file for the testnet configuration.

You should see a following response:

```commandline
adding hostname ip-XXX-XXX-XXX
found interface 127.0.0.1
found interface XXX.XX.XX.XX
spawning child, programs/eosd/eosd --skip-transaction-signatures --data-dir tn_data_0
spawning child, programs/eosd/eosd --skip-transaction-signatures --data-dir tn_data_1
```

To confirm the nodes are running, run following `eosc` commands:
```commandline
~/eos/build/programs/eosc
./eosc -p 8888 get info
./eosc -p 8889 get info
```

S
Serg Metelin 已提交
492
For each you should get a json with a blockchain information.
S
Serg Metelin 已提交
493

S
Serg Metelin 已提交
494 495
You can read more on launcher and its settings [here](https://github.com/EOSIO/eos/blob/master/testnet.md)

496
## Running EOS in Docker <a href="docker"></a>
peterwillcn's avatar
peterwillcn 已提交
497

498
Simple and fast setup of EOS in Docker is also available. Firstly, install dependencies:
499

peterwillcn's avatar
peterwillcn 已提交
500 501 502 503
 - [Docker](https://docs.docker.com)
 - [Docker-compose](https://github.com/docker/compose)
 - [Docker-volumes](https://github.com/cpuguy83/docker-volumes)

504
Build EOS image
peterwillcn's avatar
peterwillcn 已提交
505

S
Serg Metelin 已提交
506 507 508 509 510
```
git clone https://github.com/EOSIO/eos.git --recursive
cd eos
cp genesis.json Docker 
docker build -t eosio/eos -f Docker/Dockerfile .
peterwillcn's avatar
peterwillcn 已提交
511 512
```

S
Serg Metelin 已提交
513 514
We recommend 6GB+ of memory allocated to Docker to successfully build the image.

S
Serg Metelin 已提交
515
Now you can start the Docker container:
peterwillcn's avatar
peterwillcn 已提交
516

S
Serg Metelin 已提交
517
```
peterwillcn's avatar
peterwillcn 已提交
518
sudo rm -rf /data/store/eos # options 
peterwillcn's avatar
peterwillcn 已提交
519
sudo mkdir -p /data/store/eos
S
Serg Metelin 已提交
520
docker-compose -f Docker/docker-compose.yml up
peterwillcn's avatar
peterwillcn 已提交
521 522
```

523
Get chain info:
524 525 526 527 528

```
curl http://127.0.0.1:8888/v1/chain/get_info
```

529
### Run contract in docker example <a href="dockercontract"></a>
S
Serg Metelin 已提交
530

531
You can run the `eosc` commands via `docker exec` command. For example:
S
Serg Metelin 已提交
532

S
Serg Metelin 已提交
533
```
534
docker exec docker_eos_1 eosc contract exchange build/contracts/exchange/exchange.wast build/contracts/exchange/exchange.abi
S
Serg Metelin 已提交
535
```