README.md 10.3 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

## Getting Started
8
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 已提交
9

10 11
## Setting up a build/development environment
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 已提交
12

13
Dependencies:
S
Serg Metelin 已提交
14

15
* Clang 4.0.0
16 17
* CMake 3.5.1
* Boost 1.64
S
Serg Metelin 已提交
18
* OpenSSL
19 20
* LLVM 4.0
* [secp256k1-zkp (Cryptonomex branch)](https://github.com/cryptonomex/secp256k1-zkp.git)
S
Serg Metelin 已提交
21
* [binaryen](https://github.com/WebAssembly/binaryen.git)
22

23
### Clean install Ubuntu 16.10
24 25 26

Install the development toolkit:

27
```commandline
28
sudo apt-get update
29 30 31
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 \
32
                     autotools-dev build-essential \
33
                     libbz2-dev libicu-dev python-dev \
34 35 36 37 38
                     autoconf libtool git
```

Install Boost 1.64:

39
```commandline
40 41 42 43 44 45
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/
./bootstrap.sh "--prefix=$BOOST_ROOT"
./b2 install
S
Serg Metelin 已提交
46 47
echo "export BOOST_ROOT=$HOME/opt/boost_1_64_0" >> ~/.bash_profile
source ~/.bash_profile
48 49
```

50 51 52 53 54 55 56 57 58 59 60 61
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
```

S
Serg Metelin 已提交
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
Also, to use the WASM compiler, eos has an external dependency on [binaryen](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
```
D
Daniel Larimer 已提交
79

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

82 83 84 85 86 87 88 89 90 91 92
```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
93
```
94

95
### macOS Sierra 10.12.6
96 97

macOS additional Dependencies:
S
Serg Metelin 已提交
98

99 100 101 102 103 104 105
* Brew
* Newest XCode

Upgrade your XCode to the newest version:

```commandline
xcode-select --install
106 107
```

108
Install homebrew:
109 110

```commandline
111 112 113 114 115 116 117 118
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
119
```
120

121 122 123 124 125 126 127 128 129 130
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
131
```
132

S
Serg Metelin 已提交
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
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
```


151 152 153
Build LLVM and clang for WASM:

```commandline
154 155 156 157 158 159 160 161 162 163 164 165
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
```

166 167 168 169 170
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 已提交
171
source ~/.bash_profile
172 173
```

S
Serg Metelin 已提交
174 175
## Building and running a node

N
Nathan Hourt 已提交
176 177 178 179 180 181 182 183 184
### Getting the code
To download all of the code, download Eos and a recursion or two of submodules. The easiest way to get all of this is to do a recursive clone:

`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`

185 186 187 188 189
### Using the WASM compiler to perform a full build of the project

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.

190
```commandline
S
Serg Metelin 已提交
191
cd ~
192
git clone https://github.com/eosio/eos --recursive
S
Serg Metelin 已提交
193 194
mkdir -p ~/eos/build && cd ~/eos/build
cmake -DBINARYEN_BIN=~/binaryen/bin ..
195 196 197 198
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 已提交
199 200 201 202 203

`-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`.

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

N
Nathan Hourt 已提交
206
### Creating and launching a single-node testnet
N
Nathan Hourt 已提交
207 208
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` will have 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 已提交
209
Edit the `config.ini` file, adding the following settings to the defaults already in place:
N
Nathan Hourt 已提交
210 211

```
N
Nathan Hourt 已提交
212 213 214 215 216
# 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
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
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
N
Nathan Hourt 已提交
238 239
# Load the block producer plugin, so we can produce blocks
plugin = eos::producer_plugin
240 241 242
# As well as API and HTTP plugins
plugin = eos::chain_api_plugin
plugin = eos::http_plugin
N
Nathan Hourt 已提交
243 244
```

J
Joel Smith 已提交
245
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 已提交
246

S
Serg Metelin 已提交
247 248 249 250
## Accounts and smart contracts

EOS comes with example contracts that can be uploaded and run. To upload and test them, please follow the steps below.

251 252 253 254
### Create accounts for your smart contracts

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

S
Serg Metelin 已提交
255 256 257 258 259 260 261 262
At the moment for the testing purposes you need to run `eosd` with `--skip-transaction-signatures` flag to successfully create accounts and run transactions.

Run the node:

```commandline
cd ~/eos/build/programs/eosd/
./eosd --skip-transaction-signatures
```
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288

First, generate public/private key pairs for the `owner_key` and `active_key`. We will need them to create an account:

```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
```

Save the values for future reference.

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

```commandline
./eosc create account inita exchange PUBLIC_KEY_1 PUBLIC_KEY_2 
```

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

289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
Check that account was successfully created: 

```commandline
./eosc get account exchange
```

You should get a response similar to this:

```json
{
  "name": "exchange",
  "eos_balance": 0,
  "staked_balance": 1,
  "unstaking_balance": 0,
  "last_unstaking_time": "2106-02-07T06:28:15"
}
```

307
### Upload example contract
308

309
With an account for a contract created, you can upload a sample contract:
310 311 312 313 314 315

```commandline
cd ~/eos/build/programs/eosc/ 
./eosc contract exchange ../../../contracts/exchange/exchange.wast ../../../contracts/exchange/exchange.abi
```

S
Serg Metelin 已提交
316
## Run eos in docker
peterwillcn's avatar
peterwillcn 已提交
317

318 319
Simple and fast setup of EOS on Docker is also available. Firstly, install dependencies:

peterwillcn's avatar
peterwillcn 已提交
320 321 322 323
 - [Docker](https://docs.docker.com)
 - [Docker-compose](https://github.com/docker/compose)
 - [Docker-volumes](https://github.com/cpuguy83/docker-volumes)

324
Build eos image
peterwillcn's avatar
peterwillcn 已提交
325

S
Serg Metelin 已提交
326 327 328 329 330
```
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 已提交
331 332
```

S
Serg Metelin 已提交
333
Starting the Docker this can be tested from container's host machine:
peterwillcn's avatar
peterwillcn 已提交
334

S
Serg Metelin 已提交
335
```
peterwillcn's avatar
peterwillcn 已提交
336
sudo rm -rf /data/store/eos # options 
peterwillcn's avatar
peterwillcn 已提交
337
sudo mkdir -p /data/store/eos
S
Serg Metelin 已提交
338
docker-compose -f Docker/docker-compose.yml up
peterwillcn's avatar
peterwillcn 已提交
339 340
```

341
Get chain info:
342 343 344 345 346

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

S
Serg Metelin 已提交
347 348
### Run contract in docker example

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

S
Serg Metelin 已提交
351
```
352
docker exec docker_eos_1 eosc contract exchange contracts/exchange/exchange.wast contracts/exchange/exchange.abi
S
Serg Metelin 已提交
353
```