本篇文章為大家展示了nodejs開(kāi)發(fā)EOS轉(zhuǎn)賬服務(wù)的兩種方案分別是什么,內(nèi)容簡(jiǎn)明扼要并且容易理解,絕對(duì)能使你眼前一亮,通過(guò)這篇文章的詳細(xì)介紹希望你能有所收獲。
創(chuàng)新互聯(lián)公司是一家專注于網(wǎng)站制作、成都網(wǎng)站制作與策劃設(shè)計(jì),晉城網(wǎng)站建設(shè)哪家好?創(chuàng)新互聯(lián)公司做網(wǎng)站,專注于網(wǎng)站建設(shè)10余年,網(wǎng)設(shè)計(jì)領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:晉城等地區(qū)。晉城做網(wǎng)站價(jià)格咨詢:18982081108
第一種,使用eosjs開(kāi)發(fā),適用于用戶輸入私鑰方式,不安全,易造成私鑰泄露。
const rpcUrl = 'http://jungle2.cryptolions.io:80' const { Api, JsonRpc, RpcError, JsSignatureProvider } = require('eosjs'); const ecc = require('eosjs-ecc'); const fetch = require('node-fetch'); const { TextDecoder, TextEncoder } = require('text-encoding'); const rpc = new JsonRpc(rpcUrl, { fetch }); //轉(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); };
第二種,使用nodeos api+wallet api開(kāi)發(fā),適合用于公共賬戶給不同用戶轉(zhuǎn)賬。相當(dāng)于用wallet錢(qián)包服務(wù)來(lái)做密鑰管理,隱藏了私鑰,代碼中只需提供公鑰和錢(qián)包服務(wù)地址即可。
async function transfer() { try { let actor = "eosaccountaa" let transferTo = "eosaccountbb" let quantity = "1.1234 EOS" let memo = "hi heere" let blocksBehind = 3 let expireSeconds = 100 let info = await rpc.get_info(); if (info != null && info.chain_id != null && info.head_block_num != null) { let chain_id = info.chain_id; let head_block_num = info.head_block_num - blocksBehind; let block = await get_block(head_block_num); if (block != null && block.ref_block_prefix != null && block.timestamp != null) { let data = await abi_json_to_bin(actor, transferTo, quantity, memo) if (data != null) { let transactions = { "max_net_usage_words": 0, "max_cpu_usage_ms": 0, "delay_sec": 0, "context_free_actions": [], "actions": [{ "account": "eosio.token", "name": "transfer", "authorization": [{ "actor": actor, "permission": "active" }], "data": data }], "transaction_extensions": [], "expiration": ser.timePointSecToDate(ser.dateToTimePointSec(block.timestamp) + expireSeconds), "ref_block_num": block.block_num & 0xffff, "ref_block_prefix": block.ref_block_prefix }; let signTransaction = await sign_transaction(transactions, ["EOS61VncKc7P8MhKzz8K7s3kAeNxFsp5ZQGoVFbLjRh2NVR1B6D9Z"], chain_id); if (signTransaction != null && signTransaction.signatures != null) { var transaction_detail = await push_transaction(transactions, signTransaction.signatures); console.log('push_transaction=transaction_id==' + transaction_detail.transaction_id); } } } } } catch (e) { console.log(e) } }
上述內(nèi)容就是nodejs開(kāi)發(fā)EOS轉(zhuǎn)賬服務(wù)的兩種方案分別是什么,你們學(xué)到知識(shí)或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識(shí)儲(chǔ)備,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。