You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey! This is happening because Anchor let's you init an account even if the account is your wallet. So if you've chosen My address on any of the instructions that inits an account, your account will belong to the program and you will no longer be able to pay fees. Only System Program owned accounts can pay fees and if you look at any explorer, you will see that the wallet you are using is not owned by System Program.
This has been a big problem for a while and I'm planning to contribute for a fix so it doesn't let you init an account if the account's lamports is not 0.
In the meantime, you'd need to use a new wallet instead.
This account may not be used to pay transaction fees
use anchor_lang::prelude::*;
use anchor_lang::solana_program::entrypoint::ProgramResult;
declare_id!("CLvLTsZ8seZ6E19b2FSA4B1BrumUatXiSe2RmDvbtG41");
#[program]
pub mod crowdfunding {
use super::*;
pub fn create(ctx: Context, name: String, description: String) -> ProgramResult {
let campaign = &mut ctx.accounts.campaign;
campaign.name = name;
campaign.description = description;
campaign.amount_donated = 0;
campaign.current_balance = 0;
campaign.admin = *ctx.accounts.user.key;
Ok(())
}
pub fn withdraw(ctx: Context, amount: u64) -> ProgramResult {
let campaign = &mut ctx.accounts.campaign;
let user = &mut ctx.accounts.user;
if campaign.admin != *user.key {
return Err(ProgramError::IncorrectProgramId);
}
let rent_balance = Rent::get()?.minimum_balance(campaign.to_account_info().data_len());
}
#[derive(Accounts)]
pub struct Create<'info> {
#[account(
init,
payer=user,
space=9000,
seeds =[b"CAMPAIGN_DEMO".as_ref(), user.key().as_ref()],
bump
)]
pub campaign: Account<'info, Campaign>,
#[account(mut)]
pub user: Signer<'info>,
pub system_program: Program<'info, System>,
}
#[derive(Accounts)]
pub struct Withdraw<'info> {
#[account(mut)]
pub campaign: Account<'info, Campaign>,
#[account(mut)]
pub user: Signer<'info>,
}
#[derive(Accounts)]
pub struct Donate<'info> {
#[account(mut)]
pub campaign: Account<'info, Campaign>,
#[account(mut)]
pub user: Signer<'info>,
pub system_program: Program<'info, System>,
}
#[account]
pub struct Campaign {
pub admin: Pubkey,
pub name: String,
pub description: String,
pub amount_donated: u64,
pub current_balance: u64,
}
//3S9nB8j5Jod3tP74uWXKcyn1UeTSF2qykqsrTpEDNonf
Instruction index: 0
Reason: Cross-program invocation with unauthorized signer or writable account.
The text was updated successfully, but these errors were encountered: