Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: racezefi on April 22, 2016, 02:36:17 AM



Title: Issues creating a transaction using NBitcoin C# library
Post by: racezefi on April 22, 2016, 02:36:17 AM
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?

Code:
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);


Title: Re: Issues creating a transaction using NBitcoin C# library
Post by: achow101 on April 22, 2016, 03:08:40 AM
The hex is:
01000000010c23084b36102034b0e2e39bdb35af05d741b03027fe2a07c9ff3044007e9f3f01000 0001976a914b57667ec0af6f55ebe15047ac17dc1beddfe53f388acffffffff0100e6e849000000 001976a9140c41824ce507d3819b3c2c3fa89e5d9e77e8678588ac00000000
This doesn't look like it has been signed.


Title: Re: Issues creating a transaction using NBitcoin C# library
Post by: racezefi on April 22, 2016, 06:31:41 AM
The hex is:
01000000010c23084b36102034b0e2e39bdb35af05d741b03027fe2a07c9ff3044007e9f3f01000 0001976a914b57667ec0af6f55ebe15047ac17dc1beddfe53f388acffffffff0100e6e849000000 001976a9140c41824ce507d3819b3c2c3fa89e5d9e77e8678588ac00000000
This doesn't look like it has been signed.

Woopps, I was deriving the key incorrectly, was using m/0/0 when I should have been using m/0/0/0!
That solved it.