Home > Software engineering >  Does @Solana/web3.js support the current price for Solana?
Does @Solana/web3.js support the current price for Solana?

Time:04-23

I am currently using the @Solana/web3.js module and want to grab the current price for Solana in order to convert a user's balance to USD .etc.

CodePudding user response:

The @solana/web3.js module currently concerns itself solely with interacting with native Solana programs as well as giving the tools to interact with the Solana blockchain via the RPC.

I recommend using CoinGecko's API to find the current USD value of SOL and other tokens.

CodePudding user response:

Here is a client side example, notice that the url params

ids=solana vs_currencies=usd

var url = "https://api.coingecko.com/api/v3/simple/price?ids=solana&vs_currencies=usd";

var xhr = new XMLHttpRequest();
xhr.open("GET", url);

xhr.setRequestHeader("accept", "application/json");

xhr.onreadystatechange = function() {
  if (xhr.readyState === 4) {
    console.log(xhr.status);
    console.log(xhr.responseText);
  }
};

xhr.send();

  • Related