1

I am attempting to create a function that receives lamports, and if it does, to execute some code. Both the sending and receiving accounts are owned by the system program. The receiving wallet is NOT the PDA address.

I am getting the following error:

Error: AnchorError occurred. Error Code: InstructionFallbackNotFound. Error Number: 101. Error Message: Fallback functions are not supported.

Here is the rust code:


    pub fn receive_solana(ctx: Context<SendSol>) -> Result<()> {                                                                                                                                                                                                                          
                                                                                                                                                                                                                                                                                          
    |   let cpi_context = CpiContext::new(                                                                                                                                                                                                                                                
    |   |   ctx.accounts.system_program.to_account_info(),                                                                                                                                                                                                                                
    |   |   system_program::Transfer {                                                                                                                                                                                                                                                    
    |   |   |   from: ctx.accounts.sender.to_account_info(),                                                                                                                                                                                                                              
    |   |   |   to: ctx.accounts.receiver.to_account_info(),                                                                                                                                                                                                                              
    |   |   });                                                                                                                                                                                                                                                                           
                                                                                                                                                                                                                                                                                          
    |   system_program::transfer(cpi_context, 10000000)?;                                                                                                                                                                                                                                 
    |                                                                                                                                                                                                                                                                                     
    |   Ok(())                                                                                                                                                                                                                                                                            
                                                                                                                                                                                                                                                                                          
    }     

#[derive(Accounts)]                                                                                                                                                                                                                                                                       
pub struct SendSol<'info> {                                                                                                                                                                                                                                                               
    sender: Signer<'info>,                                                                                                                                                                                                                                                                
    /// CHECK:                                                                                                                                                                                                                                                                            
    receiver: AccountInfo<'info>,                                                                                                                                                                                                                                                         
    system_program: Program<'info, System>,                                                                                                                                                                                                                                               
}   

And here is the TS:

it("Receives Sol!", async () => {                                                                                                                                                                                                                                                         
                                                                                                                                                                                                                                                                                          
    const receiver = new anchor.web3.PublicKey('REDACTED ADDRESS STRING');                                                                                                                                                                                                                      

    await gameLogicProgram.methods                                                                                                                                                                                                                                                        
        .receiveSolana() //new anchor.BN(100000000))                                                                                                                                                                                                                                      
        .accounts({                                                                                                                                                                                                                                                                       
                                                                                                                                                                                                                                                                                          
                sender : provider.wallet.publicKey,                                                                                                                                                                                                                                       
                receiver : receiver,                                                                                                                                                                                                                                                           
                systemProgram: anchor.web3.SystemProgram.programId,                                                                                                                                                                                                                       
        })                                                                                                                                                                                                                                                                                
        .signers([provider.wallet.payer])                                                                                                                                                                                                                                                 
        .rpc();                                                                                                                                                                                                                                                                           
                                                                                                                                                                                                                                                                                          
                                                                                                                                                                                                                                                                                          
  });   

Has anyone else encountered this, or understand what is the source of the error?

3 Answers 3

4

More often than not, the endpoint that you're trying to call is not present in the program.

Either you:

  • A) Forgot to upgrade/redeploy the program
  • B) Sending in the wrong arguments
  • C) Calling a wrong function
1
  • 1
    It was the IDL not being updated. I deleted the target folder and rebuilt and it worked. Commented Feb 14, 2023 at 18:25
1

Check if IDL is the latest one, try erasing the target dir and run anchor build (don't forget to replace the program ID in the lib file of your programs).

See also the question AnchorError occurred. Error Code: InstructionFallbackNotFound. Error Number: 101. Error Message: Fallback functions are not supported on Stack Overflow.

0

Here is an example that you can reference for making SOL transfers via a CPI within an Anchor program: https://github.com/solana-developers/program-examples/blob/main/basics/transfer-sol/anchor/programs/transfer-sol/src/lib.rs#L12

Here are the tests: https://github.com/solana-developers/program-examples/blob/main/basics/transfer-sol/anchor/tests/test.ts

Here is the same example on Solpg: https://beta.solpg.io/63eb100767edfe0f001069bf

use anchor_lang::prelude::*;
use anchor_lang::system_program;
// This is your program's public key and it will update
// automatically when you build the project.
declare_id!("FaTJjjEhjYUdsKnPLKDn8uon8DxPZKax2EsLbn9HJYCS");

    #[program]
    mod hello_anchor {
        use super::*;
        pub fn transfer_sol_with_cpi(ctx: Context<TransferSolWithCpi>, amount: u64) -> Result<()> {
            system_program::transfer(
                CpiContext::new(
                    ctx.accounts.system_program.to_account_info(),
                    system_program::Transfer {
                        from: ctx.accounts.payer.to_account_info(),
                        to: ctx.accounts.recipient.to_account_info(),
                    },
                ),
                amount,
            )?;
    
            Ok(())
        }
    }
    
    #[derive(Accounts)]
    pub struct TransferSolWithCpi<'info> {
        #[account(mut)]
        recipient: SystemAccount<'info>,
        #[account(mut)]
        payer: Signer<'info>,
        system_program: Program<'info, System>,
    }

You can test using the Solpg UI or copy the test below to use with the Solpg test file:

describe("Test", () => {
  const test1Recipient = anchor.web3.Keypair.generate();
  const transferAmount = 0.1 * anchor.web3.LAMPORTS_PER_SOL;

  it("Transfer between accounts using the system program", async () => {
    await getBalances(
      pg.wallet.publicKey,
      test1Recipient.publicKey,
      "Beginning"
    );

    const txSig = await pg.program.methods
      .transferSolWithCpi(new anchor.BN(transferAmount))
      .accounts({
        payer: pg.wallet.publicKey,
        recipient: test1Recipient.publicKey,
        systemProgram: anchor.web3.SystemProgram.programId,
      })
      // .signers([pg.wallet])
      .rpc();

    await pg.connection.confirmTransaction(txSig);

    await getBalances(
      pg.wallet.publicKey,
      test1Recipient.publicKey,
      "Resulting"
    );
  });
});

async function getBalances(
  payerPubkey: anchor.web3.PublicKey,
  recipientPubkey: anchor.web3.PublicKey,
  timeframe: string
) {
  let payerBalance = await pg.connection.getBalance(payerPubkey);
  let recipientBalance = await pg.connection.getBalance(recipientPubkey);
  console.log(`${timeframe} balances:`);
  console.log(`   Payer: ${payerBalance}`);
  console.log(`   Recipient: ${recipientBalance}`);
}

You can try using the reference from the example-programs repo and Solpg to narrow down if the error is due to how you're setting up the instruction/test

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.