上篇在ubuntu上编译好eos,见https://www.jianshu.com/p/f28bfb5830c3
一,开始搭建测试网络:
首先运行eosd命令
cd ~/eos/build/programs/eosd/
./eosd
eosd命令执行后会在当前目录生成data-dir目录,
data-dir目录会产生一个config.ini配置文件
cd ~/eos/build/programs/eosd/
vim data-dir/config.ini
修改为如下内容,其中/home/chen/eos/build/genesis.json是编译后自动生成的:
# Track only transactions whose scopes involve the listed accounts. Default is to track all transactions.
# filter_on_accounts =
# Limits the maximum time (in milliseconds) processing a single get_transactions call.
get-transactions-time-limit = 3
# File to read Genesis State from
# genesis-json =
# override the initial timestamp in the Genesis State file
# genesis-timestamp =
# the location of the block log (absolute path or relative to application data dir)
block-log-dir = "blocks"
# Sets the block interval in seconds.
block-interval-seconds = 1
# Pairs of [BLOCK_NUM,BLOCK_ID] that should be enforced as checkpoints.
# checkpoint =
# Limits the maximum time (in milliseconds) that is allowed a transaction's code to execute from a received block.
rcvd-block-trans-execution-time = 72
# Limits the maximum time (in milliseconds) that is allowed a pushed transaction's code to execute.
trans-execution-time = 18
# Limits the maximum time (in milliseconds) that is allowed a transaction's code to execute while creating a block.
create-block-trans-execution-time = 18
# The time frame, in seconds, that the per-authorized-account-transaction-msg-rate-limit is imposed over.
per-authorized-account-transaction-msg-rate-limit-time-frame-sec = 18
# Limits the maximum rate of transaction messages that an account is allowed each per-authorized-account-transaction-msg-rate-limit-time-frame-sec.
per-authorized-account-transaction-msg-rate-limit = 1800
# The time frame, in seconds, that the per-code-account-transaction-msg-rate-limit is imposed over.
per-code-account-transaction-msg-rate-limit-time-frame-sec = 18
# Limits the maximum rate of transaction messages that an account's code is allowed each per-code-account-transaction-msg-rate-limit-time-frame-sec.
per-code-account-transaction-msg-rate-limit = 18000
# Limits the maximum database storage that an account's code is allowed.
per-code-account-max-storage-db-limit-mbytes = 5
# The overhead to apply per row for approximating total database storage.
row-overhead-db-limit-bytes = 32
# The maximum depth the pending transaction queue will be allowed to reach till new pushed transactions are rejected.
pending-txn-depth-limit = 1000
# The maximum allowed for generating a block before subsequent transactions get put back on the pending transaction queue.
gen-block-time-limit-msec = 200
# open the database in read only mode
readonly = 0
# the location of the chain shared memory files (absolute path or relative to application data dir)
shared-file-dir = "blockchain"
# Minimum size MB of database shared memory file
shared-file-size = 8192
# Time to wait, in milliseconds, between creating next faucet created account.
faucet-create-interval-ms = 1000
# Name to use as creator for faucet created accounts.
faucet-name = faucet
# [public key, WIF private key] for signing for faucet creator account
faucet-private-key = ["EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV","5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3"]
# The local IP and port to listen for incoming http connections.
http-server-address = 127.0.0.1:8888
# Specify the Access-Control-Allow-Origin to be returned on each request.
# access-control-allow-origin =
# Specify the Access-Control-Allow-Headers to be returned on each request.
# access-control-allow-headers =
# Specify if Access-Control-Allow-Credentials: true should be returned on each request.
access-control-allow-credentials = false
# The actual host:port used to listen for incoming p2p connections.
p2p-listen-endpoint = 0.0.0.0:9876
# An externally accessible host:port for identifying this node. Defaults to p2p-listen-endpoint.
# p2p-server-address =
# The public endpoint of a peer node to connect to. Use multiple p2p-peer-address options as needed to compose a network.
# p2p-peer-address =
# The name supplied to identify this node amongst the peers.
agent-name = "EOS Test Agent"
# Can be 'any' or 'producers' or 'specified' or 'none'. If 'specified', peer-key must be specified at least once. If only 'producers', peer-key is not required. 'producers' and 'specified' may be combined.
allowed-connection = any
# Optional public key of peer allowed to connect. May be used multiple times.
# peer-key =
# Tuple of [PublicKey, WIF private key] (may specify multiple times)
# peer-private-key =
# Log level: one of 'all', 'debug', 'info', 'warn', 'error', or 'off'
log-level-net-plugin = info
# Maximum number of clients from which connections are accepted, use 0 for no limit
max-clients = 25
# number of seconds to wait before cleaning up dead connections
connection-cleanup-period = 30
# True to require exact match of peer network version.
network-version-match = 0
# number of blocks to retrieve in a chunk from any individual peer during synchronization
sync-fetch-span = 100
# Enable block production, even if the chain is stale.
#enable-stale-production = false
# Percent of producers (0-99) that must be participating in order to produce blocks
required-participation = false
# ID of producer controlled by this node (e.g. inita; may specify multiple times)
# producer-name =
# Tuple of [public key, WIF private key] (may specify multiple times)
private-key = ["EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV","5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3"]
# Plugin(s) to enable, may be specified multiple times
# plugin =
genesis-json = /home/chen/eos/build/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
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
# Load the block producer plugin, so you can produce blocks
plugin = eosio::producer_plugin
# Wallet plugin
plugin = eosio::wallet_api_plugin
# As well as API and HTTP plugins
plugin = eosio::chain_api_plugin
plugin = eosio::http_plugin
修改完成后,运行eosd,就启动了一个测试网络
./eosd
二,使用钱包和账户
1,创建钱包
eosc wallet create会创建default钱包,在这里我们想创建自己命名的钱包
cd ~/eos/build/programs/eosc/
./eosc wallet create -n wallet1
返回如下内容,下面的password要保存好,用于解锁被锁定的钱包:
Creating wallet: wallet1
Save password to use in the future to unlock this wallet.
Without password imported keys will not be retrievable.
"PW5JRLFvGrDVkhBiRadjaH7qHTyUYsiVp9Ep6UbtPw7LMFRTY11Aj"
2,查看钱包列表:
./eosc wallet list
返回如下内容,带星号的钱包表示处于解锁可用状态:
Wallets:
[
"wallet1 *"
]
3,锁定和解锁钱包:
#锁定
./eosc wallet lock -n wallet1
#解锁,输入上面产生的密码:PW5JRLFvGrDVkhBiRadjaH7qHTyUYsiVp9Ep6UbtPw7LMFRTY11Aj
./eosc wallet unlock -n wallet1
4,创建公钥和私钥对,连续创建两个用于owner和active权限
./eosc create key
返回:
Private key: 5K5MhSgUbBCwDUdX3xRnZsBxapbq8CJ2uKvwS5kiMBchdmjY6Ea
Public key: EOS7s1eAB9dbGnJzhhMbHnui1MA2PXbSycabio4JVDp9iJGAvRNSm
./eosc create key
返回:
Private key: 5KdT7YKf6p4aHqSqwtmGjvqdkQ2d4ZbX31F1mmLShbQ2eSUEe9n
Public key: EOS55FiCrEu5rdtPUuUhVbDCvUcvYF64PYHh9Lj39TrH58WHj2yLG
5,把密钥导入钱包
#如果使用default包,不需要使用-参数
./eosc wallet import -n wallet1 5K5MhSgUbBCwDUdX3xRnZsBxapbq8CJ2uKvwS5kiMBchdmjY6Ea
./eosc wallet import -n wallet1 5KdT7YKf6p4aHqSqwtmGjvqdkQ2d4ZbX31F1mmLShbQ2eSUEe9n
6、查询钱包所包含的公钥和私钥
./eosc wallet keys
返回:
[[
"EOS55FiCrEu5rdtPUuUhVbDCvUcvYF64PYHh9Lj39TrH58WHj2yLG",
"5KdT7YKf6p4aHqSqwtmGjvqdkQ2d4ZbX31F1mmLShbQ2eSUEe9n"
],[
"EOS7s1eAB9dbGnJzhhMbHnui1MA2PXbSycabio4JVDp9iJGAvRNSm",
"5K5MhSgUbBCwDUdX3xRnZsBxapbq8CJ2uKvwS5kiMBchdmjY6Ea"
]
]
7,创建账户,你需要一个生产者来创建账户,在config.ini里面我们定义了一个inita的生产者
他的公钥和私钥,写死在这个配置文件里
private-key = ["EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV","5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3"]
运行创建账户account1,一个公钥用于owner,一个用于active,命令:
./eosc create account inita account1 EOS7s1eAB9dbGnJzhhMbHnui1MA2PXbSycabio4JVDp9iJGAvRNSm EOS55FiCrEu5rdtPUuUhVbDCvUcvYF64PYHh9Lj39TrH58WHj2yLG
会抛出错误
1644950ms main.cpp:1195 main ] Failed with error: Assert Exception (10)
status_code == 200: Error code 401
: {"code":401,"message":"UnAuthorized","details":"signatures do not satisfy declared authorizations (3030002)\nTransaction declares authority '{\"account\":\"inita\",\"permission\":\"active\"}', but does not have signatures for it.\n"}
原因是inita账户没有导入到wallet1钱包中,导入
./eosc wallet import -n wallet1 5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3
再重新运行:
./eosc create account inita account1 EOS7s1eAB9dbGnJzhhMbHnui1MA2PXbSycabio4JVDp9iJGAvRNSm EOS55FiCrEu5rdtPUuUhVbDCvUcvYF64PYHh9Lj39TrH58WHj2yLG
返回如下信息成功:
OS55FiCrEu5rdtPUuUhVbDCvUcvYF64PYHh9Lj39TrH58WHj2yLG
{
"transaction_id": "a529ba3116b0582de4889982dcb46f2cbed600b66d04fa20d7ce3d267ced0ec8",
"processed": {
"ref_block_num": 12722,
"ref_block_prefix": 3892340324,
"expiration": "2017-09-29T13:32:20",
"scope": [
"eos",
"inita"
],
"signatures": [
"2047ef2f72aa20018b5a964573e21100f603198a477f600a4f81a437b3e448f997129f96f8c04a4bf8991a3b4a0e63d5a90ce4d1898c5ec9141dcce2b5a9dd5716"
],
"messages": [{
"code": "eos",
"type": "newaccount",
"authorization": [{
"account": "inita",
"permission": "active"
}
],
"data": {
"creator": "inita",
"name": "account1",
"owner": {
"threshold": 1,
"keys": [{
"key": "EOS7s1eAB9dbGnJzhhMbHnui1MA2PXbSycabio4JVDp9iJGAvRNSm",
"weight": 1
}
],
"accounts": []
},
"active": {
"threshold": 1,
"keys": [{
"key": "EOS55FiCrEu5rdtPUuUhVbDCvUcvYF64PYHh9Lj39TrH58WHj2yLG",
"weight": 1
}
],
"accounts": []
},
"recovery": {
"threshold": 1,
"keys": [],
"accounts": [{
"permission": {
"account": "inita",
"permission": "active"
},
"weight": 1
}
]
},
"deposit": "0.0001 EOS"
},
"hex_data": "000000000093dd74000000214f4d113201000000010387bb96c7aafc02e568bee92b237b870f5f2f574ccdee88bad1e2f9dc5cfd2f80010000010000000102187158f7d82bca47825e960912be05c55635f662859d1ecb04eb01bbeb002d5a010000010000000001000000000093dd7400000000a8ed32320100010000000000000004454f5300000000"
}
],
"output": [{
"notify": [],
"deferred_trxs": []
}
]
}
}
8,备份密钥
在 data-dir下面会有一个钱包文件wallet1.wallet生成,保存好这个文件。