Not the same private key when signing transaction? - "Some inputs have not been fully signed"

Hi, I’m trying to send some satoshis from an address I derived from an HDPrivateKey. But, the transaction is not signed and I get an error when trying to serialize it. Can anyone help me see what’s wrong here?

var HDPrivateKey = bitcore.HDPrivateKey,
Address = bitcore.Address,
Networks = bitcore.Networks,
Transaction = bitcore.Transaction,
UnspentOutput = bitcore.Transaction.UnspentOutput;

var hdPrivateKey = new HDPrivateKey(“specific key”).derive(0),
hdPublicKey = hdPrivateKey.hdPublicKey;

var firstAddress = new Address(hdPublicKey.publicKey, Networks.livenet),
secondAddress = new Address(hdPublicKey.publicKey, Networks.livenet);

var utxo = new UnspentOutput({
“txid” : “specific txid”,
“vout” : 0,
“address” : firstAddress.toString(),
“scriptPubKey” : “76a914087ddee66b47723d8fb865ef9b025869bead531488ac”,
“satoshis” : 97380

var fee = 5430;

var tx = new Transaction()
.to(“198Z9wd57VZiK54VT7MtGKswfjPuyQTHey”, utxo.satoshis-fee)

console.log("PrivateKey generates address in utxo: " + (firstAddress.toString() === new Address(hdPrivateKey.publicKey, Networks.livenet).toString()) )
console.log("transaction verified: "+tx.verify() );
console.log("Signature correct: "+tx.isFullySigned());

So, I’m thinking that since I used hdPrivateKey to create a public key, from which to create the address which has the unspent output, it should be this key to sign the transaction. But, it’s not working. Can anyone see why?

I got the transaction id and the script from’s site following this link (but with another address). I have tried using both tx_hash and tx_hash_big_endian as values for txid.

I get this error message from running tx.serialize():

throw serializationError;
Some inputs have not been fully signed
at Error.NodeError (/home/bob/Workspace/bitcore/node_modules/bitcore-lib/lib/errors/index.js:20:41)
at Transaction._isMissingSignatures (/home/bob/Workspace/bitcore/node_modules/bitcore-lib/lib/transaction/transaction.js:268:12)
at Transaction.getSerializationError (/home/bob/Workspace/bitcore/node_modules/bitcore-lib/lib/transaction/transaction.js:211:10)
at Transaction.checkedSerialize (/home/bob/Workspace/bitcore/node_modules/bitcore-lib/lib/transaction/transaction.js:166:33)
at Transaction.serialize (/home/bob/Workspace/bitcore/node_modules/bitcore-lib/lib/transaction/transaction.js:150:17)
at Object. (/home/bob/Workspace/bitcore/test.js:45:16)
at Module._compile (module.js:556:32)
at Object.Module._extensions…js (module.js:565:10)
at Module.load (module.js:473:32)
at tryModuleLoad (module.js:432:12)

I got it working! The error was probably because I got something wrong from the transaction.

I got the utxo from Insight, that was described in a very good video here.

 var Insight = require('bitcore-explorers').Insight;
 var insight = new Insight('testnet');

 insight.getUnspentUtxos(address, function(err, utxos){
     var satoshisOwned = utxos[0].toObject().amount * 100000000,
         fee = 15000;
     var tx = bitcore.Transaction();
     tx.from(utxos);, satoshisOwned-fee);
         insight.broadcast(tx, function(err, returnedTxId){
         console.log("succesful broadcast: " + returnedTxId)

Once I got the utxos this way, everything worked fine.