getTokenAccountsByOwner
Returns all token accounts for a given owner
Parameters
Public key of the owner (base-58 encoded)
Configuration object containing:
Public key of the token program (base-58 encoded)
Commitment level (processed, confirmed, finalized)
Encoding for account data (base58, base64, jsonParsed)
Response
Object containing:
Array of token account objects containing:
Public key of the token account (base-58 encoded)
Number of lamports in the account
Public key of the account owner (base-58 encoded)
Whether the account is executable
Epoch at which the account will next owe rent
Public key of the token’s mint (base-58 encoded)
Public key of the token account owner (base-58 encoded)
Public key of the delegate (base-58 encoded)
Type of account (account)
Program that owns the account (spl-token)
Number of bytes allocated to the account
Code Examples
Basic Request
Using web3.js
Notes
- Returns all token accounts owned by the given public key
- The owner has full control over these accounts
- The response is immediate as it reads from the current state
- The accounts can change with token transfers and other operations
- The owner must be a valid public key
Best Practices
- Use appropriate commitment level based on your needs
- Cache results when appropriate to reduce RPC load
- Monitor for changes in owned accounts
- Consider using websocket subscription for real-time updates
- Handle network errors and retry when appropriate
Common Errors
Code | Message | Solution |
---|---|---|
-32601 | Method not found | Verify you’re connected to a Solana RPC node |
-32602 | Invalid params | Check owner public key and configuration |
-32007 | Owner not found | Verify the owner exists |
-32008 | Invalid program ID | Verify the program ID is correct |
Use Cases
-
Owner Account Analysis
-
Owner Account Monitoring
-
Owner Account Planning