Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix getProgramDerivedAddress() Example to Destructure as an Array Instead of an Object #118

Closed
sebastien3k opened this issue Feb 14, 2025 · 1 comment · Fixed by #120
Closed

Comments

@sebastien3k
Copy link

packages/addresses/README.md

has the following example:

import { getAddressEncoder, getProgramDerivedAddress } from '@solana/addresses';

const addressEncoder = getAddressEncoder();
const { bumpSeed, pda } = await getProgramDerivedAddress({
    programAddress: 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL' as Address,
    seeds: [
        // Owner
        addressEncoder.encode('9fYLFVoVqwH37C3dyPi6cpeobfbQ2jtLpN5HgAYDDdkm' as Address),
        // Token program
        addressEncoder.encode('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Address),
        // Mint
        addressEncoder.encode('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v' as Address),
    ],
});

Following a tutorial from QuickNode https://www.quicknode.com/guides/solana-development/tooling/web3-2/account-deserialization they provided this example:

async function main() {
    // Create encoders for PDA derivation
    const u16BEEncoder = getU16Encoder({ endian: Endian.Big });

    // Derive config account address
    const [configPda] = await getProgramDerivedAddress({
        programAddress: PROGRAM_ID,
        seeds: [
            AMM_CONFIG_SEED,
            u16BEEncoder.encode(AMM_CONFIG_INDEX),
        ]
    });

    console.log(`Parsing AMM Config PDA: ${configPda}`);

    // TODO - fetch and parse PDA
}

main().catch(console.error);

The latter worked as intended while the former did not. Examining getProgramDerivedAddress() from 'packages/addresses/src/program-derived-address.ts' seems to confirm the function returns an array. If this is the case, documentation should be updated to reflect that. I initially thought there was an issue with how my seeds were encoded, especially since I’m not using TypeScript. If the current documentation is correct and I’m missing something, feel free to disregard!

@steveluscher
Copy link
Collaborator

Thank you!

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 a pull request may close this issue.

2 participants