1

I've been trying to transfer BTC to another address but can't seem to get the transaction right.

My address is https://www.blockchain.com/btc-testnet/address/mk3RhhbT1pGCtZnoYF856KpdsY1CdTmaNg

var network = Network.TestNet
var QBitClient = new QBitNinjaClient(network);

var key = Key.Parse("privateKey", network);

var toAddress = BitcoinAddress.Create("destinationAddress", network);
var fromAddress = BitcoinAddress.Create("address', network);

var balance = QBitClient.GetBalance(fromAddress, unspentOnly: true).GetAwaiter().GetResult();
var coins = balance.Operations
   .SelectMany(op => op.ReceivedCoins)
   .Where(c => c.TxOut.ScriptPubKey == fromAddress.ScriptPubKey)
   .ToList();

var builder = network.CreateTransactionBuilder()
   .AddCoins(coins)
   .SendAll(toAddress)
   .SendFees(new Money(0.0001m, MoneyUnit.BTC))
   .SubtractFees()
   .AddKeys(key);

var trans = builder.BuildTransaction(sign: true);
builder.Verify(trans, new Money(0.0001m, MoneyUnit.BTC), out var error);

errors contain {Script error on input 0 (InvalidStackOperation)} {Script error on input 1 (InvalidStackOperation)}

What is wrong with my inputs? They are the first 2 transactions on the address and are all unspent. Another thing is that the last IN transaction on the address is not picked up by QBitClient.

New contributor
Mihai Bratulescu is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

0

Your Answer

Mihai Bratulescu is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.