web3.eth.sendRawTransaction

若是你但願立刻開始學習以太坊DApp開發,能夠訪問匯智網提供的出色的在線互動教程:git

發送一個已經簽名的交易。好比能夠用下述簽名的例子github

若是交易是一個合約建立,請使用web3.eth.getTransactionReceipt()在交易完成後獲取合約的地址。web

調用:異步

web3.eth.sendRawTransaction(signedTransactionData [, callback])

參數:函數

  • signedTransacionData: String - 16進制格式的簽名交易數據。
  • callback: Function - 回調函數,用於支持異步的方式執行7。

返回值:學習

  • String - 32字節的16進制格式的交易哈希串。

示例:ui

var Tx = require('ethereumjs-tx');
var privateKey = new Buffer('e331b6d69882b4cb4ea581d88e0b604039a3de5967688d3dcffdd2270c0fd109', 'hex')

var rawTx = {
  nonce: '0x00',
  gasPrice: '0x09184e72a000', 
  gasLimit: '0x2710',
  to: '0x0000000000000000000000000000000000000000', 
  value: '0x00', 
  data: '0x7f7465737432000000000000000000000000000000000000000000000000000000600057'
}

var tx = new Tx(rawTx);
tx.sign(privateKey);

var serializedTx = tx.serialize();

//console.log(serializedTx.toString('hex'));
//0xf889808609184e72a00082271094000000000000000000000000000000000000000080a47f74657374320000000000000000000000000000000000000000000000000000006000571ca08a8bbf888cfa37bbf0bb965423625641fc956967b81d12e23709cead01446075a01ce999b56a8a88504be365442ea61239198e23d1fce7d00fcfc5cd3b44b7215f

web3.eth.sendRawTransaction(serializedTx.toString('hex'), function(err, hash) {
  if (!err)
    console.log(hash); // "0x7f9fade1c0d57a7af66ab4ead79fade1c0d57a7af66ab4ead7c2c2eb7b11a91385"
});
相關文章
相關標籤/搜索