function serializeTx(txObj) {
  var serializedTx = '';
  var _buf16 = Buffer.alloc(4);

  // Version
  _buf16.writeUInt16LE(txObj.version, 0);
  serializedTx += _buf16.toString('hex');

  // History
  serializedTx += zbufferutils.numToVarInt(txObj.ins.length);
  txObj.ins.map(function (i) {
    // Txids and vouts
    _buf16.writeUInt16LE(i.output.vout, 0);
    serializedTx += Buffer.from(i.output.hash, 'hex').reverse().toString('hex');
    serializedTx += _buf16.toString('hex');

    // Script Signature
    // Doesn't work for length > 253 ....
    serializedTx += zbufferutils.getPushDataLength(i.script);
    serializedTx += i.script;

    // Sequence
    serializedTx += i.sequence;
  });

  // Outputs
  serializedTx += zbufferutils.numToVarInt(txObj.outs.length);
  txObj.outs.map(function (o) {
    // Write 64bit buffers
    // JS only supports 56 bit
    // https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/src/bufferutils.js#L25
    var _buf32 = Buffer.alloc(8);

    // Satohis
    _buf32.writeInt32LE(o.satoshis & -1, 0);
    _buf32.writeUInt32LE(Math.floor(o.satoshis / 0x100000000), 4);

    // ScriptPubKey
    serializedTx += _buf32.toString('hex');
    serializedTx += zbufferutils.getPushDataLength(o.script);
    serializedTx += o.script;
  });

  // Locktime
  _buf16.writeUInt16LE(txObj.locktime, 0);
  serializedTx += _buf16.toString('hex');

  return serializedTx;
}
function serializeTx(txObj) {
  var serializedTx = '';
  var _buf16 = Buffer.alloc(4);

  
  _buf16.writeUInt16LE(txObj.version, 0);
  serializedTx += _buf16.toString('hex');

  
  serializedTx += zbufferutils.numToVarInt(txObj.ins.length);
  txObj.ins.map(function (i) {
    
    _buf16.writeUInt16LE(i.output.vout, 0);
    serializedTx += Buffer.from(i.output.hash, 'hex').reverse().toString('hex');
    serializedTx += _buf16.toString('hex');

    
    
    serializedTx += zbufferutils.getPushDataLength(i.script);
    serializedTx += i.script;

    
    serializedTx += i.sequence;
  });

  
  serializedTx += zbufferutils.numToVarInt(txObj.outs.length);
  txObj.outs.map(function (o) {
    
    
    
    var _buf32 = Buffer.alloc(8);

    
    _buf32.writeInt32LE(o.satoshis & -1, 0);
    _buf32.writeUInt32LE(Math.floor(o.satoshis / 0x100000000), 4);

    
    serializedTx += _buf32.toString('hex');
    serializedTx += zbufferutils.getPushDataLength(o.script);
    serializedTx += o.script;
  });

  
  _buf16.writeUInt16LE(txObj.locktime, 0);
  serializedTx += _buf16.toString('hex');

  return serializedTx;
}
function serializeTx ( txObj ) { var serializedTx = '' ; var _buf16 = Buffer . alloc ( 4 ) ; // Version _buf16 . writeUInt16LE ( txObj . version , 0 ) ; serializedTx += _buf16 . toString ( 'hex' ) ; // History serializedTx += zbufferutils . numToVarInt ( txObj . ins . length ) ; txObj . ins . map ( function ( i ) { // Txids and vouts _buf16 . writeUInt16LE ( i . output . vout , 0 ) ; serializedTx += Buffer . from ( i . output . hash , 'hex' ) . reverse ( ) . toString ( 'hex' ) ; serializedTx += _buf16 . toString ( 'hex' ) ; // Script Signature // Doesn't work for length > 253 .... serializedTx += zbufferutils . getPushDataLength ( i . script ) ; serializedTx += i . script ; // Sequence serializedTx += i . sequence ; } ) ; // Outputs serializedTx += zbufferutils . numToVarInt ( txObj . outs . length ) ; txObj . outs . map ( function ( o ) { // Write 64bit buffers // JS only supports 56 bit // https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/src/bufferutils.js#L25 var _buf32 = Buffer . alloc ( 8 ) ; // Satohis _buf32 . writeInt32LE ( o . satoshis & - 1 , 0 ) ; _buf32 . writeUInt32LE ( Math . floor ( o . satoshis / 0x100000000 ) , 4 ) ; // ScriptPubKey serializedTx += _buf32 . toString ( 'hex' ) ; serializedTx += zbufferutils . getPushDataLength ( o . script ) ; serializedTx += o . script ; } ) ; // Locktime _buf16 . writeUInt16LE ( txObj . locktime , 0 ) ; serializedTx += _buf16 . toString ( 'hex' ) ; return serializedTx ; }
/*
Serializes a TXOBJ into hex string
@param {Object} txObj
return {String} hex string of txObj
/ * Serializes a TXOBJ into hex string