0

I need some help with solana.py API (for python). I am trying to get total supply of the token (token here) - so I copy mint address according to documentation (gettokensupply) and write usual code on solana==0.25.1:

 from solana.rpc.api import Client
 from solana.publickey import PublicKey
 http_client_solana = Client("https://api.devnet.solana.com")
 pubkey = PublicKey("CxwTQccajoiDn9Xb7BpTbvDQXEaSKNYQWMCUETiNgidZ")
 response = http_client_solana.get_token_supply(pubkey)

 amount = int(response["result"]['value']['amount'])
 decimals = response["result"]['value']['decimals']

But I receive a response:

{'jsonrpc': '2.0', 'error': {'code': -32602, 'message': 'Invalid param: could not find account'}, 'id': 1}

I don't understand what I am doing wrong, is it a problem on my end? I tried using it also with a coin address, but I still get the same error. I checked if I used exactly the mint and tried to call it using mentioned address in the example, but still receive the same error. I tried researching the problem, but found no hints.

2 Answers 2

3

Just change the devnet url to mainnet. That is, change https://api.devnet.solana.com to https://api.mainnet-beta.solana.com

2
  • I appreciate your help! It was the problem indeed, now it is solved. One colleague mentioned on the community server, that Devnet is a testnet (I assume, it's a net for tests), but we are trying to get an address from mainnet => we must use mainnet URL. P.S.-The credits for advice go to someone named 'Raliphey'. Commented Feb 22, 2023 at 17:42
  • Solana also has something it calls testnet but it's mainly for validators to test stuff. But yes both devnet and testnet are not real money docs.solana.com/clusters
    – KevinH
    Commented Feb 22, 2023 at 19:09
0

I've tried the same with https://api.mainnet-beta.solana.com but same issue.

..
# Initialize the client
client = Client("https://api.mainnet-beta.solana.com")
...
token_mint_address = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"  # USDC mint address
token_mint_pubkey = Pubkey.from_string(token_mint_address)
...
response = client.get_token_account_balance(token_mint_pubkey,commitment='confirmed')

response gives me just the error message 'Invalid param: not a Token account' instead of a proper answer.

What am I doing wrong here?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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