再战EOS合约

作为master你了不起啊

你改任你改,我重头再来!

因为master合约命令行参数又修改过了,再来一遍把!

2018.4.2日更新, 对照github文档   Tutorial.MD

环境配置略过了,执行eos目录下的eosio_build.sh 它会自行配置环境,mongodb的坑,这里就不填了。

./eosio_build.sh

成功后会出现

[100%] Built target nodeos
	 _______  _______  _______ _________ _______
	(  ____ \(  ___  )(  ____ \\__   __/(  ___  )
	| (    \/| (   ) || (    \/   ) (   | (   ) |
	| (__    | |   | || (_____    | |   | |   | |
	|  __)   | |   | |(_____  )   | |   | |   | |
	| (      | |   | |      ) |   | |   | |   | |
	| (____/\| (___) |/\____) |___) (___| (___) |
	(_______/(_______)\_______)\_______/(_______)

	EOS.IO has been successfully built. 0:4:35

	To verify your installation run the following commands:

	/home/feng/opt/mongodb/bin/mongod -f /home/feng/opt/mongodb/mongod.conf &
	cd /home/feng/eos/build; make test

	For more information:
	EOS.IO website: https://eos.io
	EOS.IO Telegram channel @ https://t.me/EOSProject
	EOS.IO resources: https://eos.io/resources/
	EOS.IO wiki: https://github.com/EOSIO/eos/wiki

到nodes目录

cd build/programs/nodeos/
mkdir data-dir config-dir
cp ../../genesis.json config-dir/
cp ../../../../config.ini config-dir/

这里不在详细介绍了,各位可以去看上一篇的介绍 

再贴一下config.ini

# Track only transactions whose scopes involve the listed accounts. Default is to track all transactions. (eosio::account_history_plugin)
# filter_on_accounts = 

# Limits the maximum time (in milliseconds) processing a single get_transactions call. (eosio::account_history_plugin)
get-transactions-time-limit = 3

# File to read Genesis State from (eosio::chain_plugin)
genesis-json = "genesis.json"

# override the initial timestamp in the Genesis State file (eosio::chain_plugin)
# genesis-timestamp = 

# the location of the block log (absolute path or relative to application data dir) (eosio::chain_plugin)
block-log-dir = "blocks"

# Pairs of [BLOCK_NUM,BLOCK_ID] that should be enforced as checkpoints. (eosio::chain_plugin)
# checkpoint = 

# Limits the maximum time (in milliseconds) that a reversible block is allowed to run before being considered invalid (eosio::chain_plugin)
max-reversible-block-time = -1

# Limits the maximum time (in milliseconds) that is allowed a pushed transaction's code to execute before being considered invalid (eosio::chain_plugin)
max-pending-transaction-time = -1

# Time to wait, in milliseconds, between creating next faucet created account. (eosio::faucet_testnet_plugin)
faucet-create-interval-ms = 1000

# Name to use as creator for faucet created accounts. (eosio::faucet_testnet_plugin)
faucet-name = faucet

# [public key, WIF private key] for signing for faucet creator account (eosio::faucet_testnet_plugin)
faucet-private-key = ["EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV","5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3"]

# The local IP and port to listen for incoming http connections. (eosio::http_plugin)
http-server-address = 127.0.0.1:8888

# Specify the Access-Control-Allow-Origin to be returned on each request. (eosio::http_plugin)
# access-control-allow-origin = 

# Specify the Access-Control-Allow-Headers to be returned on each request. (eosio::http_plugin)
# access-control-allow-headers = 

# Specify if Access-Control-Allow-Credentials: true should be returned on each request. (eosio::http_plugin)
access-control-allow-credentials = false

# The actual host:port used to listen for incoming p2p connections. (eosio::net_plugin)
p2p-listen-endpoint = 0.0.0.0:9876

# An externally accessible host:port for identifying this node. Defaults to p2p-listen-endpoint. (eosio::net_plugin)
# 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. (eosio::net_plugin)
# p2p-peer-address = 

# The name supplied to identify this node amongst the peers. (eosio::net_plugin)
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. (eosio::net_plugin)
allowed-connection = any

# Optional public key of peer allowed to connect.  May be used multiple times. (eosio::net_plugin)
# peer-key = 

# Tuple of [PublicKey, WIF private key] (may specify multiple times) (eosio::net_plugin)
# peer-private-key = 

# Log level: one of 'all', 'debug', 'info', 'warn', 'error', or 'off' (eosio::net_plugin)
log-level-net-plugin = info

# Maximum number of clients from which connections are accepted, use 0 for no limit (eosio::net_plugin)
max-clients = 25

# number of seconds to wait before cleaning up dead connections (eosio::net_plugin)
connection-cleanup-period = 30

# True to require exact match of peer network version. (eosio::net_plugin)
network-version-match = 0

# number of blocks to retrieve in a chunk from any individual peer during synchronization (eosio::net_plugin)
sync-fetch-span = 100

# Enable block production, even if the chain is stale. (eosio::producer_plugin)
enable-stale-production = true

# Percent of producers (0-99) that must be participating in order to produce blocks (eosio::producer_plugin)
#required-participation = false

# ID of producer controlled by this node (e.g. inita; may specify multiple times) (eosio::producer_plugin)
producer-name = eosio

# Tuple of [public key, WIF private key] (may specify multiple times) (eosio::producer_plugin)
private-key = ["EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV","5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3"]

# Plugin(s) to enable, may be specified multiple times
# 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  

运行nodes,文档新加了一些插件参数

./nodeos --config-dir config-dir --data-dir data-dir -e -p eosio --plugin eosio::wallet_api_plugin --plugin eosio::chain_api_plugin --plugin eosio::account_history_api_plugin 

新的命令行

cd ../cleos/

创建钱包,这个私钥要保存好,以后不会在出现,每次打开钱包需要。关闭客户端后,要重新打开钱包。

feng@feng-B250-HD3P:~/workSpace/eos/build/programs/cleos$ ./cleos wallet create
Creating wallet: default
Save password to use in the future to unlock this wallet.
Without password imported keys will not be retrievable.
"PW5Jih9U9oFCXLH62yjhCjY1iBRxfzeN6Fka1pMqYwuXMjQgxmjQq"

解锁钱包

feng@feng-B250-HD3P:~/workSpace/eos/build/programs/cleos$ ./cleos wallet unlock --password PW5Jih9U9oFCXLH62yjhCjY1iBRxfzeN6Fka1pMqYwuXMjQgxmjQq
Unlocked: default

导入测试账号的私钥,这个私钥是eosio账号测试合约用的

./cleos wallet import 5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3

重点来了,这里一定要在cleos目录去执行,不要使用cloes。

feng@feng-B250-HD3P:~/workSpace/eos/build/programs/cleos$ ./cleos set contract eosio ../../contracts/eosio.bios -p eosio
Reading WAST...
Assembling WASM...
Publishing contract...
executed transaction: ecc149bfbd77f5fc87791a1b86a6310a4daf169434084fcc3bb289a4cd6c94d1  4068 bytes  10000 cycles
#         eosio <= eosio::setcode               {"account":"eosio","vmtype":0,"vmversion":0,"code":"0061736d0100000001ab011960037f7e7f0060057f7e7e7e...
#         eosio <= eosio::setabi                {"account":"eosio","abi":{"types":[],"structs":[{"name":"set_account_limits","base":"","fields":[{"n...
feng@feng-B250-HD3P:~/workSpace/eos/build/programs/cleos$ ./cleos create key
Private key: 5Jo5M9MxS7XzWRcwjdy1QVrMWXiTe4mouRx9waJLjUA8wd1LrJX
Public key: EOS5a7fk4RAQ2fzdWy5TTRdhmcHpZQxwyoLqvczQHhpcGSjoFdSkK
feng@feng-B250-HD3P:~/workSpace/eos/build/programs/cleos$ ./cleos wallet import 5Jo5M9MxS7XzWRcwjdy1QVrMWXiTe4mouRx9waJLjUA8wd1LrJX
imported private key for: EOS5a7fk4RAQ2fzdWy5TTRdhmcHpZQxwyoLqvczQHhpcGSjoFdSkK

现在我们来测试一下--plugin eosio::account_history_api_plugin  插件是否正常

根据公钥创建两个账号,然后根据公钥显示账号。

feng@feng-B250-HD3P:~/workSpace/eos/build/programs/cleos$ ./cleos create account eosio user EOS5a7fk4RAQ2fzdWy5TTRdhmcHpZQxwyoLqvczQHhpcGSjoFdSkK EOS5a7fk4RAQ2fzdWy5TTRdhmcHpZQxwyoLqvczQHhpcGSjoFdSkK
executed transaction: ba059a60a5dfd30372f9ccf345b83954e40ea8a31221b4903570f1c2eae042ef  364 bytes  1000 cycles
#         eosio <= eosio::newaccount            {"creator":"eosio","name":"user","owner":{"threshold":1,"keys":[{"key":"EOS5a7fk4RAQ2fzdWy5TTRdhmcHp...
feng@feng-B250-HD3P:~/workSpace/eos/build/programs/cleos$ ./cleos get accounts EOS5a7fk4RAQ2fzdWy5TTRdhmcHpZQxwyoLqvczQHhpcGSjoFdSkK
{
  "account_names": [
    "user"
  ]
}
feng@feng-B250-HD3P:~/workSpace/eos/build/programs/cleos$ ./cleos create account eosio tester EOS5a7fk4RAQ2fzdWy5TTRdhmcHpZQxwyoLqvczQHhpcGSjoFdSkK EOS5a7fk4RAQ2fzdWy5TTRdhmcHpZQxwyoLqvczQHhpcGSjoFdSkK
executed transaction: b9b6f6619993a342dd6dfc2819d7b649ef95e386223b5ea19aa74a80592d1f26  364 bytes  1000 cycles
#         eosio <= eosio::newaccount            {"creator":"eosio","name":"tester","owner":{"threshold":1,"keys":[{"key":"EOS5a7fk4RAQ2fzdWy5TTRdhmc...
feng@feng-B250-HD3P:~/workSpace/eos/build/programs/cleos$ ./cleos get accounts EOS5a7fk4RAQ2fzdWy5TTRdhmcHpZQxwyoLqvczQHhpcGSjoFdSkK{
  "account_names": [
    "tester",
    "user"
  ]
}

下面测试一下token合约,首先要创建一个token账号(方便后面拷贝代码)

feng@feng-B250-HD3P:~/workSpace/eos/build/programs/cleos$ ./cleos create account eosio eosio.token EOS5a7fk4RAQ2fzdWy5TTRdhmcHpZQxwyoLqvczQHhpcGSjoFdSkK EOS5a7fk4RAQ2fzdWy5TTRdhmcHpZQxwyoLqvczQHhpcGSjoFdSkK
executed transaction: f5aa4e46d4e82187ea8f892aea9a0a170c1fb3433541e40ffe5e3cefda552710  364 bytes  1000 cycles
#         eosio <= eosio::newaccount            {"creator":"eosio","name":"eosio.token","owner":{"threshold":1,"keys":[{"key":"EOS5a7fk4RAQ2fzdWy5TT...

部署合约

feng@feng-B250-HD3P:~/workSpace/eos/build/programs/cleos$ ./cleos set contract eosio.token ../../contracts/eosio.token -p eosio.token
Reading WAST...
Assembling WASM...
Publishing contract...
executed transaction: 79b956d0c8e0a55a7e1e54a092c078dd84fb1267c0ed2630cce3f41b3fd03477  8708 bytes  10000 cycles
#         eosio <= eosio::setcode               {"account":"eosio.token","vmtype":0,"vmversion":0,"code":"0061736d0100000001ce011d60067f7e7f7f7f7f00...
#         eosio <= eosio::setabi                {"account":"eosio.token","abi":{"types":[],"structs":[{"name":"transfer","base":"","fields":[{"name"...


创建货币,这里最近有简写了,上一个简写的

feng@feng-B250-HD3P:~/workSpace/eos/build/programs/cleos$ ./cleos push action eosio.token create '[ "eosio", "1000000000.0000 EOS", 0, 0, 0]' -p eosio.token
executed transaction: beab32c6347582d363ce53bebfd973fafd3c7c971741f41499a049b6b599c501  260 bytes  1000 cycles
#   eosio.token <= eosio.token::create          {"issuer":"eosio","maximum_supply":"1000000000.0000 EOS","can_freeze":0,"can_recall":0,"can_whitelis...

下面是全的

$ ./cleos push action eosio.token create '{"issuer":"eosio", "maximum_supply":"1000000000.0000 EOS", "can_freeze":0, "can_recall":0, "can_whitelist":0}' -p eosio.token
executed transaction: 0e49a421f6e75f4c5e09dd738a02d3f51bd18a0cf31894f68d335cd70d9c0e12  260 bytes  1000 cycles
#   eosio.token <= eosio.token::create          {"issuer":"eosio","maximum_supply":"1000000000.0000 EOS","can_freeze":0,"can_recall":0,"can_whitelis...

发行货币到账号上

feng@feng-B250-HD3P:~/workSpace/eos/build/programs/cleos$ ./cleos push action eosio.token issue '[ "user", "100.0000 EOS", "memo" ]' -p eosio
executed transaction: 23f79c2ab797ac04dce6cf9c5bc0b150bf3949aafbeb9a199e6a20eed8bd7043  268 bytes  1000 cycles
#   eosio.token <= eosio.token::issue           {"to":"user","quantity":"100.0000 EOS","memo":"memo"}
>> issue
#   eosio.token <= eosio.token::transfer        {"from":"eosio","to":"user","quantity":"100.0000 EOS","memo":"memo"}
>> transfer
#         eosio <= eosio.token::transfer        {"from":"eosio","to":"user","quantity":"100.0000 EOS","memo":"memo"}
#          user <= eosio.token::transfer        {"from":"eosio","to":"user","quantity":"100.0000 EOS","memo":"memo"}

我们加上-d -j 再试一次,看下transaction 的json

feng@feng-B250-HD3P:~/workSpace/eos/build/programs/cleos$  ./cleos push action eosio.token issue '[ "user", "100.0000 EOS", "memo" ]' -p eosio -d -j{
  "expiration": "2018-04-02T08:12:50",
  "region": 0,
  "ref_block_num": 2718,
  "ref_block_prefix": 2053470162,
  "net_usage_words": 21,
  "kcpu_usage": 1000,
  "delay_sec": 0,
  "context_free_actions": [],
  "actions": [{
      "account": "eosio.token",
      "name": "issue",
      "authorization": [{
          "actor": "eosio",
          "permission": "active"
        }
      ],
      "data": "00000000007015d640420f000000000004454f5300000000046d656d6f"
    }
  ],
  "signatures": [
    "EOSJvRYs9TqrTNRx1B5RfLjiyUT8Hcsrt2krDDvocgUKbsMVStEP3dzzCEQmGQjDwMpfRcKDjLbb7GJSA8ksCvnMDzdUz2AE1"
  ],
  "context_free_data": []

转账

feng@feng-B250-HD3P:~/workSpace/eos/build/programs/cleos$ ./cleos push action eosio.token issue '[ "user", "100.0000 EOS", "memo" ]' -p eosio
executed transaction: 75bdcd8b3f4eeb0dbdd1135a4d20b249edbed3fda9c5baaaefe7106799ea3a74  268 bytes  1000 cycles
#   eosio.token <= eosio.token::issue           {"to":"user","quantity":"100.0000 EOS","memo":"memo"}
>> issue
#   eosio.token <= eosio.token::transfer        {"from":"eosio","to":"user","quantity":"100.0000 EOS","memo":"memo"}
>> transfer
#         eosio <= eosio.token::transfer        {"from":"eosio","to":"user","quantity":"100.0000 EOS","memo":"memo"}
#          user <= eosio.token::transfer        {"from":"eosio","to":"user","quantity":"100.0000 EOS","memo":"memo"}

修改合约,注意这里创建的所有账号的key,均来自create ./cleos create key

feng@feng-B250-HD3P:~/workSpace/eos/build/programs/cleos$ ./cleos create account eosio ex EOS5a7fk4RAQ2fzdWy5TTRdhmcHpZQxwyoLqvczQHhpcGSjoFdSkK EOS5a7fk4RAQ2fzdWy5TTRdhmcHpZQxwyoLqvczQHhpcGSjoFdSkK
executed transaction: 53d9e24496a4f031bea80a605d3ab1a86ba201f7f3cc2ab6dc56da20bb2f59c9  364 bytes  1000 cycles
#         eosio <= eosio::newaccount            {"creator":"eosio","name":"ex","owner":{"threshold":1,"keys":[{"key":"EOS5a7fk4RAQ2fzdWy5TTRdhmcHpZQ...
feng@feng-B250-HD3P:~/workSpace/eos/build/programs/cleos$ ./cleos set contract ex ../../contracts/exchange -p ex
Reading WAST...
Assembling WASM...
Publishing contract...
executed transaction: dd5b6cbb29400006157df7e0af8eec026a3ddd0ea71a3aea018a5a5f868a0be8  35180 bytes  10000 cycles
#         eosio <= eosio::setcode               {"account":"ex","vmtype":0,"vmversion":0,"code":"0061736d0100000001f0023460067f7e7f7f7f7f0060037f7e7...
#         eosio <= eosio::setabi                {"account":"ex","abi":{"types":[{"new_type_name":"account_name","type":"name"}],"structs":[{"name":"...

EOS区块链qq群,欢迎大家多多技术交流:695283188



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值