3

I am creating a token-sale program, to sale tokens, I want to transfer spl-tokens to a PDA-address, so I can transfer them from PDA-token-account to recipient(transaction-signer)-token-account by signing token::transfer transaction using the seeds of PDA inside program

I was able to transfer spl-tokens to PDA on localnet like this:

sellerTknAcc = await getOrCreateAssociatedTokenAccount(
  connection,
  deployer,
  mint,
  _tokensForSalePDA,
  true // allowOwnerOfCurve - allow pda accounts to be have associated token account
);

await transferSpl(
  connection,
  deployer,
  mint,
  _tokensForSalePDA,
  exchangeBal1
); 

But when I executed getOrCreateAssociatedTokenAccount() on devnet, I got this error: Server responded with 429 Too Many Requests

Then, I tried this code

const token_acc = await getAssociatedTokenAddress(
  beybladeMint,
  tokensForSalePDA,
  true
);
const transaction = new Transaction().add(
  createAssociatedTokenAccountInstruction(
    provider.publicKey,
    token_acc,
    tokensForSalePDA,
    beybladeMint,
    program.programId
  )
);
const txn = await provider.sendAndConfirm(transaction);

and got this error:

SendTransactionError: failed to send transaction: Transaction simulation failed: Error processing Instruction 0: Provided seeds do not result in a valid address
    at Connection.sendEncodedTransaction (/home/mahesh/Desktop/solana/token-sale_program/node_modules/@solana/web3.js/src/connection.ts:5054:13)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Connection.sendRawTransaction (/home/mahesh/Desktop/solana/token-sale_program/node_modules/@solana/web3.js/src/connection.ts:5013:20)
    at async sendAndConfirmRawTransaction (/home/mahesh/Desktop/solana/token-sale_program/node_modules/@project-serum/anchor/src/provider.ts:288:21)
    at async AnchorProvider.sendAndConfirm (/home/mahesh/Desktop/solana/token-sale_program/node_modules/@project-serum/anchor/src/provider.ts:148:14) {
  logs: [
    'Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL invoke [1]',
    'Program log: Create',
    'Program log: Error: Associated address does not match seed derivation',
    'Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL consumed 5058 of 200000 compute units',
    'Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL failed: Provided seeds do not result in a valid address'
  ]
}

2 Answers 2

1

If you are using the public mainnet RPCs, such as https://api.mainnet-beta.solana.com, you are limited in what you can do with programs to a set program list

Namely:

Stake11111111111111111111111111111111111111
Vote111111111111111111111111111111111111111
BPFLoader1111111111111111111111111111111111
BPFLoader2111111111111111111111111111111111
BPFLoaderUpgradeab1e11111111111111111111111
11111111111111111111111111111111
Config1111111111111111111111111111111111111
namesLPneVptA9Z5rqUDD9tMTWEJwofgaYwp8cawRkX

If you try to use getProgramAccounts outside of those programs you won't get a successful message.

Recommendation is to use one of the many other free RPCs that are available.

0

Problem was with official-rpc-provided by solana, when I used rpc from Alchemy, I was able to transfer spl-token to PDA-account.

1
  • Can you help to explain?
    – agentp
    Apr 5, 2023 at 17:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.