1

Hi I'm having this problem, I'm trying to execute the BuySingleListing from Tensor but by passing the instruction data to my program. The tx works when I just sign it in the frontend, here's the Tx inspected

But when I try to make a CPI call it appears the following error:

> Program logged: "Instruction: BuyNft"
> Program logged: "Transfer to caller"
> Program logged: "Buy NFT"
> 7QXx5AuWW8BeQA5yzU8gRVvBE9E81ymEcLG4L4DSjzLm's writable privilege escalated
> Program consumed: 53695 of 551575 compute units
> Program returned error: "Cross-program invocation with unauthorized signer or writable account"

Here's the Tx inspected from my program I pass all the accounts the instruction needs in remaining_accounts.

#[derive(Debug, Clone)]
pub struct TensorSwap;
impl Id for TensorSwap {
    fn id() -> Pubkey {
        Pubkey::from_str("TSWAPaqyCSx2KABk68Shruf4rp7CxcNi8hAsbdwmHbN").unwrap()
    }
}

pub fn buy_nft(ctx: Context<BuyNft>, data: Vec<u8>, amount: u64) -> Result<()> {

    let accs = ctx.remaining_accounts.iter()
        .map(|acc| AccountMeta::new(*acc.key, acc.is_signer)).collect();

    // I buy them
    msg!("Buy NFT");
    invoke(
        &Instruction::new_with_bytes(TensorSwap::id(), data.as_slice(), accs),
        ctx.remaining_accounts
    )?;

    ...other instructions...

    Ok(())
}

1 Answer 1

1

According to the error, 7QXx5AuWW8BeQA5yzU8gRVvBE9E81ymEcLG4L4DSjzLm must be declared as writable, but it's readonly in your transaction with the CPI. You'll notice that in the link you provided.

So be sure to declare that account as writable in your program!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.