bitcore-lib icon indicating copy to clipboard operation
bitcore-lib copied to clipboard

How to create a transaction -- what is the txId?

Open Eithcowich opened this issue 6 years ago • 2 comments

I'm looking at the code in your examples.md document and have a couple of questions.

  1. Is the string inside the PrivateKey('...') an actual private key string?

  2. Where do you get the txId from? This transaction has not yet been processed so shouldn't have an id yet.

  3. What is the script? How do I get it?

This is the code from the examples doc:

var privateKey = new 
bitcore.PrivateKey('L1uyy5qTuGrVXrmrsvHWHgVzW9kKdrp27wBC7Vs6nZDTF2BRUVwy');
var utxo = {
    "txId" : "115e8f72f39fad874cfab0deed11a80f24f967a84079fb56ddf53ea02e308986",
    "outputIndex" : 0,
    "address" : "17XBj6iFEsf8kzDMGQk5ghZipxX49VXuaV",
    "script" : "76a91447862fe165e6121af80d5dde1ecb478ed170565b88ac",
    "satoshis" : 50000
};

var transaction = new bitcore.Transaction()
  .from(utxo)
  .to('1Gokm82v6DmtwKEB8AiVhm82hyFSsEvBDK', 15000)
  .sign(privateKey);

Eithcowich avatar Sep 03 '18 13:09 Eithcowich

I have been use this method but it gives me an error. What will be wrong by me in this method?

TypeError: Object is not a valid argument for 'instanceof' (evaluating 'from instanceof Address')

Sidhesh009 avatar Oct 30 '18 06:10 Sidhesh009

@Eithcowich

  1. Yes. That is the private key. In that particular example it is in WIF format. You can google for specs. Hex and Buffer is also supported.

  2. TxID is a hash of the transaction data, it is obtainable once the transaction data is complete, even before broadcasting it.

  3. You mean script at the UTXO? The utxo's are the fund the TX is trying to spend. All utxos have an script that, when jointed with the spending transaction's scriptSig, need to be evaluated to true in order for the spending TX to be valid.

When you .sign the TX, the scriptSig of the spending TX is created.

matiu avatar Oct 31 '18 16:10 matiu