0

I'm trying to make an arbitrage program. Although I'm not able to write the transactions code using solana. I did refer from here(Sending solana transactions with python). I've made 2 accounts one with phantom and another with solflare. Hence, the account in the following code has public keys from phantom and new_account has public keys from solflare.

def perform_transaction():
    private_key = PRIVATEKEYPHANTOM
    keypair = get_keypair(private_key)

    cli = Client('https://solana-api.projectserum.com')
    account = Account(keypair[:32])
    new_account = Account(KEYPAIRSOLFLARE[:32])
    # print(new_account.public_key())
    # print(new_account.keypair())
    transaction = Transaction()
    transaction.add(sp.create_account(sp.CreateAccountParams(
            from_pubkey=account.public_key(),
            new_account_pubkey=new_account.public_key(),
            lamports=cli.get_minimum_balance_for_rent_exemption(88).get('result'),
            space=88,
            program_id=PublicKey(a_public_key),
        )))
    send_tx = cli.send_transaction(transaction, new_account)
    print(transaction)  

I get the following error

raise ValueError("invalid public key input:", value) from err
ValueError: ('invalid public key input:', '<solana.account.Account object at 0x7f8ca6429d00>')

I've never dealt with crypto transactions and this might be a very simple error. What's wrong here?

Noob
  • 117
  • 1
  • 11

1 Answers1

0

There's a couple of things you can try. First, you can use the Keypair type instead, since Account is deprecated, specifically using from_secret_key: https://github.com/michaelhly/solana-py/blob/a366253a3f043979bc6f61869ee8faad98292dc2/solana/keypair.py#L46

If that still doesn't work, the format of the private key is likely incorrect. Phantom generates private keys as base-64 strings, whereas these functions are expecting byte arrays. You can convert between the two using some of the answers at Import phantom wallet private key into solana CLI

Jon C
  • 7,019
  • 10
  • 17
  • This is better than before. Although, I still get the same error mentioned in the question. – Noob Oct 07 '21 at 11:59
  • Also, when I try to get the balance using keypair.public_key, I get 0, but when I try with my wallet address, I get the real balance. You had such situations? – Noob Oct 07 '21 at 13:57
  • 1
    This likely means that the format of the private key is incorrect -- you can check if `keypair.public_key` is equal to your wallet address as a sanity check. – Jon C Oct 13 '21 at 21:35