Closed lenhatquang97 closed 1 year ago
I have solved this problem by signing each inputs. Can everyone tell me that is this a good solution?
func SignTx(wif *btcutil.WIF, pkScript []byte, redeemTx *wire.MsgTx) (*wire.MsgTx, error) {
for i, _ := range redeemTx.TxIn {
signature, err := txscript.SignatureScript(redeemTx, i, pkScript, txscript.SigHashAll, wif.PrivKey, true)
if err != nil {
return nil, err
}
redeemTx.TxIn[i].SignatureScript = signature
}
return redeemTx, nil
}
Yes, each input of a transaction needs to be signed. Normally that is done in a loop :+1:
Situation
I want to merge multiple unspent inputs into an input because each inputs only contain 50 satoshis. What can I do or how to use multiple inputs and outputs in the transaction?
I am using simnet in btcd and btcwallet
Commands in btcd and btcwallet
btcwallet --simnet --username=youruser --password=SomeDecentp4ssw0rd
btcd --simnet --rpcuser=youruser --rpcpass=SomeDecentp4ssw0rd --miningaddr=SeZdpbs8WBuPHMZETPWajMeXZt1xzCJNAJ --txindex
Why do I ask
Because I meet this error related to using multiple inputs -25: TX rejected: failed to validate input 048e08a85d50ee1b493920ef70d68e344304bb63689384342860c534c1d6e931:3 which references output 44f6bed55cb1bc9ad55bc7906d5398055bcd5ac504100773d1af64bc889b2975:0 - index 0 is invalid for stack size 0 (input witness [], input script bytes , prev output script bytes 76a914bd6f166f34fa00ecc0010900ead95ba6cf9f2a8788ac)
Source code