之前看了eosio.token的代码,是一个可以发布多个代币的合约。
simple.token只能发布自己的代币。
前提三个账户,aiguo usr1 usr2
$eosiocpp -g simple.token.abi simple.token.cpp
$eosiocpp -o simple.token.wast simple.token.cpp
$cleos set contract aiguo simple.token/ -p aiguo
$cleos push action aiguo issue '["aiguo" , 100]' -p aiguo
$ cleos push action aiguo issue '["usr1",100]' -p aiguo
$cleos push action aiguo transfer '["aiguo", "usr2", 50]' -p aiguo
$cleos push action aiguo transfer '["usr1", "usr2", 50]' -p usr1
$cleos get table aiguo aiguo accounts
{
"rows": [{
"owner": "aiguo",
"balance": 50
},{
"owner": "usr1",
"balance": 50
},{
"owner": "usr2",
"balance": 100
}
],
"more": false
}
注意:
1.编译abi文件,注意需要将table和action加上注释,否则可能编不出abi文件
//@abi table accounts i64
struct account {
account_name owner;
uint64_t balance;
uint64_t primary_key()const { return owner; }
};
2.update contract的时候需要abi和wast文件都有改动才能update
例如在我添加table注释后,又在类中添加了一个成员变量(无用),
之后:$cleos set contract aiguo simple.token/ -p aiguo