交易所通过eosjs进行充值与转账的代码片段是怎样的
交易所通过eosjs进行充值与转账的代码片段是怎样的,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。
连了两个远程测试节点
const rpcUrl = 'http://jungle2.cryptolions.io:80'
const actionUrl = 'http://junglehistory.cryptolions.io:18888' //只找到这个测试节点能够提供actions记录
//处理账户交易记录,判断从上一次扫描之后账户新增记录,并根据备注给用户充值
async function dealActions(accountName) {
let rpcH = new JsonRpc(actionUrl, { fetch });
let actionHistory = await rpcH.history_get_actions(accountName);
let latestTime = 'select TRANS_TIME from RECHARGE where IFLAST=yes' //伪代码
for (let i in actionHistory.actions) {
var block_time = actionHistory.actions[i].block_time
if(block_time > latestTime){
let memo = actionHistory.actions[i].action_trace.act.data.memo
let quantity = actionHistory.actions[i].action_trace.act.data.quantity
let from = actionHistory.actions[i].action_trace.act.data.from
let to = actionHistory.actions[i].action_trace.act.data.to
let trx_id = actionHistory.actions[i].action_trace.trx_id
let global_action_seq = actionHistory.actions[i].global_action_seq
let block_num = actionHistory.actions[i].block_num
let producer_block_id = actionHistory.actions[i].producer_block_id
//let to = actionHistory.actions[i].action_trace.act.data.to
console.log('memos'+i+'='+memo)
//insert into RECHARGE values() //插入充值表
//update USER_ACCOUNT set BALANCE AVAILABLE_BALANCE where USER_ID = 0 //更新账户
}
};
return actionHistory
}
//转账操作 转账到账户accountName 'eosaccountb2';转账数额quantity '1.1234 EOS'
async function transfer(accountName,quantity) {
let signatureProvider = new JsSignatureProvider([pkeys[0].privateKey]);
let api = new Api({ rpc, signatureProvider, textDecoder: new TextDecoder(), textEncoder: new TextEncoder() });
let result = await api.transact({
actions: [{
account: 'eosio.token',
name: 'transfer',
authorization: [{
actor: pkeys[0].actor,
permission: 'active',
}],
data: {
from: pkeys[0].actor,
to: accountName, //提现地址
quantity: quantity, //提现数量
memo: '',
},
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
});
console.dir(result);
let transaction_id = result.transaction_id
let receipt= result.processed.receipt //抵押的net和cpu,记到数据库备份
console.log('receipt===='+JSON.stringify(receipt))
//insert into WITHDRAW()
};
看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注蜗牛博客行业资讯频道,感谢您对蜗牛博客的支持。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:niceseo99@gmail.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。
评论