Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

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

Open
Eithcowich opened this issue Sep 3, 2018 · 2 comments
Open

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

Eithcowich opened this issue Sep 3, 2018 · 2 comments

Comments

@Eithcowich
Copy link

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);
@Sidhesh009
Copy link

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')

@matiu
Copy link
Contributor

matiu commented Oct 31, 2018

@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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants