getting a "this program may not be used for excuting instructions" error when making a simple spl transfer

248 views Asked by At

i'm trying to send an spl-token transaction but it's not working, it's a transacion on the devnet with a token that i newly created, my code is

    from spl.token.instructions import transfer, TransferParams
    from spl.token.client import Client 
    from solana.publickey import PublicKey
    from solana.transaction import Transaction
    from solana.keypair import Keypair

    address = "address sending from"
    my_token = "3hALJzSz2bx8gxgrHg7EQQtdiHxG7d7LNswxVMXrUApw" #token addredd on devnet
    private_key= "64 bit key"



    def send_payouts_spl(dest,amount):
        source = address
        transfer_params= TransferParams(
        amount=amount,
        dest=PublicKey(dest),
        owner=PublicKey(source),
        program_id=PublicKey(my_token),
        source=PublicKey(source)
        )
        txn = Transaction()
        txn.add(transfer(transfer_params))
        solana_client = Client("https://api.devnet.solana.com")
        owner = Keypair.from_secret_key(private_key)
        tx_id  = solana_client.send_transaction(txn, owner)
        return tx_id

and also the error that i'm getting

solana.rpc.core.RPCException: {'code': -32002, 'message': 'Transaction simulation failed: This program may not be used for executing instructions', 'data': {'accounts': None, 'err': 'InvalidProgramForExecution', 'logs': [], 'unitsConsumed': 0}}

also if it helps, my devnet token address and my devnet address are

3hALJzSz2bx8gxgrHg7EQQtdiHxG7d7LNswxVMXrUApw, EckcvMCmpkKwF4hDhWxq8cm4qy8JBkb2vBVQDu4WvxmM respectively

1

There are 1 answers

2
Jon C On BEST ANSWER

In Solana, there's typically just one token program that is shared for all token types (mints).

When you provide the program_id, you shouldn't provide the address for your mint, but rather the id for the SPL Token Program, which is TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA. Also, the owner should be the key that owns the token account.

So instead, try:

    owner = Keypair.from_secret_key(private_key)
    transfer_params= TransferParams(
        amount=amount,
        dest=PublicKey(dest),
        owner=PublicKey(owner.public_key),
        program_id=PublicKey('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'),
        source=PublicKey(source)
    )