Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

invalid public key input:', <solana.account.Account object at 0x7f34954d5f40> #89

Open
hemantsirsat opened this issue Oct 9, 2021 · 18 comments

Comments

@hemantsirsat
Copy link

I was implementing a buy function using pyserum and solana using the following code.

        payer=sender_keypair.public_key,
        owner=Account(sender_keypair),
        side=Side.BUY,
        order_type=OrderType.LIMIT,
        limit_price=0.5,
        max_quantity=abs(1),
        opts=TxOpts(skip_preflight=True)
    )

The following error occurs:

ValueError: ('invalid public key input:', '<solana.account.Account object at 0x7fac2a7c2cd0>')
@leofisG
Copy link
Contributor

leofisG commented Oct 9, 2021 via email

@hemantsirsat
Copy link
Author

hemantsirsat commented Oct 10, 2021

Sender_keypair(<class 'solana.keypair.Keypair'>) is the keypair of the owner's wallet.

@leofisG
Copy link
Contributor

leofisG commented Oct 10, 2021 via email

@hemantsirsat
Copy link
Author

hemantsirsat commented Oct 10, 2021

Here's the code. Ignore the unnecessary imports.

from solana.keypair import Keypair
from solana.publickey import PublicKey
from solana.system_program import transfer, TransferParams, TransactionInstruction, AccountMeta
from solana.account import Account
from solana.transaction import Transaction
from solana.rpc.api import Client
from solana.rpc.types import TxOpts
from spl.token.client import Token
from pyserum.connection import conn
from pyserum.enums import OrderType, Side
from pyserum.market import Market
from pyserum.connection import get_live_markets, get_token_mints
import solana.system_program as sp
import time
import base58


PRIVATEKEYPHANTOM = AbCd123.....

def get_keypair(private_key):
    byte_array = base58.b58decode(private_key)
    return byte_array

def perform_transaction(owner_keypair,client,market):
    order = market.place_order(
        payer=owner_keypair.public_key,
        owner=Account(owner_keypair),
        side=Side.BUY,
        order_type=OrderType.LIMIT,
        limit_price=0.5,
        max_quantity=abs(1),
        opts=TxOpts(skip_preflight=True)
    )
    print(order)

if __name__ == '__main__':
    start = time.time()
    client = Client('https://api.mainnet-beta.solana.com')
    cc = conn('https://solana-api.projectserum.com')

    owner_key_pair = get_keypair(PRIVATEKEYPHANTOM)
    owner_keys = Keypair(owner_key_pair[:32])

    market = Market.load(cc,market_address,PublicKey(program_id))

    perform_transaction(owner_keys, client, market)
    end = time.time()
    print("Seconds required =",end-start)

@vikulikov
Copy link

vikulikov commented Oct 11, 2021

