Author

Topic: transaction failed to validate input (Read 195 times)

newbie
Activity: 4
Merit: 0
August 14, 2018, 05: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
legendary
Activity: 1624
Merit: 2481
August 14, 2018, 05: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.
newbie
Activity: 4
Merit: 0
August 14, 2018, 05: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
legendary
Activity: 1624
Merit: 2481
August 14, 2018, 04: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
newbie
Activity: 4
Merit: 0
August 14, 2018, 04: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
Jump to: