pub struct CreateCtx<'info> {
#[account(init, payer = admin,
seeds=[CommunityAccount::SEED, random.key.as_ref()], bump,
space = 8 + CommunityAccount::INIT_SPACE)]
pub community_account: Account<'info, CommunityAccount>,
#[account(mut)]
pub admin: Signer<'info>,
/// CHECK: this account is created randomly, no need to do anything
pub random: AccountInfo<'info>,
pub system_program: Program<'info, System>,
}
This design assume that the admin will pay rent for the CommunityAccount but it is not always the case. If I want to design a gas-less experience in Solana then this design block me from doing so.
Solution
Seperate the rent payer and data owner. The new data structure should be:
pub struct CreateCtx<'info> {
#[account(init, payer = rent_payer,
seeds=[CommunityAccount::SEED, random.key.as_ref()], bump,
space = 8 + CommunityAccount::INIT_SPACE)]
pub community_account: Account<'info, CommunityAccount>,
#[account(mut)]
pub admin: Signer<'info>,
#[account(mut)]
pub rent_payer: Signer<'info>,
/// CHECK: this account is created randomly, no need to do anything
pub random: AccountInfo<'info>,
pub system_program: Program<'info, System>,
}
Should apply this to all account creation and modification:
Problem
Take this Struct for example:
This design assume that the
admin
will pay rent for theCommunityAccount
but it is not always the case. If I want to design a gas-less experience in Solana then this design block me from doing so.Solution
Seperate the rent payer and data owner. The new data structure should be:
Should apply this to all account creation and modification: