EOS 开发相关

GitHub

EOS源码调试及跟踪(下)
http://bitbee.io/d/5b8f601014f8bf4896d27b91

Mac

clion cmake option:
-DWASM_ROOT=~/opt/wasm

MacOS Darwin 10.12 and higher (MacOS 10.13.x recommended)

rm -rf /path/to/eos
git clone https://github.com/EOSIO/eos.git --recursive
git submodule update --init --recursive
./eosio_build.sh
// Mac OS X Brew Install
brew tap eosio/eosio
brew install eosio

// response
/usr/local/Cellar/eosio/1.4.4: 14 files, 61.9MB

// Mac OS X Brew Uninstall
brew remove eosio

centos

wget https://github.com/EOSIO/eos/releases/download/v1.5.0/eosio-1.5.0-1.el7.x86_64.rpm

sudo yum install ./eosio-1.4.4-1.el7.x86_64.rpm

build source

xcode-select --install
brew install autoconf automake libtool boost openssl pkg-config

cd /path/to/eos
rm -rf ./build/
git pull
git submodule update --init --recursive
./eosio_build.sh

如果提示 llvm 找不到就指定一下路径
export LLVM_DIR=/usr/local/Cellar/llvm@4/4.0.1_1/lib/cmake

LLVM 支持 wasm 编译
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

export WASM_ROOT=~/opt/wasm

Building from Scratch

git clone --recursive https://github.com/eosio/eosio.cdt
$ cd eosio.cdt
$ ./build.sh
$ sudo ./install.sh

Start keosd

keosd &

close nodeos

notice unsafe way

safe way
pkill nodeos
pkill -15 nodeos | Safe
pkill -2 nodeos | Safe
pkill -TERM nodeos | Safe
pkill -SIGTERM nodeos | Safe
pkill -INT nodeos | Safe
pkill -SIGINT nodeos | Safe
pkill -9 nodeos | Not Safe
pkill -KILL nodeos | Not Safe
pkill -SIGKILL nodeos | Not Safe

Start nodeos

nodeos -e -p eosio \
--plugin eosio::producer_plugin \
--plugin eosio::chain_api_plugin \
--plugin eosio::http_plugin \
-d /Users/zhengjun/project/blockchain/EOS/contracts/eosio/data \
--config-dir /Users/zhengjun/project/blockchain/EOS/contracts/eosio/config \
--access-control-allow-origin=* \
--contracts-console=true \
--http-validate-host=false \
—filter-on=‘*’ > nodeos.log 2>nodeosErr.log &

parameters explain:

-d /Users/zhengjun/project/blockchain/EOS/testnetData
这是区块链数据存放的目录,根据你的配置修改为相应的路径。

--plugin eosio::chain_api_plugin
开启区块链JSON API插件。

--plugin eosio::history_api_plugin
开启历史数据插件,有了这个插件,便能查询许多不在State中的数据,譬如一个公钥所对应的所有账户等等。

--contracts-console
开启合约控制台。如果不开启的话,合约中调用print函数输出的信息将会不可见。

--filter-on "*"
开启所有账户的历史纪录。默认状态下,节点不会记录账户的历史数据,从而使得命令cleos get actions返回空。

--access-control-allow-origin "*"
允许任意域名跨域访问API,如果不开启,在dApp开发中,网站会报错。

start testnet

./local-testnet.sh

//check status
cleos get info

tail -f nodeos.log

Check the Wallet

cleos wallet list

Check Nodeos endpoints

This will check that the RPC API is working correctly

curl http://localhost:8888/v1/chain/get_info

Install the CDT

brew tap eosio/eosio.cdt
brew install eosio.cdt

brew remove eosio.cdt

Create Test Accounts

cleos create account eosio bob EOS5QhwGZkS3j47j54VSiSeGkC58PpXUKMnoKwor34EfMihvBABqg
cleos create account eosio alice EOS5QhwGZkS3j47j54VSiSeGkC58PpXUKMnoKwor34EfMihvBABqg
cleos set account permission addressbook active '{"threshold": 1,"keys": [{"key": "EOS5QhwGZkS3j47j54VSiSeGkC58PpXUKMnoKwor34EfMihvBABqg","weight": 1}],"accounts": [{"permission":{"actor":"addressbook","permission":"eosio.code"},"weight":1}]}' owner
cleos push action addressbook upsert '["alice", "alice", "alice-last",21, "liddell", "123 drink me way", "wonderland", "amsterdam"]' -p alice@active

ubuntu 18.04

// Ubuntu 18.04 Debian Package Install
wget https://github.com/eosio/eos/releases/download/v1.4.3/eosio-1.4.3.ubuntu-18.04-x86_64.deb
sudo apt install ./eosio-1.4.3.ubuntu-18.04-x86_64.deb

// Debian Package Uninstall
sudo apt remove eosio

Start Your Node & Setup

Get the docker image

docker 镜像已经不维护了。后面不要用了

docker pull eosio/eos:v1.4.2

Boot Node and Wallet

