Cartão de receitas de referência rápida - pronto para copiar e colar.
import asyncio
import httpx
from solders.pubkey import Pubkey
from solana.rpc.async_api import AsyncClient
RPC = "https://api.devnet.solana.com"
DAS = "https://devnet.helius-rpc.com/?api-key=<KEY>" # provider with DAS enabled
OWNER = Pubkey.from_string( "<OWNER_PUBKEY>" )
async def fetch_portfolio ():
async with AsyncClient( RPC ) as client:
sol = await client.get_balance( OWNER )
sigs = await client.get_signatures_for_address( OWNER , limit = 10 )
token_resp = await client.get_token_accounts_by_owner_json_parsed(
OWNER ,
{ "programId" : "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" },
)
tokens = token_resp.value
async with httpx.AsyncClient() as http:
das_resp = await http.post(
DAS ,
json = {
"jsonrpc" : "2.0" ,
"id" : 1 ,
"method" : "getAssetsByOwner" ,
"params" : { "ownerAddress" : str ( OWNER ), "page" : 1 , "limit" : 50 },
},
)
assets = das_resp.json()[ "result" ]
return {
"lamports" : sol.value,
"recent_signatures" : [s.signature for s in sigs.value],
"spl_tokens" : len (tokens),
"das_assets" : len (assets.get( "items" , [])),
}
print (asyncio.run(fetch_portfolio()))
Versões Stack: Esta página foi escrita para Agave 4.1.1 , Solana CLI 3.0.10 , Anchor 0.32.1 , anchor-lang 0.32.1 , Rust 1.91.1 , @solana/kit 7.0.0 , Surfpool 0.12.0 e LiteSVM 0.6.x .