重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
交易所通过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()
};
看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注创新互联行业资讯频道,感谢您对创新互联的支持。