docker run --name eosio \
--publish 7777:7777 \
--publish 127.0.0.1:5555:5555 \
--volume /Users/zhengjun/project/blockchain/EOS/contracts:/Users/zhengjun/project/blockchain/EOS/contracts \
--detach \
eosio/eos:v1.4.2 \
/bin/bash -c \
"keosd --http-server-address=0.0.0.0:5555 & exec nodeos -e -p eosio --plugin eosio::producer_plugin --plugin eosio::chain_api_plugin --plugin eosio::history_plugin --plugin eosio::history_api_plugin --plugin eosio::http_plugin -d /mnt/dev/data --config-dir /mnt/dev/config --http-server-address=0.0.0.0:7777 --access-control-allow-origin=* --contracts-console --http-validate-host=false --filter-on='*' --verbose-http-errors"

–verbose-http-errors 输出详细 debug 信息

Check the installation

docker logs --tail 10 eosio

Check the Wallet

docker exec -it eosio bash
cleos --wallet-url http://127.0.0.1:5555 wallet list
response:
Wallets:
[]
// 退出
exit

到此为止,节点运行正常,不需要登录 docker,从本地终端就可以操作了

Check Nodeos endpoints

curl http://localhost:7777/v1/chain/get_info

Aliasing Cleos

alias cleos='docker exec -it eosio /opt/eosio/bin/cleos --url http://127.0.0.1:7777 --wallet-url http://127.0.0.1:5555'

Useful Docker Commands

docker start eosio
docker stop eosio

docker exec -it eosio bash
docker rm eosio

Create Development Wallet

cleos wallet create --to-console

Creating wallet: default
Save password to use in the future to unlock this wallet.
Without password imported keys will not be retrievable.
"PW5Jd4jD7LxsaeWCdRL9EfmRSJJniMCscEAqYoWAWUkLegeFkob12"

Open the Wallet

cleos wallet open
cleos wallet list
// Unlock it
cleos wallet unlock

cleos wallet list
return: lastest asterisk means
Wallets:
[
"default *"
]

Import keys into your wallet

// Generate a private key
cleos wallet create_key

Created new private key with a public key of: "EOS7YSqcinSoBSLrg9TmbmHJF6cjMUCQuZvxifFRAARiS4Y7afnpz"

Import the Development Key

cleos wallet import

5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3

Create Test Accounts

cleos create account eosio bob EOS7YSqcinSoBSLrg9TmbmHJF6cjMUCQuZvxifFRAARiS4Y7afnpz
cleos create account eosio alice EOS7YSqcinSoBSLrg9TmbmHJF6cjMUCQuZvxifFRAARiS4Y7afnpz

executed transaction: 1b6ba347497d0ec6be261835a15e8ab65c8d459edc3ac2e2ffbc48871318c1da 200 bytes 768 us
# eosio <= eosio::newaccount {"creator":"eosio","name":"bob","owner":{"threshold":1,"keys":[{"key":"EOS8hR3s3uanKUZEmrF2aqgEtnEXZ...

executed transaction: 095ca02fc4bff44978d41bf088bf61c177178b90fd82b7d027c8430da6f3268e 200 bytes 303 us
# eosio <= eosio::newaccount {"creator":"eosio","name":"alice","owner":{"threshold":1,"keys":[{"key":"EOS8hR3s3uanKUZEmrF2aqgEtnE...
warning: transaction executed locally, but may not be confirmed by the network yet ]

contracts

// compile
eosio-cpp -o hello.wasm hello.cpp --abigen

cleos wallet keys
cleos create account eosio hello EOS7YSqcinSoBSLrg9TmbmHJF6cjMUCQuZvxifFRAARiS4Y7afnpz -p eosio@active
cleos set contract hello /Users/zhengjun/project/blockchain/EOS/contracts/hello -p hello@active
cleos push action hello hi '["bob"]' -p bob@active
cleos push action hello hi '["alice"]' -p alice@active

Deploy, Issue and Transfer Tokens

Obtain Contract Source

cd /Users/zhengjun/project/blockchain/EOS/contracts
git clone https://github.com/EOSIO/eosio.contracts --branch v1.4.0 --single-branch
cd eosio.contracts/eosio.token

Create Account for Contract

cleos create account eosio eosio.token EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV

Compile the Contract

eosio-cpp -I include -o eosio.token.wasm src/eosio.token.cpp --abigen

Deploy the Token Contract

cleos set contract eosio.token /Users/zhengjun/project/blockchain/EOS/contracts/eosio.contracts/eosio.token --abi eosio.token.abi -p eosio.token@active

Create the Token

cleos push action eosio.token create '[ "eosio", "1000000000.0000 SYS"]' -p eosio.token@active

This command created a new token SYS with a precision of 4 decimals and a maximum supply of 1000000000.0000 SYS. To create this token requires the permission of the eosio.token contract. For this reason, -p eosio.token@active was passed to authorize the request.

Issue Tokens

cleos push action eosio.token issue '[ "alice", "100.0000 SYS", "memo" ]' -p eosio@active

To inspect the transaction, try using the -d -j options, they indicate “don’t broadcast” and “return transaction as json,” which you may find useful during development.

cleos push action eosio.token issue '["alice", "100.0000 SYS", "memo"]' -p eosio@active -d -j

Transfer Tokens

cleos push action eosio.token transfer '[ "alice", "bob", "25.0000 SYS", "m" ]' -p alice@active

// check result
cleos get currency balance eosio.token bob SYS

Building your first smart contract

cd ./examples/hello
eosio-cpp -abigen hello.cpp -o hello.wasm

This will generate two files:
The compiled binary wasm (hello.wasm)
The generated ABI file (hello.abi)