5分钟学会搭建EOS本地测试环境并发币

# 第一步:安装Docker

# 根据操作系统下载相应docker进行配置安装,支持windows 10, Linux, Mac

# https://www.docker.com/community-edition

# install docker (for CentOS)

su yum install -y yum-utils device-mapper-persistent-data lvm2 yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo yum install -y docker-ce service docker start

# 第二步:部署EOS节点服务

# pull images

docker pull eosio/eos:latest 

# create dirs for blocks & wallet

mkdir -p /data/eosio/nodeos-data 

# 如果曾经创建过nodeos容器需要先删除

docker stop nodeos docker rm nodeos 

# create & run nodeos container (Windows需删掉换行符并在一行内)

docker run -d --name nodeos -v /data/eosio/nodeos-data:/opt/eosio/bin/data-dir -p 8888:8888 -p 9876:9876 -t eosio/eos /opt/eosio/bin/nodeosd.sh -e --replay-blockchain --plugin eosio::chain_api_plugin --plugin eosio::history_api_plugin --plugin eosio::wallet_api_plugin --data-dir /opt/eosio/bin/data-dir

# config.ini及区块自动生成在/data/eosio/nodeos-data下

# get logs. CTRL+C to break

docker logs -f nodeos 

# create cleos commond alias

alias cleos='docker exec -i nodeos /opt/eosio/bin/cleos -u http://127.0.0.1:8888 --wallet-url http://127.0.0.1:8888'

# get chain info with cleos

cleos get info 

# issue fix: std::exception::what: database dirty flag set (likely due to unclean shutdown) replay or resync required

# issue fix: Failed to start a pending block, will try again later

cd /data/eosio/nodeos-data rm ./* -rf 

# 修改nodeos-data下文件后需重启nodeos

# restart nodeos service

docker stop nodeos docker start nodeos # or docker restart nodeos 

# 第三步:发行系统代币

# create default key wallet, save password to use in the future to unlock this wallet.

cleos wallet create cleos wallet unlock 

# create & import keys

cleos create key 

# Private key: 5J5cKtCM7MvC8kUGPyT59xPeK6KUG2waJJQhmNTx1TjjjeR34rd# Public key: EOS75eHTUgnvzUQt8qgj48kDBLyTQvSqpc6mEjW3pzaYuThqC7Mdw

cleos wallet import 5J5cKtCM7MvC8kUGPyT59xPeK6KUG2waJJQhmNTx1TjjjeR34rd 

# setup eosio.bios

cd /data/eosio/nodeos-data cleos set contract eosio contracts/eosio.bios -p eosio 

# setup eosio.token

cleos create account eosio eosio.token EOS75eHTUgnvzUQt8qgj48kDBLyTQvSqpc6mEjW3pzaYuThqC7Mdw cleos set contract eosio.token contracts/eosio.token -p eosio.token

# create token

cleos push action eosio.token create    '{"issuer":"eosio", "maximum_supply":"1000000000.0000 SYS"}'    -p eosio.token 

# issue tokens

cleos push action eosio.token issue    '[ "eosio", "1000000000.0000 SYS", "memo"  ]'    -p eosio 

# get balance

cleos get currency balance eosio.token eosio cleos get table eosio.token eosio accounts  

# transfer tokens

cleos create account eosio user EOS75eHTUgnvzUQt8qgj48kDBLyTQvSqpc6mEjW3pzaYuThqC7Mdw cleos create account eosio tester EOS75eHTUgnvzUQt8qgj48kDBLyTQvSqpc6mEjW3pzaYuThqC7Mdw cleos transfer eosio user '25 SYS' 'm' cleos get currency balance eosio.token user cleos push action eosio.token transfer '[ "user", "tester", "5.0000 SYS", "m" ]' -p user cleos get currency balance eosio.token tester

# smart contract: hello

cleos set contract user contracts/hello -p user cleos push action user hi '["eosio"]' -p user 

# user <= user::hi {“user”:”eosio”}>> Hello, eosio

# Clear all. stop & remove containers, delete all data

# WARNING: delete nodeos-data will lost config & block files & all imported keys!

docker ps -a docker stop nodeos docker rm nodeos sudo rm /data/eosio/nodeos-data -rf 

# After all cleared, we can start over everything again

# 一键发币!

service docker start docker pull eosio/eos:latest mkdir -p /data/eosio/nodeos-data docker run -d --name nodeos -v /data/eosio/nodeos-data:/opt/eosio/bin/data-dir -p 8888:8888 -p 9876:9876 -t eosio/eos /opt/eosio/bin/nodeosd.sh -e --replay-blockchain --plugin eosio::chain_api_plugin --plugin eosio::history_api_plugin --plugin eosio::wallet_api_plugin --data-dir /opt/eosio/bin/data-dir alias cleos='docker exec -i nodeos /opt/eosio/bin/cleos -u http://127.0.0.1:8888 --wallet-url http://127.0.0.1:8888' cleos get info cleos wallet create cleos wallet import 5J5cKtCM7MvC8kUGPyT59xPeK6KUG2waJJQhmNTx1TjjjeR34rd cd /data/eosio/nodeos-data cleos set contract eosio contracts/eosio.bios -p eosio cleos create account eosio eosio.token EOS75eHTUgnvzUQt8qgj48kDBLyTQvSqpc6mEjW3pzaYuThqC7Mdw cleos set contract eosio.token contracts/eosio.token -p eosio.token cleos push action eosio.token create '{"issuer":"eosio", "maximum_supply":"1000000000.0000 SYS"}' -p eosio.token cleos push action eosio.token issue '[ "eosio", "1000000000.0000 SYS", "memo" ]' -p eosio cleos get currency balance eosio.token eosio cleos get table eosio.token eosio accounts cleos create account eosio user EOS75eHTUgnvzUQt8qgj48kDBLyTQvSqpc6mEjW3pzaYuThqC7Mdw cleos create account eosio tester EOS75eHTUgnvzUQt8qgj48kDBLyTQvSqpc6mEjW3pzaYuThqC7Mdw cleos transfer eosio user '25 SYS' 'm' cleos get currency balance eosio.token user cleos push action eosio.token transfer '[ "user", "tester", "5.0000 SYS", "m" ]' -p user cleos get currency balance eosio.token tester cleos set contract user contracts/hello -p user cleos push action user hi '["eosio"]' -p user

# EOS src & wiki: github.com/EOSIO/eos

# EOS dev docs: eosio.github.io/eos/

# 5分钟学会注册EOS主网账户、投票和发币

# 欢迎收藏本文备用。

发表评论