Hey people, maybe somebody can help me out. Trying to create a transaction on TestNet.
I'm still learning, so I'm probably making a mistake creating the transaction by hand.
I think the problem might be the signing or the ScriptPubKey for the input. I'm getting the error "Error sending transaction: Rejected script for input 0 referencing 3f9f7e004430ffc9072afe2730b041d705af35db9be3e2b0342010364b08230c at 1.. " when trying to broadcast the hex of the Tx using
https://live.blockcypher.com/btc-testnet/pushtx/The hex is:
01000000010c23084b36102034b0e2e39bdb35af05d741b03027fe2a07c9ff3044007e9f3f01000
0001976a914b57667ec0af6f55ebe15047ac17dc1beddfe53f388acffffffff0100e6e849000000
001976a9140c41824ce507d3819b3c2c3fa89e5d9e77e8678588ac00000000
Anyway, here's the code, perhaps somebody could help out?
ExtKey _xprvKey = ExtKey.Parse("tprv8ZgxMBicQKsPdf3eLfgjbCxeGSep73nvrgA6eSRq9t4X4SoQ9DYGXeetjpbQ9qu5fd55k1VEADkre66Cfib1xD9P72qb8VzGTnC1vpVPmXV");
ExtKey extKey = _xprvKey.Derive(new KeyPath("m/0/0"));//this is the source address, the receiver of the TxIn
BitcoinSecret secret = extKey.PrivateKey.GetBitcoinSecret(Network.TestNet);
BitcoinAddress sourceAddress = BitcoinAddress.Create("mx4SSmJXaeqrDGwxWmnd6KWk68P6GjLbvf", Network.TestNet);
BitcoinAddress destAddress = BitcoinAddress.Create("mgdkszxePH9RT7C6aEbv7j3DdTXgCTwaTL", Network.TestNet);//this is m/0/1
var blockr = new BlockrTransactionRepository();
blockr.Network = Network.TestNet;
Transaction fundingTransaction =
blockr.Get("3f9f7e004430ffc9072afe2730b041d705af35db9be3e2b0342010364b08230c");
int index = 1;
var tx = new NBitcoin.Transaction();
var txIn = new TxIn(new OutPoint(fundingTransaction, index));
tx.AddInput(txIn);
var amount = new Money(1240000000, MoneyUnit.Satoshi);//total in source address is 12.5 BTC, keeping 0.1 for the fee
tx.AddOutput(amount, destAddress);
txIn.ScriptSig = sourceAddress.ScriptPubKey;
tx.Sign(secret.PrivateKey, false);