enhancedGetPrice
Learn how to use the enhancedGetPrice JSON-RPC method.
POST
/
#enhancedGetPrice
enhancedGetPrice
curl --request POST \
--url 'https://rpc.particle.network/solana/#enhancedGetPrice' \
--header 'Authorization: Basic <encoded-value>' \
--header 'Content-Type: application/json' \
--data '
{
"jsonrpc": "2.0",
"id": 1,
"chainId": 101,
"method": "enhancedGetPrice",
"params": [
[
"<string>"
]
]
}
'import requests
url = "https://rpc.particle.network/solana/#enhancedGetPrice"
payload = {
"jsonrpc": "2.0",
"id": 1,
"chainId": 101,
"method": "enhancedGetPrice",
"params": [["<string>"]]
}
headers = {
"Authorization": "Basic <encoded-value>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Basic <encoded-value>', 'Content-Type': 'application/json'},
body: JSON.stringify({
jsonrpc: '2.0',
id: 1,
chainId: 101,
method: 'enhancedGetPrice',
params: [['<string>']]
})
};
fetch('https://rpc.particle.network/solana/#enhancedGetPrice', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://rpc.particle.network/solana/#enhancedGetPrice",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'jsonrpc' => '2.0',
'id' => 1,
'chainId' => 101,
'method' => 'enhancedGetPrice',
'params' => [
[
'<string>'
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Basic <encoded-value>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://rpc.particle.network/solana/#enhancedGetPrice"
payload := strings.NewReader("{\n \"jsonrpc\": \"2.0\",\n \"id\": 1,\n \"chainId\": 101,\n \"method\": \"enhancedGetPrice\",\n \"params\": [\n [\n \"<string>\"\n ]\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Basic <encoded-value>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://rpc.particle.network/solana/#enhancedGetPrice")
.header("Authorization", "Basic <encoded-value>")
.header("Content-Type", "application/json")
.body("{\n \"jsonrpc\": \"2.0\",\n \"id\": 1,\n \"chainId\": 101,\n \"method\": \"enhancedGetPrice\",\n \"params\": [\n [\n \"<string>\"\n ]\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://rpc.particle.network/solana/#enhancedGetPrice")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Basic <encoded-value>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"jsonrpc\": \"2.0\",\n \"id\": 1,\n \"chainId\": 101,\n \"method\": \"enhancedGetPrice\",\n \"params\": [\n [\n \"<string>\"\n ]\n ]\n}"
response = http.request(request)
puts response.read_body{
"jsonrpc": "2.0",
"id": 1,
"chainId": 101,
"result": [
{
"address": "<string>",
"currencies": [
{
"type": "<string>",
"price": 123,
"marketCap": 123,
"24hChange": 123,
"24hVol": 123,
"lastUpdatedAt": 123
}
]
}
]
}Understanding enhancedGetPrice
enhancedGetPriceretrieves the real-time price (fiat exchange rate) of a Solana token (SPL token). It takes:address- array of strings. This represents the SPL token address; for $SOL, you can use the stringnative.currencies- array of strings. It can containusdandcny.
Query example
JavaScript
const axios = require('axios');
(async () => {
const response = await axios.post('https://rpc.particle.network/solana', {
chainId: 103,
jsonrpc: '2.0',
id: 0,
method: 'enhancedGetPrice',
params: [
[
'native',
'2Dzzc14S1D7cEFGJyMZMACuoQRHVUYFhVE74C5o8Fwau',
],
[
'usd',
'cny',
],
],
}, {
auth: {
username: 'Your Project Id',
password: 'Your Project Server Key',
},
});
console.log(response.data);
})();
Authorizations
Basic authentication header of the form Basic <encoded-value>, where <encoded-value> is the base64-encoded string username:password.
Body
application/json
Request to get the price of a token.
Version of the JSON-RPC protocol, should be 2.0.
Example:
"2.0"
The request identifier.
Example:
1
The blockchain chain ID.
Example:
101
API method being called.
Available options:
enhancedGetPrice Parameters for getting token price.
Token address.
Response
200 - application/json
Successful response with token price information.
Was this page helpful?
⌘I
enhancedGetPrice
curl --request POST \
--url 'https://rpc.particle.network/solana/#enhancedGetPrice' \
--header 'Authorization: Basic <encoded-value>' \
--header 'Content-Type: application/json' \
--data '
{
"jsonrpc": "2.0",
"id": 1,
"chainId": 101,
"method": "enhancedGetPrice",
"params": [
[
"<string>"
]
]
}
'import requests
url = "https://rpc.particle.network/solana/#enhancedGetPrice"
payload = {
"jsonrpc": "2.0",
"id": 1,
"chainId": 101,
"method": "enhancedGetPrice",
"params": [["<string>"]]
}
headers = {
"Authorization": "Basic <encoded-value>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Basic <encoded-value>', 'Content-Type': 'application/json'},
body: JSON.stringify({
jsonrpc: '2.0',
id: 1,
chainId: 101,
method: 'enhancedGetPrice',
params: [['<string>']]
})
};
fetch('https://rpc.particle.network/solana/#enhancedGetPrice', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://rpc.particle.network/solana/#enhancedGetPrice",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'jsonrpc' => '2.0',
'id' => 1,
'chainId' => 101,
'method' => 'enhancedGetPrice',
'params' => [
[
'<string>'
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Basic <encoded-value>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://rpc.particle.network/solana/#enhancedGetPrice"
payload := strings.NewReader("{\n \"jsonrpc\": \"2.0\",\n \"id\": 1,\n \"chainId\": 101,\n \"method\": \"enhancedGetPrice\",\n \"params\": [\n [\n \"<string>\"\n ]\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Basic <encoded-value>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://rpc.particle.network/solana/#enhancedGetPrice")
.header("Authorization", "Basic <encoded-value>")
.header("Content-Type", "application/json")
.body("{\n \"jsonrpc\": \"2.0\",\n \"id\": 1,\n \"chainId\": 101,\n \"method\": \"enhancedGetPrice\",\n \"params\": [\n [\n \"<string>\"\n ]\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://rpc.particle.network/solana/#enhancedGetPrice")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Basic <encoded-value>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"jsonrpc\": \"2.0\",\n \"id\": 1,\n \"chainId\": 101,\n \"method\": \"enhancedGetPrice\",\n \"params\": [\n [\n \"<string>\"\n ]\n ]\n}"
response = http.request(request)
puts response.read_body{
"jsonrpc": "2.0",
"id": 1,
"chainId": 101,
"result": [
{
"address": "<string>",
"currencies": [
{
"type": "<string>",
"price": 123,
"marketCap": 123,
"24hChange": 123,
"24hVol": 123,
"lastUpdatedAt": 123
}
]
}
]
}