NodeJs-based development

Hi folks,

I’m developing a simple service for minting, transferring native tokens using NodeJS but don’t know which SDK or libraries to use. Can you suggest me some? I want basic functionalities like query UTXOs, choosing UTXOs based on output amount, creating and sending transaction, and minting native tokens (NFTs).

Thanks!!

Cardano is primarily made with Haskell and there is no official support for JavaScript, NodeJS, etc.

This is the closest thing resembling the kind of SDK you’re looking for

Additional cursory search query on GitHub reveals a few other attempts at API wrappers

1 Like

Hey,

Check out this blog post
Node.js: writing shell scripts

Here is their code:

module.exports.exec = function (command, {capture = false, echo = false} = {}) {
command = command.replace(/\?\n/g, ‘’); // need to merge multi-line commands into one string

if (echo) {
console.log(command);
}

const spawn = require(‘child_process’).spawn;
const childProcess = spawn(‘bash’, [‘-c’, command], {stdio: capture ? ‘pipe’ : ‘inherit’});

return new Promise((resolve, reject) => {
let stdout = ‘’;

if (capture) {
  childProcess.stdout.on('data', (data) => {
    stdout += data;
  });
}

childProcess.on('error', function (error) {
  reject({code: 1, error: error});
});

childProcess.on('close', function (code) {
  if (code > 0) {
    reject({code: code, error: 'Command failed with code ' + code});
  } else {
    resolve({code: code, data: stdout});
  }
});

});
};

Then you could call the cli commands like this:

const addr = ’abcde’
await exec('cardano-cli query utxo --address ’ + addr);

You can even get the result back into a variable:

const data = (await exec('cardano-cli query utxo --address ’ + addr)).data;

I havent tested this myself but it will hopefully put you on the right track

Good luck :+1:t3:

2 Likes

Thank you @Cardano-Cal and @DinoDude.