首先,目前dawn-4.1, dawn-4.2使用inline action是会报错的

transaction declares authority '{"actor":"hello.code","permission":"active"}', but does not have signatures for it under a provided delay of 0 ms

这个是4.0以后inline action的权限发生变化。这个改动在eos官网的\#3013([https://github.com/EOSIO/eos/issues/3013](https://github.com/EOSIO/eos/issues/3013))这个issue讨论话题,BM有提到过


核心是添加eosio.code permission,比如hello.code调用hello.target智能合约,需要添加如下permission

cleos set account permission args.user active '{"threshold": 1,"keys": [{"key":"EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", "weight":1}],"accounts": [{"permission":{"actor":"hello.code","permission":"eosio.code"},"weight":1}]}' owner -p args.user@owner

代码

新建两个contract: hello.code和hello.target

hello.target代码如下

hello.code的代码:

核心就是上面的红色字体的内容action(xx).send(),具体参数的含义是:

Action(permssion_level, other_contract_account_name, method, args)

所以:

action(permission_level{to, N(active)},

N(hello.target), N(callme),

std::make_tuple(to)

).send();

这个等价于如下命令

$cleos push action hello.targetcallme '["to"]' -p to

编译

请参考我的博文【EOS编写HelloWorld智能合约

测试

$cleos create account eosio hello.code $KEY_PUB_1 $KEY_PUB_1

$cleos set contract hello.code ./hello -p hello.code

$cleos create account eosio args.user $KEY_PUB_2 $KEY_PUB_2

$cleos create account eosio hello.target $KEY_PUB_3 $KEY_PUB_3

$cleos create account eosio args.user1 $KEY_PUB_4 $KEY_PUB_4

$cleos set contract hello.target ./hello.target -p hello.target

$cleos set account permission args.user1 active '{"threshold": 1,"keys": [],"accounts": [{"permission":{"actor":"hello.code","permission":"eosio.code"},"weight":1}]}' owner -p args.user1@owner

$cleos push action hello.code hi '["args.user", "args.user1"]' -p args.user

源码一键实践

从以下github网页下载源码,即可一键实践执行该智能合约

https://github.com/itleaks/eos-contract/tree/master/callcontract-exp/

results matching ""

    No results matching ""