Custom Token transfer using our Smart contract

I am transferring custom token using our Smart contract by invoking Token program and pass transfer parameters in it.

there is 50M token balance in source and 20M token balance in destination Token account.

Now i m facing problem that , if send 0 Amount token transaction will be successfully complete but if i transfer 1 token it show Insufficient Balance.

Error:-
‘Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]’,
‘Program log: Instruction: Transfer’,
‘Program log: Error: insufficient funds’,
‘Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 2263 of 198155 compute units’,
‘Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA failed: custom program error: 0x1’,
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

 Token_TokenInstruction token_transfer;

 token_transfer.transfer.amount= AMOUNT;
 token_transfer.tag=Token_TokenInstruction_Transfer;
 AccountMeta transfer_metas[]={
                                /*Pubkey                 //Writable     //Singer*/
                                {&from_Wallet.pubkey(),     true,         false},
                                {&to_Wallet.pubkey(),       true,         false},
                                {&Owner_Wallet.pubkey(),    true,         true},
                                {&Owner_Wallet.pubkey(),    true,         true}                                    
                            };
                            /*
                              token program key
                              from key
                              to_Wallet
                              Owner_wallet
                              Owner_wallet
                            */
const Instruction token_transfer_inst(Fame_Token.owner(),transfer_metas,token_transfer);

if (invoke(token_transfer_inst, accounts) != SUCCESS) {
    log("ERROR: Could not allocate space.");
    sol_panic();
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

i need help in this issue.

I’m not sure exactly what your problem is. It looks like you’re using C or C++, which I’m not super familiar with the Solana interface for, too.

You might find more help on Discord.

My only thought is that maybe you are mixing up the from wallet and trying to transfer from an account that doesn’t actually have the amount of tokens, but I’m not sure.

solution found
need to change transaction class to dill amount data.
refer below class

class attribute((packed)) Token_TokenInstruction_Transfer
{
uint8_t tag;
Lamports amount;
public:
Token_TokenInstruction_Transfer(Lamports& amount) :
tag(3),
amount(amount){
}
};
static_assert(sizeof(Token_TokenInstruction_Transfer) == 1 + 8);

Thanks &Regards

1 Like