Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with moving a utxo locked in always_succeeds contract #678

Open
devMoney71 opened this issue Jul 23, 2024 · 6 comments
Open

Issues with moving a utxo locked in always_succeeds contract #678

devMoney71 opened this issue Jul 23, 2024 · 6 comments

Comments

@devMoney71
Copy link

devMoney71 commented Jul 23, 2024

I am a beginner who just started developing with Cardano.
I am writing a javascript code to move a utxo locked in the trivial.always_succeeds contract (preprod: addr_test1wquu2gxsvfa2lfeg7ljd6yq59dmuy4up8sm02l3vhz8h9fg4q3ckq), using a reference UTXO.
I managed to sent a utxo with datum "TEST" to the contract, but failed to withdraw it to my address.

Here is a part of my code.

Create a TransactionBuilder and a TxInputsBuilder:

let txBuilder = CardanoWasm.TransactionBuilder.new(txBuilderCfg);
let txInputsBuilder = CardanoWasm.TxInputsBuilder.new();

Create a TransactionInput for a transaction, and also a reference TransactionInput :

let txIn = CardanoWasm.TransactionInput.new(
	CardanoWasm.TransactionHash.from_bytes(Buffer.from(utxoHash, 'hex')),
	parseInt(utxoIndex, 10)
);
let txInRef = CardanoWasm.TransactionInput.new(
	CardanoWasm.TransactionHash.from_bytes(Buffer.from(referenceUtxoHash, 'hex')),
	parseInt(referenceUtxoIndex, 10)
);

And build the input of transction:

txInputsBuilder.add_plutus_script_input(
	plutusWitness,
	txIn,
	CardanoWasm.Value.new(CardanoWasm.BigNum.from_str(utxoAmount))
);
txBuilder.set_inputs(txInputsBuilder);

Here plutusWitness is defined as follows:

let scriptHash = "39c520d0627aafa728f7e4dd10142b77c257813c36f57e2cb88f72a5";
let script = CardanoWasm.PlutusScriptSource.new_ref_input_with_lang_ver(
	CardanoWasm.ScriptHash.from_hex(scriptHash),
	txInRef,
	CardanoWasm.Language.new_plutus_v2()
);
let datum = CardanoWasm.DatumSource.new(CardanoWasm.PlutusData.new_bytes(Buffer.from("TEST", "utf-8")));
let redeemer = CardanoWasm.Redeemer.new(
	CardanoWasm.RedeemerTag.new_spend(),
	CardanoWasm.BigNum.from_str('0'),
	CardanoWasm.PlutusData.new_bytes(Buffer.from(datumStr, "utf-8")),
	CardanoWasm.ExUnits.new(
		CardanoWasm.BigNum.from_str("7000000"),
		CardanoWasm.BigNum.from_str("3000000000")
	)
);
let plutusWitness = CardanoWasm.PlutusWitness.new_with_ref(
    	script,
	datum,
	redeemer
);

In fact, I am not sure those variables are set correctly. The hash of the script is "39c520d0627aafa728f7e4dd10142b77c257813c36f57e2cb88f72a5", I found this hash at "https://preprod.cardanoscan.io/transaction/be8217d6682be1d1888ca112896345612f0d6dec4552970188a9d1cbcf47e17b?tab=utxo".

And then, I add collateral utxo.

let collateralBuilder = CardanoWasm.TxInputsBuilder.new();
let collateralInput = CardanoWasm.TransactionInput.new(
  CardanoWasm.TransactionHash.from_bytes(Buffer.from(collateralUtxo.tx_hash, 'hex')),
  parseInt(collateralUtxo.tx_index, 10)
);
collateralBuilder.add_input(
  CardanoWasm.Address.from_bech32(public_key),
  collateralInput,
  CardanoWasm.Value.new(CardanoWasm.BigNum.from_str(collateral_quantity))
);
txBuilder.set_collateral(collateralBuilder);

After that, I use calc_script_data_hash:

let costModel = CardanoWasm.TxBuilderConstants.plutus_vasil_cost_models().get(CardanoWasm.Language.new_plutus_v2());
let costModels = CardanoWasm.Costmdls.new();
costModels.insert(CardanoWasm.Language.new_plutus_v2(), costModel);
txBuilder.calc_script_data_hash(costModels);

Then, add change:
txBuilder.add_change_if_needed(CardanoWasm.Address.from_bech32(to));

And then, build tx:
let tx = txBuilder.build_tx();

And sign with payment_key (this is for collateral) and submit transaction using blockfrost api:

let txBytes = tx.to_bytes();
let signedTxBytes = signTransaction(txBytes, payment_key);
let result = await submitTransaction(signedTxBytes);

But got the following error.

{
  contents: {
    contents: {
      contents: {
        era: 'ShelleyBasedEraBabbage',
        error: [
          {
            contents: {
              contents: {
                contents: [
                  [
                    {
                      kind: 'AlonzoSpending',
                      value: {
                        item: '542077cd26ff83bc5de764be8aa3dfa985f8479c983153bbcc7ee690101cbc98#TxIx 0'
                      }
                    },
                    'dc90c02719b5b3b1d56b5f22a39225dd9da5cf4d435c048a0c8657b4'
                  ]
                ],
                tag: 'MissingRedeemers'
              },
              tag: 'AlonzoInBabbageUtxowPredFailure'
            },
            tag: 'UtxowFailure'
          },
          {
            contents: {
              contents: {
                contents: [
                  'd6483414bef2d593b18792aeb898cd6c2d88933d30e49ea234cdba87219ea719',
                  '75be5e37c2a7f07027713f0cf852aabedb84498d31182e96a4d2390dc2817d3f'
                ],
                tag: 'PPViewHashesDontMatch'
              },
              tag: 'AlonzoInBabbageUtxowPredFailure'
            },
            tag: 'UtxowFailure'
          },
          {
            contents: {
              contents: 'AlonzoInBabbageUtxoPredFailure (UtxosFailure (CollectErrors [NoRedeemer (AlonzoSpending (TxIn (TxId {unTxId = SafeHash "542077cd26ff83bc5de764be8aa3dfa985f8479c983153bbcc7ee690101cbc98"}) (TxIx 0)))]))',
              tag: 'UtxoFailure'
            },
            tag: 'UtxowFailure'
          }
        ],
        kind: 'ShelleyTxValidationError'
      },
      tag: 'TxValidationErrorInCardanoMode'
    },
    tag: 'TxCmdTxSubmitValidationError'
  },
  tag: 'TxSubmitFail'
}

I would appreciate any help you can provide on this issue. Thank you.

@devMoney71 devMoney71 changed the title Problem with moving locked assets in always_succeeds contract Issues with moving a utxo locked in always_succeeds contract Jul 23, 2024
@Emurgo Emurgo deleted a comment Jul 24, 2024
@lisicky
Copy link
Contributor

lisicky commented Jul 29, 2024

Hey @devMoney71 ! You need to provide collateral inputs to not get the error "Plutus inputs are present, but no collateral inputs are added". Also builder.build() returns tx body without any witnesses that's why you got the error from cardano node, you need to use builder.build_tx()

@devMoney71 devMoney71 reopened this Aug 5, 2024
@devMoney71
Copy link
Author

Hey @devMoney71 ! You need to provide collateral inputs to not get the error "Plutus inputs are present, but no collateral inputs are added". Also builder.build() returns tx body without any witnesses that's why you got the error from cardano node, you need to use builder.build_tx()

Thank you for your reply.
I used build_tx and also add collateral as following:

let collateralBuilder = CardanoWasm.TxInputsBuilder.new();
let collateralInput = CardanoWasm.TransactionInput.new(
  CardanoWasm.TransactionHash.from_bytes(Buffer.from(collateralUtxo.tx_hash, 'hex')),
  parseInt(collateralUtxo.tx_index, 10)
);
collateralBuilder.add_input(
  CardanoWasm.Address.from_bech32(addr),
  collateralInput,
  CardanoWasm.Value.new(CardanoWasm.BigNum.from_str(quantity))
);
txBuilder.set_collateral(collateralBuilder);

But I am still getting errors.

{
  contents: {
    contents: {
      contents: {
        era: 'ShelleyBasedEraBabbage',
        error: [
          {
            contents: {
              contents: {
                contents: [
                  [
                    {
                      kind: 'AlonzoSpending',
                      value: {
                        item: '542077cd26ff83bc5de764be8aa3dfa985f8479c983153bbcc7ee690101cbc98#TxIx 0'
                      }
                    },
                    'dc90c02719b5b3b1d56b5f22a39225dd9da5cf4d435c048a0c8657b4'
                  ]
                ],
                tag: 'MissingRedeemers'
              },
              tag: 'AlonzoInBabbageUtxowPredFailure'
            },
            tag: 'UtxowFailure'
          },
          {
            contents: {
              contents: {
                contents: [
                  'd6483414bef2d593b18792aeb898cd6c2d88933d30e49ea234cdba87219ea719',
                  '75be5e37c2a7f07027713f0cf852aabedb84498d31182e96a4d2390dc2817d3f'
                ],
                tag: 'PPViewHashesDontMatch'
              },
              tag: 'AlonzoInBabbageUtxowPredFailure'
            },
            tag: 'UtxowFailure'
          },
          {
            contents: {
              contents: 'AlonzoInBabbageUtxoPredFailure (UtxosFailure (CollectErrors [NoRedeemer (AlonzoSpending (TxIn (TxId {unTxId = SafeHash "542077cd26ff83bc5de764be8aa3dfa985f8479c983153bbcc7ee690101cbc98"}) (TxIx 0)))]))',
              tag: 'UtxoFailure'
            },
            tag: 'UtxowFailure'
          }
        ],
        kind: 'ShelleyTxValidationError'
      },
      tag: 'TxValidationErrorInCardanoMode'
    },
    tag: 'TxCmdTxSubmitValidationError'
  },
  tag: 'TxSubmitFail'
}

@lisicky
Copy link
Contributor

lisicky commented Aug 5, 2024

According to errors you don't have a redeemer in your witnesses set, do not modify witnesses set after you built a tx except vkey and bootstrap witnesses

@lisicky
Copy link
Contributor

lisicky commented Aug 28, 2024

Hey @devMoney71 ! Did it helped ?

@devMoney71
Copy link
Author

devMoney71 commented Sep 17, 2024

Hey @devMoney71 ! Did it helped ?

Sorry for the late reply.
I haven't solved it yet.

I have an another error.

{
  contents: {
    contents: {
      contents: 'EraMismatch {ledgerEraName = "Conway", otherEraName = "Babbage"}',
      tag: 'TxValidationEraMismatch'
    },
    tag: 'TxCmdTxSubmitValidationError'
  },
  tag: 'TxSubmitFail'
}

Can you provide a link for a sample code?

@lisicky
Copy link
Contributor

lisicky commented Oct 9, 2024

@devMoney71 you need to update the tool which you use to to submit a tx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants