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

largestFirst doesn't return utxos #1

Open
uouo690 opened this issue Mar 12, 2023 · 3 comments
Open

largestFirst doesn't return utxos #1

uouo690 opened this issue Mar 12, 2023 · 3 comments

Comments

@uouo690
Copy link

uouo690 commented Mar 12, 2023

Hello ,
I am trying to mint an asset as described in this repo , but I debugged the code and founded that the selectedUtxos is empty as indicated in the attached image

image

Despite the fact the utxos has at least one utxo

image

The code I am using to mint as follow:

`
const recipientAddtess = req.body.recipientAddress;
const utxos = req.body.utxos;

const koiosProvider = new KoiosProvider('preprod');

const appWallet = new AppWallet({
    networkId: 0,
    fetcher: koiosProvider,
    submitter: koiosProvider,
    key: {
      type: 'mnemonic',
      words:[
      ....
      ],
    },
});

const appWalletAddress = appWallet.getPaymentAddress();
const forginScript = ForgeScript.withOneSignature(appWalletAddress);

const assetName = 'PointsAsset'
 // define asset#1 metadata
const assetMetadata1: AssetMetadata = {
    "name": "Mesh Token",
    "image": "ipfs://QmRzicpReutwCkM6aotuKjErFCUD213DpwPq6ByuzMJaua",
    "mediaType": "image/jpg",
    "description": "This NFT is minted during points initial creation."
};

const asset1: Mint = {
    assetName: assetName,
    assetQuantity: '1',
    metadata: assetMetadata1,
    label: '721',
    recipient: recipientAddtess,
};


const costLovelace =  "10000000";
const selectedUtxos = largestFirst(costLovelace, utxos, true);

const tx = new Transaction({ initiator: appWallet });
tx.setTxInputs(selectedUtxos);
tx.mintAsset(forginScript, asset1);
tx.sendLovelace(bankWalletAddress, costLovelace);
tx.setChangeAddress(recipientAddtess);


const _unsignedTx = await tx.build();
const unsignedTx = await appWallet.signTx(_unsignedTx,true);

return res.status(200).json({ unsignedTx : unsignedTx});

}`

This code always break at the tx.buil(); giving this error

Error: [Transaction] An error occurred during build: Insufficient input in transaction. shortage: {ada in inputs: 0, ada in outputs: 11168010, fee 182749
NOTE! "ada in inputs" must be >= ("ada in outputs" + fee) before adding change
and "ada in inputs" must be == ("ada in outputs" + fee) after adding change

Can u guid me what is the issue .
thanks

@MeshJS MeshJS deleted a comment Mar 13, 2023
@jinglescode
Copy link
Member

Hi, your code looks fine, and for this simple case of selecting 10 ADA it should work.
This is my suggestion, use keepRelevant().

Replace:

const selectedUtxos = largestFirst(costLovelace, utxos, true);

With:

import { keepRelevant } from '@meshsdk/core';
import type { Unit, Quantity } from '@meshsdk/core';

const assetMap = new Map<Unit, Quantity>();
assetMap.set('lovelace', costLovelace);

const selectedUtxos = keepRelevant(assetMap, utxos);

@uouo690
Copy link
Author

uouo690 commented Mar 13, 2023

Thanks , I can mint now :)
But I have another question , when tried miniting using smart contract , I faced this error
image

@jinglescode
Copy link
Member

@uouo690 , check out my explanation here MeshJS/mesh#72 (comment)

for app wallet, do tx.setCollateral(utxo).

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