Coder Social home page Coder Social logo

Comments (9)

acheroncrypto avatar acheroncrypto commented on May 23, 2024

From seed should be able to calculate the bump automatically, is there any other usecase I'm missing?

from solana-playground.

murtazaali1999 avatar murtazaali1999 commented on May 23, 2024

Umm...so how many instructions I pass in the instructions above the account, the single bump would handle it, without a target ?

from solana-playground.

acheroncrypto avatar acheroncrypto commented on May 23, 2024

You can pass #[account(seed = ..., bump)] without specifying the bump value. You can get the address From seed when testing in the UI and you won't need the bump. Is there an example where you need the bump?

from solana-playground.

murtazaali1999 avatar murtazaali1999 commented on May 23, 2024

Im trying to do this, I want to make PDA accounts with different u8 bump value to create accounts belonging to the same user or wallet

from solana-playground.

acheroncrypto avatar acheroncrypto commented on May 23, 2024

I want to make PDA accounts with different u8 bump value to create accounts belonging to the same user.

You should never do this. PDA calculation is extremely expensive, and essentially limited to maximum 2^8 accounts(realistically much less than that) and you need to try to get it with brute force and what's worse is there is no guarantee you will hit a PDA, that's why bumps exist in the first place.

Instead use something like:

#[derive(Accounts)]
#[instruction(id: u8)]
pub struct MyAccount<'info> {
    #[account(seed = [authority.key().as_ref(), &[id]], bump)]
    pub user: Account<'info, User>.
    pub authority: Signer<'info>
}

Also you can ask about this in Solana Stackexchange.

from solana-playground.

murtazaali1999 avatar murtazaali1999 commented on May 23, 2024

When I do this and pass this in the creation of the account, e.g: string , pubkey and number , It says:

The program could not deserialize the given instruction

from solana-playground.

acheroncrypto avatar acheroncrypto commented on May 23, 2024

Can you share the how you init the account? #[account(init, ...)] part.

from solana-playground.

murtazaali1999 avatar murtazaali1999 commented on May 23, 2024

#[instruction(user_bump: u8)]

#[account(init, payer = user, space = 10000,seeds=[b"pool".as_ref(), user.key().as_ref(),&[user_bump]],bump)]

from solana-playground.

acheroncrypto avatar acheroncrypto commented on May 23, 2024
use anchor_lang::prelude::*;

declare_id!("11111111111111111111111111111111");

#[program]
mod my_program {
    use super::*;
    pub fn init(ctx: Context<MyContext>, id: u8) -> Result<()> {
        msg!("Initialized user {}'s account #{}", ctx.accounts.user.key(), id);
        Ok(())
    }
}

#[derive(Accounts)]
#[instruction(id: u8)]
pub struct MyContext<'info> {
    #[account(
        init,
        payer = user,
        space = 8,
        seeds = [
            b"pool",
            user.key().as_ref(),
            &[id]
        ]
        ,bump)
     ]
    pub my_account: Account<'info, MyAccount>,
    #[account(mut)]
    pub user: Signer<'info>,
    pub system_program: Program<'info, System>,
}

#[account]
#[derive(Default)]
pub struct MyAccount {}

Make sure you are using the correct seeds.
Seed 1: pool (string)
Seed 2: the address that signs the transaction (pubkey)
Seed 3: id (number)

And testing:
image

from solana-playground.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.