分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 软件开发

web3js 进行转账

发布时间:2023-09-06 02:23责任编辑:胡小海关键词:js
const Web3 = require(‘web3‘)const EthereumTx = require(‘ethereumjs-tx‘)const web3 = new Web3( new Web3.providers.HttpProvider(‘http://localhost:8145‘) )web3.eth.defaultAccount = ‘af7574a21729d22e119df7456bf913194d73c209‘const amountToSend = 0.00100000let details = { ???"to": ‘0x5cf83df52a32165a7f392168ac009b168c9e8915‘, ???"value": 998100000, ???"gas": 21000, ???"gasPrice": 50 * 1000000000, ????"nonce": 11, ???"chainId": 11243575 ??}var tx = new EthereumTx(details)tx.sign( Buffer.from(‘FC1A5C66932BD7C93E05661A58FD534967739CE517D8695EBBE89135CEE78DA4‘, ‘hex‘) )var serializedTx = tx.serialize();web3.eth.sendSignedTransaction(‘0x‘ + serializedTx.toString(‘hex‘)).on(‘receipt‘, console.log);

  

输出输出:

Promise {
?<pending>,
?_events: { receipt: EE { fn: [Function: bound ], context: [Circular], once: false } },
?emit: [Function: emit],
?on: [Function: on],
?once: [Function: once],
?off: [Function: removeListener],
?listeners: [Function: listeners],
?addListener: [Function: on],
?removeListener: [Function: removeListener],
?removeAllListeners: [Function: removeAllListeners] }

输出(这里等待了很长时间):

{ blockHash: ‘0x7a0f412ba0b09dfcfacb826712f4b8e5089e8d1c6d35385d2e29d5dc4400ab37‘,
?blockNumber: 155425,
?contractAddress: null,
?cumulativeGasUsed: 63000,
?from: ‘0xaf7574a21729d22e119df7456bf913194d73c209‘,
?gasUsed: 21000,
?logs: [],
?logsBloom: ‘0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000‘,
?status: true,
?to: ‘0x5cf83df52a32165a7f392168ac009b168c9e8915‘,
?transactionHash: ‘0x6030b35f4d948a83370d0a759be98820eb72d94623e9d9063fabaab4a9543aed‘,
?transactionIndex: 2 }

web3js 进行转账

原文地址:https://www.cnblogs.com/freebird92/p/10001039.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved