0

I create a transaction with this command:

cardano-cli latest transaction build \
    --testnet-magic 2 \
    --out-file "$tx_unsigned_name" \
    --tx-in "$nft_utxo" \
    --tx-in-datum-file data.json \
    --tx-in-redeemer-file redeemer.json \
    --tx-in-script-file contract_code.txt \
    --tx-in $utxo \
    --tx-in-collateral $collateral_utxo \
    --change-address "$wallet_address" \
    --tx-out "$(cat contract_address.txt)+${nft}" \
    --tx-out-datum-hash-file data_new.json \
    --invalid-hereafter $deadline

and expect that the ctx.transaction.datums has an entry (h, d) where h is hash of data_new.json and d is the data from that file. But I printed the dict and it contains only the data from data.json file.

Here is the line from plutus-pioneer-program code that searches the datums entry for the output data so I thought that should work.

The question is, how can I access the output data from the contract script?

Update:

Plutonomicon says:

The datums for the inputs are always contained in txInfoData. Anything else may not be present. If you in your script depend on the datum for an output being available, you must make sure when submitting the transaction that you include the datum in txInfoData.

So, how can I include the datum to txIinfoData? One possibility is to use some additional input, but is there more straightforward solution?

1
  • Just realized that maybe I should use --tx-out-datum-embed-file instead of --tx-out-datum-hash-file. I can not check this right now
    – amakarov
    Commented Jun 19 at 17:27

1 Answer 1

0

I should have used --tx-out-datum-embed-file instead of --tx-out-datum-hash-file. I did not understand data/embedded data/inlined data. Below is my understanding:

  • In regular case one transaction attaches a hash (with --tx-out-datum-hash-*) to an output sent to a script address. The transaction that consumes that output needs the actual data that is provided by --tx-in-datum-*.

  • Sometimes a script in the transaction that creates an output also needs the actual data present in the transaction (this is my case). Then it should use --tx-out-datum-embed-*. In this case the datum is added to txIinfoData in the transaction context that produces the transaction. The script in the transaction that consumes that output also needs the actual data in the transaction context (--tx-in-datum-*) so there are two instances of the data both in the transaction that creates the output and in the transaction that consumes it.

  • So in this case inlined data could be used: data is attached to the producer transaction with --tx-out-inline-datum-* and the consuming transaction has access to it if --tx-in-inline-datum-present is specified for that output.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.