Getting error for Cardano fee executation in Node JS using cmd.runSync

Hi I am trying to get txn fee for a test.txraw file.

When I am running the command on terminal I am getting response.

Command used on terminal: "cardano-cli transaction calculate-min-fee --tx-body-file test.txraw --tx-in-count 1 --tx-out-count 2 --witness-count 2 --testnet-magic 1097911063 --protocol-params-file protocol.json | egrep -o '[0-9]+'"

Response: 202065

On Node JS side I am running this using “node-cmd”

let fee = cmd.runSync([
   "cardano-cli transaction calculate-min-fee",
   `--tx-body-file test.txraw`,
   `--tx-in-count 1`,
   `--tx-out-count 2`,
   `--witness-count 2`,
   `--testnet-magic 1097911063`,
   `--protocol-params-file protocol.json`,
   `| egrep -o '[0-9]+'`

Response: Cannot read property 'toString' of undefined.

Please help on this.

Please run that without the | egrep -o '[0-9]+', so that you (and we) can see the whole error message and not just the part that accidentally fulfils the grep pattern.

This is the error I am getting without | egrep -o ‘[0-9]+’

This is my code.

You seem to have two problems here.

The one with the cardano-cli command itself could best be seen if you run the command on the command line, not within Javascript, without the egrep.

The error by Javascript is that you seem to use cmd.runSync wrong. According to it does not return the output of the command as a script, but an object with different information about the process. You are probably interested in the data attribute.

1 Like

Thanks for your suggestion. I tried with .exec() and got the fee amount.

Thanks a lot.