Using knowledge of the following facts:
- All nonce accounts are owned by the system program
- Nonce accounts are exactly 80 bytes long
- The nonce authority's public key is written into bytes 8–40
You can find all of the nonce accounts for which X is the authority using getProgramAccounts
:
import { Connection, PublicKey, clusterApiUrl } from '@solana/web3.js';
const AUTHORITY_PUBLIC_KEY = new PublicKey(
'A1FGsvF7c87UgjYxDyC22rAKAqchBAcFLSMcAGhECLKV'
);
const SYSTEM_PROGRAM_ADDRESS = new PublicKey(
'11111111111111111111111111111111'
);
const connection = new Connection(clusterApiUrl('testnet'));
const nonceAccounts = await connection.getProgramAccounts(
// The system program owns all nonce accounts.
SYSTEM_PROGRAM_ADDRESS,
{
filters: [
{
// Nonce accounts are exactly 80 bytes long
dataSize: 80,
},
{
// The authority's 32-byte public key is written
// into bytes 8-40 of the nonce's account data.
memcmp: {
bytes: AUTHORITY_PUBLIC_KEY.toBase58(),
offset: 8,
},
},
],
}
);
console.log(nonceAccounts);
Playground link.