Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
Add getProgramAccounts and getTokenAccountsByOwner methods to Solana
Browse files Browse the repository at this point in the history
  • Loading branch information
mattstauffer committed Sep 11, 2021
1 parent 9d6fbb1 commit 6efc67f
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/Solana.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,42 @@ public function getConfirmedTransaction(string $transactionSignature): array
return $this->client->call('getConfirmedTransaction', [$transactionSignature])['result'];
}

public function getProgramAccounts(string $pubKey)
{
$probablyMetaPlexKey = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'; // 🤷‍♂️
$magicOffsetNumber = 326; // 🤷‍♂️

return $this->client->call('getProgramAccounts', [
$probablyMetaPlexKey,
[
'encoding' => 'base64',
'filters' => [
[
'memcmp' => [
'bytes' => $pubKey,
'offset' => $magicOffsetNumber,
],
],
],
],
])->json();
}

public function getTokenAccountsByOwner(string $pubKey)
{
$solanaTokenProgramId = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA';

return $this->client->call('getTokenAccountsByOwner', [
$pubKey,
[
'programId' => $solanaTokenProgramId,
],
[
'encoding' => 'jsonParsed',
],
])['result']['value'];
}

// NEW: This method is only available in solana-core v1.7 or newer. Please use getConfirmedTransaction for solana-core v1.6
public function getTransaction(string $transactionSignature): array
{
Expand Down

0 comments on commit 6efc67f

Please sign in to comment.