michaelhly / solana-py

Solana Python SDK
https://michaelhly.github.io/solana-py
MIT License
1.05k stars 271 forks source link

Transaction feePayer required #111

Open spongehenk opened 3 years ago

spongehenk commented 3 years ago

I don´t know what I´m doing wrong but I get the error: Transaction feePayer required".

the code:

usdc_mint = PublicKey(base58.b58decode(SPLtokenProgramPubkey)) #mint account solana_client = Client("https://api.devnet.solana.com")

source = spl.token.client.Token(conn=solana_client, pubkey=usdc_mint, program_id=spl.token.constants.TOKEN_PROGRAM_ID, payer=account1) #account1 = Account(keypair1[:32]) usdc_token_client = spl.token.client.Token(pubkey=usdc_mint,conn=solana_client, program_id=spl.token.constants.TOKEN_PROGRAM_ID, payer=account1) print(usdc_token_client)

usdc_token_client.transfer(source=source.create_account(owner=account1.public_key()), # PK of USDC token account you're transfering FROM dest=publickey3, # PK of USDC token account you're transfering TO owner=usdc_mint, # Account that owns your source USDC token account amount=500000, opts=TxOpts(skip_confirmation=False), )

vcyleung commented 3 years ago

owner=usdc_mint, # Account that owns your source USDC token account

the owner is your sol address. Your sol address owns the token you are transferring and will pay the sol tx fees not the usdc mint implied in your code.

...
from spl.token.constants import TOKEN_PROGRAM_ID
...

        keypair = self._keypair       
        payer = Account(keypair[:32])    #or publickey
        token_mint_key = PublicKey(token_mint) # Public key of the token mint
        conn = Client("https://api.mainnet-beta.solana.com/")
        token_client = Token(conn, token_mint_key, TOKEN_PROGRAM_ID, payer)
        try: 
            print (source,'begin sending', amount)
            resp = token_client.transfer(
                source=PublicKey(source), # PK of token account you're transfering FROM
                dest=PublicKey(destination), # PK of token account you're transfering TO
                owner=payer, # Account that owns your source token account
                amount=amount,
                opts=TxOpts(skip_confirmation=True),
            )
            return resp
        except Exception as e: 
            print('token transfer failed for:', source)
            print(e)
ghost commented 2 years ago

I have used your code and I have error:{'code': -32002, 'message': 'Transaction simulation failed: Error processing Instruction 0: invalid account data for instruction', 'data': {'accounts': None, 'err': {'InstructionError': [0, 'InvalidAccountData']}, 'logs': ['Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [1]', 'Program log: Instruction: Transfer', 'Program log: Error: InvalidAccountData', 'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 1302 of 200000 compute units', 'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA failed: invalid account data for instruction'], 'unitsConsumed': 0}}