Offline creating raw transaction and sign on device.

296 views
Skip to first unread message

Constantine Stanev

unread,
Jul 16, 2018, 7:52:17 AM7/16/18
to bitcoinj
Hello, I tried create a raw transaction and sing it without connection to peer and blocks synchronization. 
But I've getting error "Error validating transaction: Error running script for input 0 referencing 3615d7ecabe9f8f2788e5d78d1399692df3e7bf54ab89b0b4a807ffabcb94179 at 0: Script was NOT verified successfully.." while broadcasting transaction on  https://live.blockcypher.com/btc-testnet/pushtx/
I spent this week looking for a possible error, and look on other open source projects, but I did not find any clue. 
I will be very grateful for the help, thanks.

There is my code:
Address fromAddress = wallet.currentReceiveAddress();// mtTvAK7vLFVUEWMuMMvK6Gmp6sxbjZPKjf
Address receiver = Address.fromBase58(params, "mysBqTUdJTLLw95x9eyc8QApFRkJXErD8R");
List<UTXO> utxos; // I get UTXOs from custom API service

DumpedPrivateKey dumpedPrivateKey = wallet.currentReceiveKey().getPrivateKeyEncoded(params);
ECKey key = dumpedPrivateKey.getKey();
Transaction tx = new Transaction(params);
tx.addOutput(Coin.valueOf(amount), receiver);

for(UTXO utxo : utxos) {
TransactionOutPoint outPoint = new TransactionOutPoint(
params,
utxo.vout,
Sha256Hash.wrap(utxo.txid)
);
tx.addSignedInput(outPoint, new Script(hexEncoding.decode(utxo.scriptPubKey)), key);
}

tx.getConfidence().setSource(TransactionConfidence.Source.SELF);
tx.setPurpose(Transaction.Purpose.USER_PAYMENT);

tx.verify();

byte[] ser = tx.unsafeBitcoinSerialize();
String finalHex = hexEncoding.encode(ser);
System.out.println("RESULT "+ finalHex); //And here I am try to broadcast it on
https://live.blockcypher.com/btc-testnet/pushtx/

Here is additional data: 

Structure of JSON response for unspent outputs:
{
    "txid":"3615d7ecabe9f8f2788e5d78d1399692df3e7bf54ab89b0b4a807ffabcb94179",
   "vout":0,
   "address":"mtTvAK7vLFVUEWMuMMvK6Gmp6sxbjZPKjf",
   "scriptPubKey":"76a9148e069b3babbe2a49241614e0b089a814a22fb6ac88ac",
   "amount":1.3
},
{
  "txid":"e3aafa54a9ef06f0c4196c8a4334aedc78113733832f8563937a274484a87854",
  "vout":0,"address":"mtTvAK7vLFVUEWMuMMvK6Gmp6sxbjZPKjf",
  "scriptPubKey":"76a9148e069b3babbe2a49241614e0b089a814a22fb6ac88ac",
  "amount":1.3
}

Hex of raw transaction: 01000000027941b9bcfa7f804a0b9bb84af57b3edf929639d1785d8e78f2f8e9abecd71536000000006b4830450221008f7a50ead70af7d64b84f222d9147974715ec435f758e525d88f97dd53ec905602200a4e6f657050fa2cfc2c0a9d108a14e61a8441f42cec64724ced0560dd5c3648012103811de3a664b58047c5d49cee145ee8b46040aaeb368d2cb885b12d3e78b80d33ffffffff5478a88444277a9363852f8333371178dcae34438a6c19c4f006efa954faaae3000000006a47304402200cf18ce3d26b33c46841ddecd90785814f03a89d66ca3b062f0f1a8ef880c82902206c314a3e9b0a7ce780d6504913b2ca13b06d2b1e3542a2563766d158572c47c3012103811de3a664b58047c5d49cee145ee8b46040aaeb368d2cb885b12d3e78b80d33ffffffff0180a4bf07000000001976a914c945e31d42cf43a00d6d6980d71c9bc8b3a6c63488ac00000000

Тимур Панжиев

unread,
Aug 5, 2018, 8:19:03 AM8/5/18
to bitcoinj
Here is my question:
may be it`ll be useful for you. And of course, if you get me some advice or solution about my problem, I'll really appreciate it.

понедельник, 16 июля 2018 г., 14:52:17 UTC+3 пользователь Constantine Stanev написал:
Reply all
Reply to author
Forward
0 new messages