Skip to content

getTokenAccountsByOwner - #187

Open
wiyarmir wants to merge 1 commit into
mainfrom
guillermo/get-token-accounts-by-owner
Open

getTokenAccountsByOwner#187
wiyarmir wants to merge 1 commit into
mainfrom
guillermo/get-token-accounts-by-owner

Conversation

@wiyarmir

@wiyarmir wiyarmir commented Jan 14, 2025

Copy link
Copy Markdown
Member

TL;DR

Added support for retrieving SPL Token accounts by owner with optional mint or program ID filtering.

What changed?

  • Created a new PublicKeyBase58Serializer for handling Base58 serialization of public keys
  • Implemented getTokenAccountsByOwner methods with support for filtering by mint or program ID
  • Added data classes to represent token account information including account details, token amounts, and ownership data

How to test?

// Test retrieving token accounts by owner and mint
val tokenAccounts = client.getTokenAccountsByOwnerAndMint(
    account = ownerPublicKey,
    mint = mintPublicKey
)

// Test retrieving token accounts by owner and program ID
val programTokenAccounts = client.getTokenAccountsByOwnerAndProgramId(
    account = ownerPublicKey,
    programId = programPublicKey
)

Why make this change?

This addition enables querying and filtering SPL Token accounts, which is essential for applications that need to track token holdings, manage token accounts, or analyze token-related activities for specific accounts on the Solana blockchain.

@github-actions

github-actions Bot commented Jan 14, 2025

Copy link
Copy Markdown
Contributor

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@github-actions

github-actions Bot commented Jan 14, 2025

Copy link
Copy Markdown
Contributor

🥳 JUnit passed

Passed Failed Skipped
✅ 38 ❌ 0 ⚠️ 4

You can see the report here.

🥳 JUnit passed

Passed Failed Skipped
✅ 38 ❌ 0 ⚠️ 4

You can see the report here.

@wiyarmir
wiyarmir requested a review from jszmltr January 14, 2025 16:25
@wiyarmir
wiyarmir force-pushed the guillermo/get-token-accounts-by-owner branch from c589cbe to 9839397 Compare December 16, 2025 15:05

Copy link
Copy Markdown
Member Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

public data class TokenAmount(
public val amount: String,
public val decimals: Int,
public val uiAmount: Double,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Non-nullable uiAmount will fail on null API responses

The uiAmount field in TokenAmount is declared as non-nullable Double, but the Solana RPC API can return null for this deprecated field. The existing TokenAmountInfo class in getTokenAccountBalance.kt correctly uses Double? for this same field. When the API returns null for uiAmount, deserialization will fail with a runtime exception.

Fix in Cursor Fix in Web

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀 ?

@jszmltr jszmltr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an outstanding bot comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants