Bitcoin Forum
May 05, 2024, 10:12:06 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Issues creating a transaction using NBitcoin C# library  (Read 968 times)
racezefi (OP)
Member
**
Offline Offline

Activity: 80
Merit: 14


View Profile
April 22, 2016, 02:36:17 AM
Merited by ABCbits (1)
 #1

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);
1714947126
Hero Member
*
Offline Offline

Posts: 1714947126

View Profile Personal Message (Offline)

Ignore
1714947126
Reply with quote  #2

1714947126
Report to moderator
1714947126
Hero Member
*
Offline Offline

Posts: 1714947126

View Profile Personal Message (Offline)

Ignore
1714947126
Reply with quote  #2

1714947126
Report to moderator
"Bitcoin: the cutting edge of begging technology." -- Giraffe.BTC
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714947126
Hero Member
*
Offline Offline

Posts: 1714947126

View Profile Personal Message (Offline)

Ignore
1714947126
Reply with quote  #2

1714947126
Report to moderator
achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 3388
Merit: 6581


Just writing some code


View Profile WWW
April 22, 2016, 03:08:40 AM
 #2

The hex is:
01000000010c23084b36102034b0e2e39bdb35af05d741b03027fe2a07c9ff3044007e9f3f01000 0001976a914b57667ec0af6f55ebe15047ac17dc1beddfe53f388acffffffff0100e6e849000000 001976a9140c41824ce507d3819b3c2c3fa89e5d9e77e8678588ac00000000
This doesn't look like it has been signed.

racezefi (OP)
Member
**
Offline Offline

Activity: 80
Merit: 14


View Profile
April 22, 2016, 06:31:41 AM
 #3

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.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!