您好,登錄后才能下訂單哦!
交易所通過eosjs進(jìn)行充值與轉(zhuǎn)賬的代碼片段是怎樣的,很多新手對此不是很清楚,為了幫助大家解決這個難題,下面小編將為大家詳細(xì)講解,有這方面需求的人可以來學(xué)習(xí)下,希望你能有所收獲。
連了兩個遠(yuǎn)程測試節(jié)點(diǎn)
const rpcUrl = 'http://jungle2.cryptolions.io:80'
const actionUrl = 'http://junglehistory.cryptolions.io:18888' //只找到這個測試節(jié)點(diǎn)能夠提供actions記錄
//處理賬戶交易記錄,判斷從上一次掃描之后賬戶新增記錄,并根據(jù)備注給用戶充值
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
}
//轉(zhuǎn)賬操作 轉(zhuǎn)賬到賬戶accountName 'eosaccountb2';轉(zhuǎn)賬數(shù)額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, //提現(xiàn)地址
quantity: quantity, //提現(xiàn)數(shù)量
memo: '',
},
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
});
console.dir(result);
let transaction_id = result.transaction_id
let receipt= result.processed.receipt //抵押的net和cpu,記到數(shù)據(jù)庫備份
console.log('receipt===='+JSON.stringify(receipt))
//insert into WITHDRAW()
};
看完上述內(nèi)容是否對您有幫助呢?如果還想對相關(guān)知識有進(jìn)一步的了解或閱讀更多相關(guān)文章,請關(guān)注億速云行業(yè)資訊頻道,感謝您對億速云的支持。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。