关于抵押和赎回的方法,拿eosjs举例
https://eosio.github.io/eosjs/guides/2.-Transaction-Examples.html
Stake 抵押
const result = await api.transact({
actions: [{
account: 'eosio',
name: 'delegatebw',
authorization: [{
actor: 'useraaaaaaaa',
permission: 'active',
}],
data: {
from: 'useraaaaaaaa',
receiver: 'useraaaaaaaa',
stake_net_quantity: '1.0000 SYS',
stake_cpu_quantity: '1.0000 SYS',
transfer: false,
}
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
});
Unstake 赎回
const result = await api.transact({
actions: [{
account: 'eosio',
name: 'undelegatebw',
authorization: [{
actor: 'useraaaaaaaa',
permission: 'active',
}],
data: {
from: 'useraaaaaaaa',
receiver: 'useraaaaaaaa',
unstake_net_quantity: '1.0000 SYS',
unstake_cpu_quantity: '1.0000 SYS',
transfer: false,
}
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
});
操作细节看以上demo即可,下面我们说下抵押时transfer
这个参数。
先看合约 (跳转代码)
if ( transfer ) {
from = receiver;
}
如果设置transfer
参数为true
,及把来源的账户修改为接收账户。
也就变成了接收账户自己给自己抵押,由来源账户付钱
查看数据
(查看代码)
抵押数据表明为delband
(查看代码)
del_bandwidth_table del_tbl( _self, from.value );
是以来源账户为查询的scope
所以RPC查询如下
post: https://api.eoslaomao.com/v1/chain/get_table_rows
data:
{
"scope": "bcskillsurou",
"code": "eosio",
"table": "delband",
"json": true
}
返回
{
"rows": [
{
"from": "bcskillsurou",
"to": "bcskillsurou",
"net_weight": "0.0046 EOS",
"cpu_weight": "0.0147 EOS"
}
],
"more": false
}