Questions tagged [pda]
The pda tag has no usage guidance.
295 questions
2
votes
2
answers
41
views
Make reading from PDAs private
If I remember correctly, PDA can be found out by anyone who knows the seed, Public Keys and the Program ID related to a Solana program. Is there a mechanism through which no one except the public key ...
2
votes
2
answers
242
views
How to sign with PDAs
I have a this function
pub fn sign_up(ctx: Context<SignUp> , user_name: String , phone_number: String , email: String) -> Result<()> {// logic is here}
And in SignUp i have :
#[derive(...
5
votes
3
answers
657
views
how to fetch list of all pda accounts in frontend? like sale account instance to display in the market? or should i be fetching from token account?
i have a sale order account defined like this..
#[account]
pub struct Order {
pub creator: Pubkey,
pub mint_key: Pubkey,
pub memo: String,
pub price: u64,
pub bump: u8,
}
And this ...
9
votes
2
answers
4k
views
IllegalOwner error: Provided owner is not allowed
I am having this error when processing instructions for a transaction.
Detail error log:
Transaction simulation failed: Error processing Instruction 1: Provided owner is not allowed
Program ...
3
votes
1
answer
387
views
Instruction Error after upgrading solana program
I deployed a program. some account interact with it and created PDA for the user state of the program.
After a while I upgraded the program because i need to modify the user state PDA, adding a new ...
2
votes
1
answer
49
views
How do I restrict the rights to the created PDA?
I want anyone to be able to create a PDA, but only I can edit it. I was able to do this with "constraint", but when I send the transaction I also need to send signers. Is it ok? Or it can be ...
5
votes
2
answers
204
views
Confusion about PDAs
pda are generated with combination of seeds and bump, so if I know seeds and bump (in case if I don't know the bump, I can brute force it[0-255]) used by program to generates a pda to hold some ...
1
vote
1
answer
2k
views
Anchor init PDA fails with "signer privilege escalated"
I probably am doing something really stupid but this basic thing doesn't seem to work for me for this scenario. I checked the other questions similar to this one but they are either different ...
1
vote
1
answer
97
views
Can I read information stored by a PDA without having to deserialize its byte array?
here is my on-chain code to create the PDA account
#[derive(Accounts)]
pub struct Initialize<'info> {
#[account(init, payer = user, space = 20 , seeds = [user.key().as_ref()], bump)]
...
2
votes
1
answer
326
views
I want to create multiple PDA accounts made with different seeds belonging to a single user/wallet. to be exact I want to initialize multiple PDA Aco [closed]
I want to create multiple PDA accounts made with different seeds belonging to a single user/wallet. to be exact I want to initialize multiple PDA Accounts with different seeds or bumps belonging to a ...
4
votes
1
answer
1k
views
Anchor: How to set a PDA with seeds using variables from another account that is also being initialized?
What is the correct way to initialize a PDA using data from another account in the seeds that is simultaneously being initialized?
In the [#derive(Accounts)] section below, I am trying to use the ...
2
votes
1
answer
87
views
Multiple Valid PDAs with the same seeds but Different Bump?
Is it possible to have multiple valid PDAs (off the curve) using the same seeds? since bump can be from 0 to 255.
find_program_address
This function will do its very best to find an address off the ...
1
vote
2
answers
140
views
Validation check on inputs
I have a sign_up function :
pub fn sign_up(ctx: Context<SignUp> , user_name: String , phone: String , email: String) -> Result<()> {// Code is here }
and one of the arguments is ...
4
votes
5
answers
592
views
Anchor - Manually setting program account discriminator
Is it possible to set the 8-byte discriminator on an Anchor account manually?
I'm trying to initialize a new pda account in an instruction, but not all of the seeds are available in the context (can't ...
7
votes
3
answers
749
views
How to withdraw SOL from a PDA
I want to use my pda as a vault.
Deposit function works fine, but withdraw doesn't
pub fn withdraw(ctx: Context<DepositWithdrawVault>, amount: u64) -> Result<()> {
let ...
4
votes
1
answer
85
views
Can you modify a non-PDA account's data when you know its private key [closed]
I am gathering some information about the advantages of PDA accounts over accounts that have private keys. While the obvious one is that there is the potential vulnerability that you can withdraw ...
0
votes
2
answers
262
views
How do I use PDA account to pay for new PDA account
I am struggling to successfully create a PDA account (pdaUSER) paid for by another PDA account.
I am doing it like this, and it does not work:
invoke_signed(
&system_instruction::...
1
vote
3
answers
206
views
Unauthorized signer on CPI transfer call
so I am trying to write an app where we can deposit native SOL to a wallet, that wallet would be a PDA, and based on some event I would like to transfer SOL to a particular wallet via a CPI call but I ...
1
vote
1
answer
92
views
In Anchor, how do I init a callee's account that's used to create CpiContext in caller's program?
I'm trying to make CPI to the callee program to initialize a config account when I do initialization in caller's program. One of the accounts used in callee's initialization used #[account(init)], but ...
0
votes
3
answers
269
views
Issue, transfer SOL via CPI call
I am trying to make a SOL transfer via a CPI call, I managed to create an account to which I have to transfer, this account's authority is owned by a (master) PDA, transfer/deposit works fine but when ...
3
votes
0
answers
139
views
Is it possible to use conditional seed for PDA creation?
So, the two endpoints I am using are almost identical, the only difference being the seed used in the creation of PDA for each of the accounts.
I will start with the abstract of my program:
First of ...
0
votes
2
answers
193
views
Having a Solana program mint tokens while a user pays the fee [closed]
I'm trying to have a Solana Anchor program mint tokens to a user's token account (so the program or its PDA should be the authority for the mint), while the owner of the token account that's receiving ...
4
votes
3
answers
661
views
Can anyone create an account at a specific PDA address?
Let's say that I have a program printing receipts for an action in order to either enable further actions or restrict actions depending on the existence of the PDA address.
The question is, could ...
0
votes
2
answers
45
views
How can I instances of an account when more than one ref is used for seeds?
In order to create history and statistics, I'm struggling to figure out the best way to implement a lookup system. I'm building a game, and right now, my init for the entrant account looks like this:
...
1
vote
2
answers
89
views
What stops malicious clients from using PDAs in a series of CPIs with anchor?
Let's say we have a series of programs (A -> B -> C) and each one uses PDAs for which the user public keys are used as the seeds.
If a normal user calls ProgramA I think this is safe because the ...
1
vote
2
answers
219
views
Using bump constraint for a PDA with AccountLoader
According to the Anchor Book bump constraint can be specified for a PDA, so Anchor doesn't need to search for it:
#[derive(Accounts)]
pub struct ChangeUserName<'info> {
pub user: Signer<'...
3
votes
2
answers
139
views
How secure is a PDA when generated client-side?
Going through the anchor-docs provided by the official Anchor github I've learned a fair bit about how PDAs work and manipulating them. Though I get a sneaking feeling like its extremely insecure and ...
0
votes
3
answers
76
views
deposit sol from 2 accounts [closed]
I was wondering if I want 2 accounts to deposit SOL to a PDA, would that imply to use a multisig or that can be done without multisig? Suppose 2 wallets have to deposit sol to that account, and based ...
1
vote
2
answers
209
views
Using Anchor, how to have PDA created without the PDA info being sent by the client?
Program:
#[derive(Accounts)]
pub struct Transact<'info> {
#[account(init, payer=payer, space= 8 + 1 + 4, seeds=[b"transaction", payer.key.as_ref()], bump)]
pub transaction: ...
1
vote
1
answer
58
views
How can a program enforce that one of two authorities to sign a transaction?
I know I can pass in a Context to my instruction and the struct looks something like:
#[derive(Accounts)]
pub struct ListOfAccounts<'info> {
#[account(mut)]
pub ONE: AccountInfo<'info&...
1
vote
1
answer
139
views
What seeds should I use in `invoke_signed()` for PDA derived via `create_with_seed()`
I have a PDA generated with:
const SEED: &str = "My Seed";
let pda = Pubkey::create_with_seed(program_id, SEED, &owner_id).unwrap();
Where program_id and owner_id are some fixed ...
6
votes
2
answers
1k
views
Why do PDAs need to be bumped so that they are not on the Ed25519 elliptic curve?
As a beginner, what is a good way to understand the purpose of Program Derived Addresses being bumped until they are off of the ed25519 elliptic curve?
What is the ed25519 elliptic curve?
How is it ...
9
votes
2
answers
249
views
How to use PDAs instead of Hash maps
I'm trying to build a crowdfunding dapp and I want to store/map the Pubkey to the amount donated. I also want to get the Top 10 donors. What would have been suitable for this kind of data is hashmap ...
5
votes
1
answer
561
views
How can I delete all PDA accounts for my program (anchor)?
I created several PDA accounts with custom data fields. However, I realized that I want to add a new variable inside; since I have already made the accounts and allocated space for them, I can't just ...
10
votes
4
answers
871
views
How to check if a PDA account has/hasn't been initialized?
I am using anchor and I need to check that two different PDAs have not been initialized. Later on in a different function call I need to check if a PDA has been initialized before closing the account.
...
4
votes
1
answer
127
views
How to verify if a public key is a PDA without the seeds?
If we have a public key, how can we determine if it is a PDA? Especially in the case where we don't have any information about the source code programs related to the public key. Is it possible to ...
2
votes
1
answer
210
views
How to add metadata to a token whose mint is a PDA?
My token is program-controlled, i.e. my mint address (and authority) is a PDA.
For that reason, I have to create code within my Solana Program to add metadata to my token.
While I can easily mint, it ...
1
vote
1
answer
289
views
"error: ... An account required by the instruction is missing" when issuing create_metadata_accounts_v3 via CPI
I have a token mint address that is a PDA.
Because of that, I cannot just add metadata the usual way. No wallet can sign for the PDA, so my Program needs to add the metadata.
So I created a new ...
5
votes
3
answers
242
views
findProgramAddress() is not returning the original address created even though I'm using the same seeds
async function debug(){
var basePubKey = new solanaWeb3.PublicKey("6gHtRckgbXmRtXkkCx5vhAh9jBUC3AuXTgmhi9gMHMVM");
var programID = new solanaWeb3.PublicKey("...
4
votes
2
answers
370
views
Error : Signature verification failed when using PDA ,,when transfering sol from a PDA to another address
I'm trying to write a code that transfers SOL from a vault(A PDA) to another address and my code looks like this
pub fn withdraw(ctx: Context<Withdraw>,amount:u64) -> Result<()> {
...
1
vote
2
answers
1k
views
How to create a metadata account for a token whose mint authority is a PDA?
My token's mint authority is my Program.
I need to add metadata so that the token appears nicely in my users' wallets.
So in order to add the metadata, I need to create a new instruction into my ...
2
votes
2
answers
1k
views
"Error processing Instruction 0: invalid program argument" while signing transfer transaction with PDA
Can someone point out what I'm doing wrong? I'm trying to transfer SOL from a PDA to the to_account but for some reason when I call it, fails with the following error message: Error processing ...
1
vote
2
answers
1k
views
Error Code: DeclaredProgramIdMismatch
I am trying to run some tests in my Solana Anchor project but I get an error saying that the declared program id does not match the actual program id.
Error: AnchorError occurred. Error Code: ...
7
votes
4
answers
1k
views
In a program, what is the difference between invoke and invoke_signed and when to use them?
Can someone explain what the difference is between the two and when to use each?
when to use invoke vs invoke_signed inside a program (smart contract)?
30
votes
6
answers
2k
views
What is a Program Derived Address (PDA) exactly?
Is this an account or is it an address? Why do I need it? What problem or use case does it solve? Why can't I just use a regular account instead?