cardano-serialization-lib icon indicating copy to clipboard operation
cardano-serialization-lib copied to clipboard

Error: "Inputs do not conform to this spec or are otherwise invalid" after use inline datum intead of data hash

Open K4waiiChan opened this issue 2 years ago • 2 comments

I'm using the latest version of the library (11.0.0) and I want to start using inline datum instead of data hash, I have tried to use with_plutus_data in the txOutputBuilder I have also tried with set_plutus_data in the txOutput, but I get this error "Inputs do not conform to this spec or are otherwise invalid" in both cases, the inputs are utxos coming from nami wallet

This is my code:

const buildSendTokenToPlutusScript = async (walletApi, {
      assetNameHex,
      assetPolicyIdHex,
      assetAmountToSend,
      lovelaceToSend = 2000000
    }) => {
      const txBuilder = TransactionBuilder.new(
        TransactionBuilderConfigBuilder.new()
          .fee_algo(LinearFee.new(BigNum.from_str("44"), BigNum.from_str("155381")))
          .pool_deposit(BigNum.from_str("500000000"))
          .key_deposit(BigNum.from_str("2000000"))
          .coins_per_utxo_byte(BigNum.from_str("4310"))
          .max_value_size(5000)
          .max_tx_size(16384)
          .prefer_pure_change(true)
          .build()
        );
      const ScriptAddress = Address.from_bech32(settings.smartContract.addressScriptBech32);
      const shelleyChangeAddress = Address.from_bech32(await walletApi.getChangeAddress());
      let txOutputBuilder = TransactionOutputBuilder.new();
      txOutputBuilder = txOutputBuilder.with_address(ScriptAddress);
      const inlineDatum = PlutusData.new_integer(BigInt.from_str('12345'));
      txOutputBuilder = txOutputBuilder.with_plutus_data(inlineDatum);
      txOutputBuilder = txOutputBuilder.next();
      let multiAsset = MultiAsset.new();
      let assets = Assets.new()
      assets.insert(
        AssetName.new(Buffer.from(assetNameHex, "hex")), // Asset Name
        BigNum.from_str(assetAmountToSend.toString()) // How much to send
      );
      multiAsset.insert(
        ScriptHash.from_bytes(Buffer.from(assetPolicyIdHex, "hex")), // PolicyID
        assets
      );
      txOutputBuilder = txOutputBuilder.with_coin_and_asset(BigNum.from_str(lovelaceToSend.toString()),multiAsset)
      const txOutput = txOutputBuilder.build();
      txBuilder.add_output(txOutput)
      // Find the available UTXOs in the wallet and
      // us them as Inputs
      const { txOutputs: txUnspentOutputs } = await walletApi.getUtxos();
      txBuilder.add_inputs_from(txUnspentOutputs, 3)
      // calculate the min fee required and send any change to an address
      txBuilder.add_change_if_needed(shelleyChangeAddress)
      // once the transaction is ready, we build it to get the tx body without witnesses
      const txBody = txBuilder.build();
      // Tx witness
      const transactionWitnessSet = TransactionWitnessSet.new();
      const tx = Transaction.new(
        txBody,
        TransactionWitnessSet.from_bytes(transactionWitnessSet.to_bytes())
      );
      let txVkeyWitnesses = await walletApi.api.signTx(Buffer.from(tx.to_bytes(), "utf8").toString("hex"), true);
      txVkeyWitnesses = TransactionWitnessSet.from_bytes(Buffer.from(txVkeyWitnesses, "hex"));
      transactionWitnessSet.set_vkeys(txVkeyWitnesses.vkeys());
      const signedTx = Transaction.new(
        tx.body(),
        transactionWitnessSet
      );
      const submittedTxHash = await walletApi.api.submitTx(Buffer.from(signedTx.to_bytes(), "utf8").toString("hex"));
      return {
        submittedTxHash: submittedTxHash,
        transactionIdLocked: submittedTxHash,
        lovelaceLocked: lovelaceToSend
      };
  }

K4waiiChan avatar Aug 03 '22 21:08 K4waiiChan

Hi @K4waiiChan ! Do you still have the issue? Could you provide cbor of tx ? Did you try it on mainnet or testnet ?

lisicky avatar Oct 11 '22 12:10 lisicky

Building a very similar txn from gathering utxos from nami and having same issue at signTx

code snippet:

let tx = await txBuilder.build();

let txVkeyWitnesses = await this.ENABLED_WALLET.signTx(
        toHex(tx.to_bytes()),
        true
);

Suggestion this error is far too generic and as I understand could be anything including wrong network destination address mismatch. Need a verbose error to understand what part of the input is actually wrong.

Using version ^11.1.0

khcd avatar Oct 19 '22 04:10 khcd