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

Merging change utxos in minting transaction #239

Open
khiemn159 opened this issue Dec 20, 2023 · 1 comment
Open

Merging change utxos in minting transaction #239

khiemn159 opened this issue Dec 20, 2023 · 1 comment

Comments

@khiemn159
Copy link

Hello, I'm relatively new to Cardano and Lucid. I am trying to mint a token like this, and my goal is to produce only 1 utxo that will also contain the token:

const txn = await params.lucid.newTx()
    .attachMintingPolicy({
      type: "PlutusV2", script: policyScript
    })
    .mintAssets({
      [`${token}`]: 1n,
    }, Data.to(12n))
    .complete();

const signing = await txn.sign().complete();
const hash = await signing.submit();
console.log("hash: ", hash);

And the result get splitted into 2 utxos:
image

I have tried other method such as:

const txn = await params.lucid.newTx()
    .attachMintingPolicy({
      type: "PlutusV2", script: policyScript
    })
    .mintAssets({
      [`${token}`]: 1n,
    }, Data.to(12n))
    .payToAddress(await params.lucid.wallet.address(), {
      [`${token}`]: 1n,
    })
    .complete();

const signing = await txn.sign().complete();
const hash = await signing.submit();
console.log("hash: ", hash);

but it still produces 2 utxos.
What can I do to make it produce 1 utxo only? Thanks in advance!

@cmorgado
Copy link

I don't believe it is possible, if you look carefully, it's not a bug but how the eUTxO and cardano works.
You need to send back to the wallet the ada it had minus what it has spent from the input, thus the utxo with the minted value.
I've seen this pattern many times.

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