Bitcoin Forum
May 11, 2024, 09:31:32 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: transaction failed to validate input  (Read 162 times)
glacial_boy (OP)
Newbie
*
Offline Offline

Activity: 4
Merit: 0


View Profile
August 14, 2018, 09:17:50 AM
 #1

Hello,

Im owner of this btc testnet address mxsdtqnL3trUZcuqniHJ3G5DXKeNKBQ3Td
If I want to spend this output https://testnet.blockchain.info/tx/984d6478625df41d675a39d908f5147348b07fe2f0828c5866af3aca438d29aa, how can I sign it to be valid?
This unspent output is of type pay-to-pubkey

Thank you
1715463092
Hero Member
*
Offline Offline

Posts: 1715463092

View Profile Personal Message (Offline)

Ignore
1715463092
Reply with quote  #2

1715463092
Report to moderator
1715463092
Hero Member
*
Offline Offline

Posts: 1715463092

View Profile Personal Message (Offline)

Ignore
1715463092
Reply with quote  #2

1715463092
Report to moderator
1715463092
Hero Member
*
Offline Offline

Posts: 1715463092

View Profile Personal Message (Offline)

Ignore
1715463092
Reply with quote  #2

1715463092
Report to moderator
It is a common myth that Bitcoin is ruled by a majority of miners. This is not true. Bitcoin miners "vote" on the ordering of transactions, but that's all they do. They can't vote to change the network rules.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
bob123
Legendary
*
Offline Offline

Activity: 1624
Merit: 2481



View Profile WWW
August 14, 2018, 09:57:07 AM
 #2

Which wallet/client/library are you using to create the transaction ?
Are you trying to manually sign it ?

For manually signing transactions (and a small python code snippet), look here: https://bitcoin.stackexchange.com/questions/36440/signing-a-raw-transaction-with-python-ecdsa-or-openssl

glacial_boy (OP)
Newbie
*
Offline Offline

Activity: 4
Merit: 0


View Profile
August 14, 2018, 10:02:05 AM
 #3

Im doing a manual sign, code written in Golang with library https://github.com/btcsuite/btcd

As for unspent output with type of P2PKH, I managed to create transaction and broadcast successfully. I tried to apply same technique for P2PK but it didnt work
bob123
Legendary
*
Offline Offline

Activity: 1624
Merit: 2481



View Profile WWW
August 14, 2018, 10:07:12 AM
 #4

It would be way more easier for us to find your mistake if you would share the relevant code.

Can't tell much without looking at it. But generally speaking, you seem to have built the transaction wrong.

glacial_boy (OP)
Newbie
*
Offline Offline

Activity: 4
Merit: 0


View Profile
August 14, 2018, 10:11:30 AM
 #5

Code:
func CreateTransaction(secret, sender, destination string, amount int64, txHash string) (*wire.MsgTx, error) {

// convert private key (string) -> ECDSA format
priv, _ := stringToPrivateECDSA(secret)

// init new transaction
// TxVersion = 1
redeemTx := wire.NewMsgTx(TxVersion)
// convert sender address (string) -> BTC Address format
sourceAddress, _ := btcutil.DecodeAddress(sender, ChainParams)
// create script base on address converted
sourcePkScript, _ := txscript.PayToAddrScript(sourceAddress)

// prepare output of sending #btc to destination address
// convert destination address (string) -> BTC Address format
// trying pay-to-pubkey method
destinationAddress, _ := btcutil.DecodeAddress(destination, ChainParams)
// create script for output address
destinationPkScript, _ := txscript.PayToAddrScript(destinationAddress)
// set amount to send to destination
redeemTxOut := wire.NewTxOut(amount, destinationPkScript)
redeemTx.AddTxOut(redeemTxOut)

// prepare output for Tx
// return #btc changes back to our wallet
// Total = #btc of that unspent output
// amount = #btc send to destination
redeemTxOut = wire.NewTxOut(Total-amount-TxFee, sourcePkScript)
redeemTx.AddTxOut(redeemTxOut)

// txHash = previous unspent output of sourceAddress
sourceUtxoHash, _ := chainhash.NewHashFromStr(txHash)
prevOut := wire.NewOutPoint(sourceUtxoHash, 0)
redeemTxIn := wire.NewTxIn(prevOut, nil, nil)
redeemTx.AddTxIn(redeemTxIn)

sig, err := txscript.SignatureScript(redeemTx, 0, sourcePkScript, txscript.SigHashAll, priv, false)
if err != nil {
fmt.Println(err)
return nil, err
}
redeemTx.TxIn[0].SignatureScript = sig

return redeemTx, nil
}

This is my function to create a transaction written in Go.
Thank you and really appreciate for your help  Cheesy
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!