Emurgo / cardano-serialization-lib

This is a library, written in Rust, for serialization & deserialization of data structures used in Cardano's Haskell implementation of Alonzo along with useful utility functions.
Other
231 stars 125 forks source link

Ability to mint asset and add inline datum #599

Closed bigirishlion closed 1 year ago

bigirishlion commented 1 year ago

I'm currently trying to craft a transaction that mints a token and provide datum for the UTxO output. I'm aware of the add_mint_asset_and_output but I can't figure out a way to do this and provide an output with datum.

Here's what I've tried:

let txOutputBuilder = serializationLib.TransactionOutputBuilder.new()
      .with_address(returnAddress)
      .with_plutus_data(plutusData)
      .next()
      .with_asset_and_min_required_coin_by_utxo_cost(
        multiAsset,
        serializationLib.DataCost.new_coins_per_byte(
          serializationLib.BigNum.from_str(dataCost)
        )
      )
      .build();
    txBuilder.add_output(txOutputBuilder);

    txBuilder.set_mint_builder(mintBuilder);

Any help is appreciated.

lisicky commented 1 year ago

Hi @bigirishlion ! with_plutus_data(plutusData) adds datum to a tx output. But if you need to use a datum for a plutus mint script, you need to use MintBuilder API. Because for using a Plutus mint script, you need to provide a redeemer (not datum ) and a Plutus script to MintBuilder, they will be placed to a witnesses set by MintBuilder.

But if you need to create a tx output with inlined datum with_plutus_data would be enough.

bigirishlion commented 1 year ago

Hey @lisicky. Thanks for the reply! Sorry for the confusion, I'm not asking how to send datum to a mint contract, I'm asking how to have an output with both a minted asset and inline datum.

lisicky commented 1 year ago

@bigirishlion you can create MintBuilder and TransactionOutput ( for example by TransactionOutputBuilder) with the same assets amount and add them to the tx builder. But add_mint_asset_and_output should work too, but it less flexible.

bigirishlion commented 1 year ago

Thanks @lisicky I was able to get it working using the code above and the MintBuilder.