Advertisement
Guest User

Untitled

a guest
Mar 7th, 2019
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. const Client = require('bitcoin-core');
  2. const bitcore = require('bitcore-lib');
  3. const client = new Client({
  4. network: 'regtest',
  5. username: 'bitcoinuser',
  6. password: 'bitcoinpass',
  7. port: 18443
  8. });
  9.  
  10. var tx = new bitcore.Transaction();
  11.  
  12. var sourceAddress = ["mwkT2k1o6k4dF7ZZQ2VBbw7VedBkQA2CBK"];
  13. var minconf = 6;
  14. var maxconf = 999999;
  15. var targetAddress = "2Mw3iwZdVXjeb7BN5hWqegFs8VdfZo5Rmdo";
  16. var privateKey = "cQqVxdtPz95monJe8QJUE4h5JVtSSAjTQ1SU6z8PL9pmFj5V7ieA";
  17.  
  18. var txns = [];
  19. client.listUnspent(minconf, maxconf, sourceAddress)
  20. .then(function(help){
  21. txns = help.slice();
  22. return txns;
  23. }).then(function(txns){
  24. return tx.from(txns).to(targetAddress, 15000).sign(privateKey);
  25. }).then(function(result){
  26. console.log(result);
  27. });
  28.  
  29. Transaction {
  30. inputs:
  31. [ PublicKeyInput {
  32. witnesses: [],
  33. output:
  34. Output {
  35. _satoshisBN:
  36. BN { negative: 0, words: [ 16972032, 37 ], length: 2, red: null
  37. },
  38. _satoshis: 2500000000,
  39. _scriptBuffer:
  40. <Buffer 21 02 0b 0f c0 79 9d 39 8d 83 be 39 08 2c 72 49 0a 57 00 0e c2 f5 e0 01 ab a1 ee 9b 07 19 cc bd fb e3 ac>,
  41. _script:
  42. Script {
  43. chunks:
  44. [ { buf:
  45. <Buffer 02 0b 0f c0 79 9d 39 8d 83 be 39 08 2c 72 49 0a 57 00 0e c2 f5 e0 01 ab a1 ee 9b 07 19 cc bd fb e3>,
  46. len: 33,
  47. opcodenum: 33 },
  48. { opcodenum: 172 } ],
  49. _isOutput: true } },
  50. prevTxId:
  51. <Buffer e1 45 8a fb cd df 9b 8b aa 4c a7 a0 13 b7 f6 d3 91 87 8f a3 02 94 78 92 ef 59 03 0e 40 f5 51 00>,
  52. outputIndex: 0,
  53. sequenceNumber: 4294967295,
  54. _script: Script { chunks: [], _isInput: true },
  55. _scriptBuffer: <Buffer > },
  56. PublicKeyInput {
  57. witnesses: [],
  58. output:
  59. Output {
  60. _satoshisBN:
  61.  
  62. let txSerialized = transaction.serialize(true);
  63.  
  64. client.sendRawTransaction(txSerialized, (error, response) => { if (error) console.log(error); console.log(response); });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement