Get the price of the Raydium token using the Solscan API: a quick guide
In recent times, Solana has become a main platform for decentralized applications (DAPP), and its native cryptocurrency, Raydium Token (Ray), has drawn significant attention. As a popular commercial pair on Solana’s blockchain, Ray is closely monitored by traders and investors. In this article, we will explore the process of obtaining the current price of the Raydium token using the Solscan API (Pro).
What is the Solscan API?
The Solscan API (Pro) is a powerful tool that allows developers to interact with Solana’s Blockchain by program. It gives access to various APIs, including Solscan, which offers a range of features and tools to create personalized applications.
To start: Configure the Solscan API
To use the Solscan API, you will need to save an account on the Solscan platform and get your API key. Here is a step by step guide:
- Go to the [Solscan website] (
- Click on “Create an account” and follow the instructions.
- Fill in the registration form with your email, password and other details.
- Check your account by clicking on the link sent to your email.
Obtain a Solscan API key
Once you have recorded an account, you will receive a single API key. To use this key in the Solscan API, follow these steps:
- Connect to your Solscan account and access the “API Keys” section.
- Click on “Generate a new API key”.
- Fill out the form with your API key and other details (for example, name, e-mail).
- Download your API key as a JSON file.
To start with the SOLSCAN API
Now that you have your API key, you can start using it to get the price of the Raydium token on Solana. Here is an example of an extract of code in Rust:
`Rust
Use Solana_sdk :: Account_info :: {Accountinfo, Programmid};
Use Solana_SDK :: Key_pair :: Keypair;
Use Solana_SDK :: Transaction :: Transaction;
// Define the API key and account information for the Raydium token
Const Ray_Api_Key: & Str = "Your_api_key";
Const Ray_account_info: & actinfo = & account
Pub key: Keypair :: new ([1, 0]), // replace with your public address
Pub Program_ID: Programid :: From_str ("Ray"). UNFRAP (),
};
// Define the transaction to get the price of the Raydium token
async fn get_raydium_token_price () -> Result <(), box
Leave mured transaction = transaction :: new ();
transaction.set_program_id (publickey :: from_str ("your_public_address"));
transaction.add_input_account_info (ray_account_info);
transaction.sign (& Ray_Api_Key);
// Execute the transaction
Let (tx_hash, _, _) = Solana_sdk :: Transaction :: Run_transaction (Transaction) .await?;
Let transaction_result = tx_hash.as_ref (). A little ();
Match transaction_result {
Ok (_) => ok (()),
Err (e) => err (box :: new (std :: error :: error :: from (e))),
}
}
// Main function
async fn main () -> Result <(), box
Let result = get_raydium_token_price (). Await?;
if! result.is_ok () {
EPRINTLN! ("Error: {}", result);
back;
}
// Prints the price of the Raydium token
Println! ("Raydium Token Price: {}", result.unwrap ());
All right(())
}
'
Code execution
Save this code in a file (for example,get_raydium_token_price.rs) and run it using your favorite IDE or control line. Replace the reserved spaces (
your_api_key,
your_public_address, etc.) with your real -solscan key, your public address and other details.
Tips and variations
- To obtain the current price of the Raydium token, you can modify the transaction to use theGet_price function” on Solana.
- You can also use the
Get_Account_info
in Function to recover information on specific accounts, including their sales and addresses.