搭建测试节点 - Docker
创建本地文件夹 /home/xxx/contracts, 以后的 CONTRACTS_DIR 都指的是这个地址
使用全路径替换 Docker 启动脚本
1 |
|
检验安装结果
1 | docker logs --tail 10 eosio |
创建快捷脚本, 注意使用 source 使之生效
1 | 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' |
安装合约编译环境
下载代码
1 | git clone --recursive https://github.com/eosio/eosio.cdt |
创建测试账号
首先创建默认钱包的密码
1 | # 这里就使用了前面定义的别名 cleos |
1 | Creating wallet: default |
1 | Creating wallet: tokiyotomare |
查看钱包是否创建
1 | cleos wallet open [-n tokiyotomare] |
创建 key
1 | cleos wallet create_key |
1 | Created new private key with a public key of: "EOS7athvxS527mUALbh6RP332SYqS3zVeEyk5m7YT7ty6RRhMGA3L" |
导入共有测试钱包私钥
1 | cleos wallet import |
输入共用私钥: 5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3
1 | private key: imported private key for: EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV |
创建账号
1 | cleos create account eosio ono EOS7athvxS527mUALbh6RP332SYqS3zVeEyk5m7YT7ty6RRhMGA3L |
1 | executed transaction: 06d63c647e673094624d6f579cca49ffe7f1202cca8651b551399736da76d876 200 bytes 1763 us |
执行合约部署的资金
创建一个 token 管理账户
1 | cleos create account eosio eosio.token EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV |
编译安装 token 合约
1 | cd ${CONTRACTS_DIR} |
1 | Reading WASM from /Users/admin/Projects/eos-path/contracts/eosio.contracts/eosio.token/eosio.token.wasm... |
创建一个 token
1 | cleos push action eosio.token create '[ "eosio", "1000000000.0000 SYS"]' -p eosio.token@active |
1 | executed transaction: 4dfff899bc528f9c4d8a95453db6eb1e9681db0ebb53eed9c7bf3bc4b6458fb1 120 bytes 4302 us |
转账给指定账户
1 | cleos push action eosio.token issue '[ "ono", "100.0000 SYS", "memo" ]' -p eosio@active -j |
账户之间转移
1 | cleos push action eosio.token transfer '[ "from", "to", "25.0000 SYS", "memo" ]' -p from@active |
1 | executed transaction: 7ecb5dbaec5a46d16f6245d0fe2925f68d5d2d3b4522965f4ba1e70e385f965a 136 bytes 2801 us |
检查账户资产
1 | cleos get currency balance eosio.token ono SYS |
搞一个小合约玩儿一下
进入 ${CONTRACTS_DIR} 目录创建 hello 文件夹:
编辑文件 hello.cpp
:
1 |
|
编译 c++ 代码:
1 | eosio-cpp -o hello.wasm hello.cpp --abigen |
为新项目创建一个账户:
1 | cleos create account eosio hello EOS7athvxS527mUALbh6RP332SYqS3zVeEyk5m7YT7ty6RRhMGA3L -p eosio@active |
推送代码到服务器
1 | cleos set contract hello ${CONTRACTS_DIR}/hello -p hello@active |
调用合约
1 | cleos push action hello hi '["ono"]' -p ono@active |
改动代码后, 需要重复调用上面两步, 推送和调用 => 是不是应该写一个自动化脚本?!~
摇色子合约
If you use diceUser permission to call action in contractA, and in the action you use inline_action_sender to call action in contractB, the contractB does not receive the diceUser permission. Instead it is use contractB’s owner and permission “eosio.code” to call action in contractB.
To allow contractB to use diceUser’s permission, you can configure diceUser’s permission to allow contractB owner and permission eosio.code to have diceUser’s active permission.
1 | cleos set account permission 用户账号名 active '{"threshold":1, "keys":[{"key":"用户账号 publickey", "weight":1}], "accounts": [{"permission":{"actor":"合约 B 的创建账户名","permission":"eosio.code"},"weight":1}]}' owner -p 用户账号名 |
1 | cleos set account permission ono active '{"threshold":1, "keys":[{"key":"EOS7athvxS527mUALbh6RP332SYqS3zVeEyk5m7YT7ty6RRhMGA3L", "weight":1}], "accounts": [{"permission":{"actor":"dice","permission":"eosio.code"},"weight":1}]}' owner -p ono |