What are the two schemes for nodejs to develop EOS transfer service?
This article shows you what are the two solutions for nodejs to develop EOS transfer service, which are concise and easy to understand, which will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
First, the use of eosjs development, suitable for users to enter the private key, insecure, easy to cause private key disclosure.
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}); / / transfer operation to account accountName' eosaccountb2' Transfer amount 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, / / withdrawal address quantity: quantity / / number of withdrawals memo:'',},}]}, {blocksBehind: 3, expireSeconds: 30,}) Console.dir (result);}
The second is developed using nodeos api+wallet api, which is suitable for public accounts to transfer money to different users. Equivalent to using wallet wallet service to do key management, hiding the private key, the code only needs to provide the public key and wallet service address.
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)}} what are the two solutions for nodejs to develop EOS money transfer service? have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.