Space was the issue for me as well. In my case, I solved it with the equivalent of the following
#[derive(Accounts)]
#[instruction(new_uri: String)]
pub struct ModifyLedger<'info> {
#[account(
mut,
// 8 for discriminator, 4 for the string length, and uri.len() for the content of string
space = 8 + 4 + new_uri.len()
)]
pub ledger_account: Account<'info, Ledger>,
#[account(mut)]
pub wallet: Signer<'info>,
}
Essentially, I am computing the space required to store the ledger account struct, from the data passed in to the instruction. Remember to add 8 bytes at the start for anchor's discriminator.
#[account]
pub struct Ledger {
pub uri: String,
}
Using the exact space required helps you be more efficient in terms of SOL usage.
References:
- Solana Quick Start Tutorial - Program Derived Address - Implement Create Instruction (open the Explanation accordion)