I have deployed a Rust contractstaking program on devnet. It has an instruction which invokesinitiates spl_token transfer user's from user's token account to the my contract'sits own token account.
When I call the contract instruction from frontend, the signature verification fails after approve popup fromAfter connecting wallet: {"code":-32003,"message":"failed to send transaction: Transaction simulation failed: Error processing Instruction 0: Cross-program invocation with unauthorized signer or writable account"}
Here is when frontend react app calls the Rust code:
let transfer_to_initializer_ix = spl_token::instruction::transfer(
token_program.key,
source_token_account.key,
destination_token_account.key,
initializer.key,
&[],
1,
)?;
msg!("Calling token program to transfer tokens");
invoke(
&transfer_to_initializer_ix,
&[
source_token_account.clone(),
destination_token_account.clone(),
initializer.clone(),
token_program.clone(),
]
)?;
This is howrust program for staking spl tokens, I send the call to instruction from my react appget signature verification error:
const instruction = new web3.TransactionInstruction({
keys: [
{
pubkey: publicKey,
isSigner: true,
isWritable: false,
},
{
pubkey: pda,
isSigner: false,
isWritable: true
},
{
isSigner: false,
isWritable: true,
pubkey: web3.SystemProgram.programId
},
{
is_signer: false,
is_writable: true,
pubkey: userAta,
},
{
is_signer: false,
is_writable: true,
pubkey: crowdpadATA,
},
{
is_signer: false,
is_writable: false,
pubkey: token.TOKEN_PROGRAM_ID,
},
],
data"code": buffer-32003,
programId"message": crowdpadStakingProgram
})
console.log('adding staking instruction')
transaction.add(instruction)
try {
const txid"failed =to awaitsend sendTransaction(transaction, connection);
alert(`Transaction submitted: https://explorer.solana.com/tx/${txid}?cluster=devnet`)
console.log(`TransactionTransaction submitted:simulation httpsfailed://explorer.solana.com/tx/${txid}?cluster=devnet`)
} catch (e) {
console.log(JSON.stringify(e))
alert(JSON.stringify(e))
Error processing Instruction 0: Cross-program invocation with }
unauthorized signer or writable account"}
You can try to run the client after setting solana config to devnet.