miguelaeh/cardanocli-js

TypeError: Cannot read property 'forEach' of undefined

Closed this issue · 6 comments

Hey all,

Currently trying to mint a one-off CNFT using this amazing repo, but seem to run into an issue when attempting the minting process. More specifically, here is the error message I get when running my minting script:

/<MY-PATH>/node_modules/cardanocli-js/helper.js:145
  minting.action.forEach((mint, index, arr) => {
                 ^

TypeError: Cannot read property 'forEach' of undefined
    at exports.mintToString (/<MY-PATH>/node_modules/cardanocli-js/helper.js:145:18)
    at CardanocliJs.transactionBuildRaw (/<MY-PATH>/node_modules/cardanocli-js/index.js:854:39)
    at buildTransaction (/<MY-PATH>/src/mint-asset.js:99:25)
    at Object.<anonymous> (/<MY-PATH>/src/mint-asset.js:110:13)

See actual minting script below:

const cardano = require("./cardano")

// 1. Get the wallet

const wallet = cardano.wallet("<MY-WALLET-NAME>");

// 2. Define mint script

const mintScript = {
    type: "all",
    scripts: [
        {
            slot: 49483967,
            type: "before"
        },
        {
            keyHash: cardano.addressKeyHash(wallet.name),
            type: "sig"
        }
    ]
}

// 3. Create POLICY_ID

const POLICY_ID = cardano.transactionPolicyid(mintScript)

// 4. Define ASSET_NAME

const ASSET_NAME = "TestCNFT001"

// 5. Create ASSET_ID

const ASSET_ID = POLICY_ID + "." + ASSET_NAME

// 6. Define metadata

const metadata = {
    721: {
        [POLICY_ID]: {
            [ASSET_NAME]: {
                name: ASSET_NAME,
                image: "ipfs://<IPFS-HASH>",
                description: "Test CNFT 001",
                type: "image/png",
            }
        }
    }
}

// 7. Define transaction

const tx = {
    txIn: wallet.balance().utxo,
    txOut: [
        {
            address: wallet.paymentAddr,
            value: { ...wallet.balance().value, [ASSET_ID]: 1 }
        }
    ],
    mint: {
        actions: [{ type: "mint", quantity: 1, asset: ASSET_ID }],
        script: [mintScript]
    },
    metadata,
    witnessCount: 2
}

// 8. Build transaction

const buildTransaction = (tx) => {

    const raw = cardano.transactionBuildRaw(tx)
    const fee = cardano.transactionCalculateMinFee({
        ...tx,
        txBody: raw
    })

    tx.txOut[0].value.lovelace -= fee

    return cardano.transactionBuildRaw({ ...tx, fee })
}

const raw = buildTransaction(tx)

// 9. Sign transaction

const signTransaction = (wallet, tx) => {

    return cardano.transactionSign({
        signingKeys: [wallet.payment.skey, wallet.payment.skey],
        txBody: tx
    })
}

const signed = signTransaction(wallet, raw)

// 10. Submit transaction

const txHash = cardano.transactionSubmit(signed)

console.log(txHash)

Any clues as to why this error is being triggered?

Just got this same error when I tried to mint an nft as well...

helper.js
line 145 >
minting.actions
instead of minting.action

Has been updated 4 days ago, update and the above fix was added :)

I am still getting an error when trying to mint my NFT. Code is pretty much the same as above. Getting even after I replace mint.action with mint.actions. I even cloned your repo and imported the index.js to make sure the versioning is appropriate. Not sure what the issue is. Should I open a separate issue?
CleanShot 2021-10-25 at 15 48 09@2x

They have updated their code beyond that. It's different and I haven't gotten back into using this yet.

So the code that I mentioned doesn't work anymore. It did, then they changed it. If you notice the 'actions' isn't there anymore, it's minting.forEach instead of minting.actions.forEach so... you'll have to look through the code and figure out what it's doing. Fix it and maybe do a pull request. I stopped using this until they update it further.

Hi @dlm001 ,
You can find a working example at examples/mintMA.js. After the upgrade for supporting multi-assets, you need to specify an array.

const tx = {
  txIn: wallet.balance().utxo,
  txOut: [
    {
      address: wallet.paymentAddr,
      value: { ...wallet.balance().value, [BERRYCOIN]: 100 },
    },
  ],
  mint: [
    { action: "mint", quantity: 100, asset: BERRYCOIN, script: mintScript },
  ],
  witnessCount: 2,
};