Insufficient Input in transaction for burning assets, cardano_serialization_library

I am creating a script in which i am trying to burn an asset using @emurgo/cardano-serialization-lib-nodejs

 txBuilder.add_mint_asset(
      allScript,
      CardanoWasm.AssetName.new(Buffer.from("NFT")),
      CardanoWasm.Int.new_negative(CardanoWasm.BigNum.from_str("1"))
    );

i am getting the following as I run my script

Insufficient input in transaction. shortage: {policy id: “aad0401c838240d6250c56ccd0109950c566739e7f30195cb6241fb8”, asset name: “4e4654” coins in inputs: 0, coins in outputs: 1
}

i tried to use the add_input_key function to input the assets still not working

You can only burn what you have on an UTxO on one of the addresses you control. And you have to add that UTxO to the transaction with add_input.

I don’t know what add_input_key does. It does not show up in https://github.com/Emurgo/cardano-serialization-lib/blob/master/rust/pkg/cardano_serialization_lib.js.flow.

Burning NFT · Issue #432 · Emurgo/cardano-serialization-lib · GitHub

i am trying this issue link right now I’ll update if it’ll workout

is add_input function for assets input in the transaction?

const txBuilder = CardanoWasm.TransactionBuilder.new(txBuilderCfg);
    txBuilder.add_key_input(
      PRIVATE_KEY.to_public().hash(),
      CardanoWasm.TransactionInput.new(
        CardanoWasm.TransactionHash.from_bytes(
          Buffer.from(
            "5330de8020ed8df6db20274959f9283edb30f89d1794fcbdeed8105dedaedcb7",
            "hex"
          )
        ),
        1
      ),
      CardanoWasm.Value.new(CardanoWasm.BigNum.from_str("1150770"))
    );
    txBuilder.add_mint_asset(
      allScript,
      CardanoWasm.AssetName.new(Buffer.from(assetName)),
      CardanoWasm.Int.new_negative(CardanoWasm.BigNum.from_str("1"))
    );

i tried this thing but it didn’t worked getting the same error

Ah, add_key_input, not add_input_key. Yes, seems to be the correct function. Don’t know the difference to add_input and the documentation is legendarily unhelpful, but it should work as in your example.

Are you absolutely sure that allScript is the one belonging to the policy ID aad0401c838240d6250c56ccd0109950c566739e7f30195cb6241fb8 and that assetName is nftName?

yes it does belong to the same policy id

i’ll try to create a new nft with different policy id and then i’ll burn it

one thing i noticed is my asset metadata also had the description part is it possible that’s why i wasn’t able to burn it when i used the function add_mint_asset()?

My suspicion would rather be the assetName, since you wrote here

quite clearly that you were trying to burn one NFT, but if I look at

the NFTs on there are six nftNames.

The asset name has to match exactly.

Burning does not care about metadata at all, minting also not really. The metadata are an additional standard that wallet apps and others have agreed on. The blockchain itself does not care about them.

i have minted a new asset

Preview Policy a788fce773ab5748e3e3483f0343866a8a21208a7aad89a34f3f48eb - Cardanoscan

here is the utxo

 "address": "addr_test1qz6uleapn0tzd0gdyejhanadqnw3jnxg9gvxzwfr8g3x4d220lldl3pyxdvp8nxdgd2hjmleruq6fqjyu4caztnx6scq53l9kh",
        "tx_hash": "8aa72135dd469466c4a729917bcc60e723a665b64d80507a8f5ac12064d3a1e9",
        "tx_index": 0,
        "output_index": 0,
        "amount": [
            {
                "unit": "lovelace",
                "quantity": "120000000"
            },
            {
                "unit": "a788fce773ab5748e3e3483f0343866a8a21208a7aad89a34f3f48ebe382a2e382bbe38383e38388",
                "quantity": "1"
            }

the policy id from the script: a788fce773ab5748e3e3483f0343866a8a21208a7aad89a34f3f48eb

const txBuilder = CardanoWasm.TransactionBuilder.new(txBuilderCfg);
    txBuilder.add_key_input(
      PRIVATE_KEY.to_public().hash(),
      CardanoWasm.TransactionInput.new(
        CardanoWasm.TransactionHash.from_bytes(
          Buffer.from(
            "8aa72135dd469466c4a729917bcc60e723a665b64d80507a8f5ac12064d3a1e9",
            "hex"
          )
        ), // tx hash
        0 // index
      ),
      CardanoWasm.Value.new(CardanoWasm.BigNum.from_str("120000000"))
    );

 txBuilder.add_mint_asset(
      allScript,
      CardanoWasm.AssetName.new(Buffer.from(assetName)),
      CardanoWasm.Int.new_negative(CardanoWasm.BigNum.from_str("1"))

assetName is the exact name as in transaction link

Insufficient input in transaction. shortage: {policy id: "a788fce773ab5748e3e3483f0343866a8a21208a7aad89a34f3f48eb", asset name: "e382a2e382bbe38383e38388" coins in inputs: 0, coins in outputs: 1

Okay, that looks correct. The NFT it is missing in

does exist on the output with index 0 of:

Only thing left that I could think of is that in

you do not tell it that that input does contain the NFT in addition to the ADA, but I find it strange that I cannot google any example, where it is given.

i did found this link where it is taking asset as an input

cardano serialization lib - How to add multiasset as input to txBuilder? - Cardano Stack Exchange

but i was bit confused about the assetStr variable is the name of the asset in the number form as input

const assetsToSend = CardanoWasm.MultiAsset.new();
    const assets = CardanoWasm.Assets.new();
    const policyStr =
      "d12b505315d97870eb4d0f9d1be2e461d41a1a3bdaf22501b1abe101";

    // const assetStr = "6173736574";
    const asset = CardanoWasm.AssetName.new(Buffer.from(assetName));

    // creating asset value for lovelaces
    const assetsValue = CardanoWasm.Value.new(
      CardanoWasm.BigNum.from_str("10000000")
    );

    // Inserting Native token
    assets.insert(asset, CardanoWasm.BigNum.from_str("1"));

    // Adding asset to multiasset
    assetsToSend.insert(
      CardanoWasm.ScriptHash.from_bytes(Buffer.from(policyStr, "hex")),
      assets
    );
    // Setting value with multiasset
    assetsValue.set_multiasset(assetsToSend);

    txBuilder.add_input(
      CardanoWasm.Address.from_bech32(OWNER_ADDRESS),
      CardanoWasm.TransactionInput.new(
        CardanoWasm.TransactionHash.from_bytes(
          Buffer.from(
            "b76d7c9da6a8ee350f5e86aabb668b73a0216810cb7cd49ba8ccdac8577c65b6",
            "hex"
          )
        ), // tx hash
        0 // index
      ),
      assetsValue
      //   CardanoWasm.Value.new(CardanoWasm.BigNum.from_str("1150770"))
    );

adding this thing worked out i had to remove the the add_key_input part and when i added this part
in the


const assetsValue = CardanoWasm.Value.new(
      CardanoWasm.BigNum.from_str("10000000")
    );

for some reason this part was taking the ada in that utxo in which i also had my asset
here is the utxo

 {
        "address": "addr_test1qz6uleapn0tzd0gdyejhanadqnw3jnxg9gvxzwfr8g3x4d220lldl3pyxdvp8nxdgd2hjmleruq6fqjyu4caztnx6scq53l9kh",
        "tx_hash": "b76d7c9da6a8ee350f5e86aabb668b73a0216810cb7cd49ba8ccdac8577c65b6",
        "tx_index": 0,
        "output_index": 0,
        "amount": [
            {
                "unit": "lovelace",
                "quantity": "10000000"
            },
            {
                "unit": "d12b505315d97870eb4d0f9d1be2e461d41a1a3bdaf22501b1abe1016173736574",
                "quantity": "1"
            }
        ],
        "block": "93b2aeeb4126011596e11e29d354b6d56124a970cb2129b5d7f77408fe6fd98d",
        "data_hash": null,
        "inline_datum": null,
        "reference_script_hash": null
    }

here is the transaction

Preview Transaction 2924d380abca317f95452df69a0a0deb2911c07038ad8c5f087fd8a3152f04ce - Cardanoscan

1 Like

@HeptaSean sorry about pinging you just wanted to ask if there is a way i can change my tx script in a dynamic way that if i pass all the utxo it can select on its own or should i have to create my own logic to make this thing work?

Does this discussion maybe help?

add_inputs_from seems to do the job of selecting inputs from a set of UTxOs given to it:

thanks for the links! i’ll check them