I've got the same error with this part of the traceback:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/solana/publickey.py", line 31, in __init__
    self._key = base58.b58decode(value)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/base58/__init__.py", line 124, in b58decode
    acc = b58decode_int(v, alphabet=alphabet, autofix=autofix)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/base58/__init__.py", line 104, in b58decode_int
    raise ValueError(
ValueError: Invalid character <<>

The above exception was the direct cause of the following exception:

The full traceback is:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/solana/publickey.py", line 31, in __init__
    self._key = base58.b58decode(value)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/base58/__init__.py", line 124, in b58decode
    acc = b58decode_int(v, alphabet=alphabet, autofix=autofix)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/base58/__init__.py", line 104, in b58decode_int
    raise ValueError(
ValueError: Invalid character <<>

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/vikulikov/projects/solana_test/main.py", line 28, in <module>
    market.place_order(
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pyserum/market/market.py", line 129, in place_order
    return self._conn.send_transaction(transaction, *signers, opts=opts)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/solana/rpc/api.py", line 1059, in send_transaction
    txn.sign(*signers)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/solana/transaction.py", line 262, in sign
    self.sign_partial(*signers)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/solana/transaction.py", line 241, in sign_partial
    sign_data = self.serialize_message()
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/solana/transaction.py", line 222, in serialize_message
    return self.compile_message().serialize()
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/solana/transaction.py", line 207, in compile_message
    return Message(
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/solana/message.py", line 59, in __init__
    self.account_keys = [PublicKey(key) for key in args.account_keys]
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/solana/message.py", line 59, in <listcomp>
    self.account_keys = [PublicKey(key) for key in args.account_keys]
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/solana/publickey.py", line 33, in __init__
    raise ValueError("invalid public key input:", value) from err
ValueError: ('invalid public key input:', '<solana.account.Account object at 0x7fdacd13b7c0>')

@leofisG
Copy link
Contributor

leofisG commented Oct 11, 2021 via email

@kwaibun
Copy link

kwaibun commented Oct 11, 2021

something like this change could work, that's all because in
site-packages/solana/rpc/api.py", line 1059, in send_transaction
    txn.sign(*signers)
signers should be Keypair, not Account, this is a recent change
michaelhly/solana-py@4fcf707

--- a/pyserum/market/market.py
+++ b/pyserum/market/market.py
@@ -5,6 +5,7 @@ from typing import List
 
 from solana.account import Account
 from solana.publickey import PublicKey
+from solana.keypair import Keypair
 from solana.rpc.api import Client
 from solana.rpc.types import RPCResponse, TxOpts
 from solana.transaction import Transaction
@@ -125,7 +126,14 @@ class Market(MarketCore):
             open_order_accounts=open_order_accounts,
             place_order_open_order_account=place_order_open_order_account,
         )
-        return self._conn.send_transaction(transaction, *signers, opts=opts)
+        new_signers: List[Keypair] = []
+        for item in signers:
+            if isinstance(item, Account):
+                new_signers.append(Keypair(item.secret_key()))
+            else:
+                new_signers.append(item)
+
+        return self._conn.send_transaction(transaction, *new_signers, opts=opts)
 
     def cancel_order_by_client_id(
         self, owner: Account, open_orders_account: PublicKey, client_id: int, opts: TxOpts = TxOpts()

@Imaclean74
Copy link
Contributor

probably better to patch market and the other libs to use Keypair instead of Account ?

@hemantsirsat
Copy link
Author

I tried changing public_key() to public_key of pyserum/market.py and pyserum/core.py. Now there's a new error.
pyserum/market/core.py line 149, in _prepare_order_transaction raise ValueError("Invalid payer account. Cannot use unwrapped SOL.") ValueError: Invalid payer account. Cannot use unwrapped SOL.

@Imaclean74
Copy link
Contributor

First attempt at replacing Account with Keypair in the PR referenced above

@vikulikov
Copy link

vikulikov commented Oct 17, 2021

in _prepare_order_transaction raise ValueError("Invalid payer account. Cannot use unwrapped SOL.") ValueError: Invalid payer account. Cannot use unwrapped SOL. `

I believe it happens due to payer == SOL unwrapped public address. Does anybody know how to handle it? Or it is a bug?
How can I trade instruments with SOL (such as selling SOL/USDC or buying SRM/SOL) in this case?

@hemantsirsat
Copy link
Author

hemantsirsat commented Oct 25, 2021

in _prepare_order_transaction raise ValueError("Invalid payer account. Cannot use unwrapped SOL.") ValueError: Invalid payer account. Cannot use unwrapped SOL. `

I believe it happens due to payer == SOL unwrapped public address. Does anybody know how to handle it? Or it is a bug? How can I trade instruments with SOL (such as selling SOL/USDC or buying SRM/SOL) in this case?

Did you find any solution?

@Imaclean74
Copy link
Contributor

is this still failing with the latest release ?

@hemantsirsat
Copy link
Author

invalid public key input is solved. Although there's a new error.
ValueError: Invalid payer account. Cannot use unwrapped SOL.

@EnderElement
Copy link

I'm also getting this same issue still. #95 looks to be a fix for this so I'm waiting for that.

@EnderElement
Copy link

EnderElement commented Nov 16, 2021

I'm also getting this same issue still. #95 looks to be a fix for this so I'm waiting for that.

Turns out my issue can be fixed by simply settling funds before placing an order. Btw the payer account is your token account address, not your public key if you aren't dealing with SOL or USDC I think.

@hemantsirsat
Copy link
Author

I'm also getting this same issue still. #95 looks to be a fix for this so I'm waiting for that.

Turns out my issue can be fixed by simply settling funds before placing an order. Btw the payer account is your token account address, not your public key if you aren't dealing with SOL or USDC I think.

And how did you achieve that? Can you share the snippet?

@EnderElement
Copy link

EnderElement commented Nov 17, 2021

I'm also getting this same issue still. #95 looks to be a fix for this so I'm waiting for that.

Turns out my issue can be fixed by simply settling funds before placing an order. Btw the payer account is your token account address, not your public key if you aren't dealing with SOL or USDC I think.

And how did you achieve that? Can you share the snippet?

I'll show this with an example using the ATLAS/USDC pair
Screen Shot 2021-11-17 at 1 24 24 pm

Say I want to buy the asset using USDC, I take my USDC address as the payer. If I wanted to sell the asset then the payer would be the address of the asset. This likely won't work if the payer address is your SOL wallet which will give the ValueError you got. If you want to buy something using SOL then idk how you would go about doing that. I just get my token address from raydium, you might want to instead do that by code.

atlas_market_address = PublicKey("Di66GTLsV64JgCCYGVcY21RZ173BHkjJVgPyezNN7P1K") # ATLAS/USDC
usdc_wallet = PublicKey("ANDAfNfg...13UG6PWd") # USDC
atlas_market = Market.load(cc, atlas_market_address)
atlas_market.place_order(payer=usdc_wallet,owner=Keypair(privateKey),order_type=OrderType.LIMIT,side=Side.BUY,limit_price=0.1,max_quantity=1,opts=TxOpts(skip_confirmation=False))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants