bitcore-lib
bitcore-lib copied to clipboard
How to create a transaction -- what is the txId?
I'm looking at the code in your examples.md
document and have a couple of questions.
-
Is the string inside the
PrivateKey('...')
an actual private key string? -
Where do you get the
txId
from? This transaction has not yet been processed so shouldn't have an id yet. -
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);
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')
@Eithcowich
-
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.
-
TxID is a hash of the transaction data, it is obtainable once the transaction data is complete, even before broadcasting it.
-
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 totrue
in order for the spending TX to be valid.
When you .sign
the TX, the scriptSig
of the spending TX is created.