Skip to content

Instantly share code, notes, and snippets.

@matiu
Last active August 29, 2015 14:14
Show Gist options
  • Save matiu/057cac1e90b8fdd7e5a6 to your computer and use it in GitHub Desktop.
Save matiu/057cac1e90b8fdd7e5a6 to your computer and use it in GitHub Desktop.
var b = require('bitcore');
var priv = new b.PrivateKey();
var pub = new b.PublicKey(priv);
var inputs =
[ { txid: 'e872a0fda0afd0bce31ddfd9229c9eca2a68e4746615b8a0902b7a657b83676d',
vout: 8,
amount: 100,
scriptPubKey: b.Script.buildPublicKeyHashOut(pub).toBuffer().toString('hex') } ] ;
var t = new b.Transaction()
.from(inputs)
.to('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 1000)
.change('3CauZ5JUFfmSAx2yANvCRoNXccZ3YSUjXH');
// 1) toObject does not includes info about change address.
console.log('[UNO]', t.toObject()); //TODO
t.sign(priv);
// 2) here the change address is addded to output
console.log('[DOS]', t.toObject()); //TODO
// Output
/*
[UNO] { version: 1,
inputs:
[ { prevTxId: 'e872a0fda0afd0bce31ddfd9229c9eca2a68e4746615b8a0902b7a657b83676d',
outputIndex: 8,
sequenceNumber: 4294967295,
script: '',
output: [Object] } ],
outputs:
[ { satoshis: 1000,
script: 'OP_DUP OP_HASH160 20 0x51224bca38efcaa31d5340917c3f3f713b8b20e4 OP_EQUALVERIFY OP_CHECKSIG' } ],
nLockTime: 0 }
[DOS] { version: 1,
inputs:
[ { prevTxId: 'e872a0fda0afd0bce31ddfd9229c9eca2a68e4746615b8a0902b7a657b83676d',
outputIndex: 8,
sequenceNumber: 4294967295,
script: '72 0x3045022100c92e0d74614be036bde180a4f67a2c56916b296ed1e48c2ea49c1e8c9fa5d288022055220a8d3151e5107ac9319acffc68fd5f426de992a06f6aa962804bae5bcf8201 33 0x02a76d52997b5414ac8ff58de660bb20fb4fcf918ca70398f0d8165b0fd5989baf',
output: [Object] } ],
outputs:
[ { satoshis: 1000,
script: 'OP_DUP OP_HASH160 20 0x51224bca38efcaa31d5340917c3f3f713b8b20e4 OP_EQUALVERIFY OP_CHECKSIG' },
{ satoshis: 9999989000,
script: 'OP_HASH160 20 0x778192003f0e9e1d865c082179cc3dae5464b03d OP_EQUAL' } ],
nLockTime: 0 }
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment