Author

Topic: Don't know how to sign for this kind of scriptPubKey (Read 110 times)

legendary
Activity: 1568
Merit: 6660
bitcoincleanup.com / bitmixlist.org
TransactionOutPoint.addSignedInput() does not support P2SH or P2WSH scripts so since you are using LegacyAddress class which allows for P2SH script input via the fromBase58() function make sure you are not passing any addresses into the function that are P2SH (begin with a "3").
legendary
Activity: 1442
Merit: 1179
How did you create that address? Perhaps it is a non-standard script which is why the error says it doesn't know how to sign it. If a custom p2sh what was your script?
legendary
Activity: 1512
Merit: 7340
Farewell, Leo
Quote
3. What version of programming language do you use (it looks like C# for me, but i'm not sure)?
It isn't C#, but Java and he probably uses the bitcoinj library.

But, OP it's true. You should specify your problem; by saying that it returns you an exception as an error, we can't understand much. Is this your code or have you copied it from somewhere else? You may be more assisted in here: https://bitcoin.stackexchange.com/questions/tagged/bitcoinj
newbie
Activity: 1
Merit: 5
when I send tx but catch this message "Don't know how to sign for this kind of scriptPubKey",I don't know what happen I
hope someone help me,my code is:

 public  String sign(String fromAddress, String toAddress, String privateKey, long amount, long fee, List utxos) throws Exception {
        NetworkParameters networkParameters = MainNetParams.get();
        Transaction transaction = new Transaction(networkParameters);
        String changeAddress = fromAddress;//找零地址
        Long changeAmount = 0L;
        Long utxoAmount = 0L;
        List needUtxos = new ArrayList();
        if (utxos == null || utxos.size() == 0) {
            throw new Exception("未消费列表为空");
        }
        //遍历未花费列表,组装合适的item
        for (UTXO utxo : utxos) {
            if (utxoAmount >= (amount + fee)) {
                break;
            } else {
                needUtxos.add(utxo);
                utxoAmount += utxo.getValue().value;
            }
        }
        transaction.addOutput(Coin.valueOf(amount), LegacyAddress.fromBase58(networkParameters, toAddress));
        //消费列表总金额 - 已经转账的金额 - 手续费 就等于需要返回给自己的金额了
        changeAmount = utxoAmount - (amount + fee);
        //余额判断
        if (changeAmount < 0) {
            throw new Exception("utxo余额不足");
        }
        //输出-转给自己(找零)
        if (changeAmount > 0) {
            transaction.addOutput(Coin.valueOf(changeAmount), LegacyAddress.fromBase58(networkParameters, changeAddress));
        }
        //输入未消费列表项
        DumpedPrivateKey dumpedPrivateKey = DumpedPrivateKey.fromBase58(networkParameters, privateKey);
        ECKey ecKey = dumpedPrivateKey.getKey();
        for (UTXO utxo : needUtxos) {
            TransactionOutPoint outPoint = new TransactionOutPoint(networkParameters, utxo.getIndex(), utxo.getHash());
              transaction.addSignedInput(outPoint, utxo.getScript(), ecKey, Transaction.SigHash.ALL, true);
        }
        byte[] bytes = transaction.bitcoinSerialize();
        String hash = Hex.toHexString(bytes);
        log.info("fee:{},utxoAmount:{},changeAmount{}", fee, utxoAmount, changeAmount);
        return hash;
    }

the exception at the red color
Jump to: