4

I am building an MERN stack app cardano dex tool, I want to use Blockfrost.

I have installed the SDK in Node.js backend, but there are only very few examples on how to get any kind of data from it.

The [Blockfrost documentation](https://docs.blockfrost.io/( gives more info and I know how to use it with fetch, but only url based and don't know how to implement QUERY PARAMETERS into the url request. Here is an example.

function getAssets(){
        fetch(`https://cardano-mainnet.blockfrost.io/api/v0/assets`,{
            headers: {
                "project_id":'API KEY'
            },
        })
        .then(res=>res.json())
        .then(data=>{console.log(data)})
    }
    getAssets()

If there is someone that could explain me a bit how to start using Blockfrost the proper way with a Node.js backend and basically get any kind of information.

Or maybe there is a better solution to get all data from the Cardano network, I have an relay node running with GraphQL, but getting data from that is very difficult if you just starting to use it and I don't know if it will keep working after the Alonzo fork.

Please someone that can help me pointing the right direction would be awesome.

1

Using the Blockfrost SDK is pretty straight forward, as in this example:

import { BlockFrostAPI } from '../src/index';

async function run() {
  const API = new BlockFrostAPI({
    projectId: 'YOUR API KEY HERE', // see: https://blockfrost.io
  });

  try {
    const latestBlock = await API.blocksLatest();
    const latestEpoch = await API.epochsLatest();
    const health = await API.health();
    const address = await API.addresses(
      'addr1qxqs59lphg8g6qndelq8xwqn60ag3aeyfcp33c2kdp46a09re5df3pzwwmyq946axfcejy5n4x0y99wqpgtp2gd0k09qsgy6pz',
    );

    console.log('address', address);
    console.log('latestEpoch', latestEpoch);
    console.log('latestBlock', latestBlock);
    console.log('health', health);
  } catch (err) {
    console.log('error', err);
  }
}

run();

Basically you can use any of Blockfrost endpoints in the SDK as well, check out the list of available calls. I recommend you using an IDE such as codium as it will autofill these as you code.

1
  • 1
    Hey, thank you for the reply. Well you are right the wiki you show is very clear. Somehow I missed the right menu to get more specific info. Aug 30 at 4:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.