web3js 进行转账

Posted 心飞翔<

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了web3js 进行转账相关的知识,希望对你有一定的参考价值。

 

 

 

 

 

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.00100000

let 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 进行转账的主要内容,如果未能解决你的问题,请参考以下文章

springboot操作以太坊(eth),使用web3j,转账等

web3js 支持比特币吗

web3Transaction 转账

本地链使用web3js发送签名交易

使用Java+Web3j和Ethereum网络交互:获取Ethereum信息

以太坊/BSC 区块链交易数据

(c)2006-2024 SYSTEM All Rights Reserved IT常识