solana-py icon indicating copy to clipboard operation
solana-py copied to clipboard

deserialize random behavior

Open uy5cu71 opened this issue 1 year ago • 9 comments

input_mint = 'So11111111111111111111111111111111111111112' output_mint = 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v' amount = 5000000000 slippage_bps = 50

api_url = f'https://quote-api.jup.ag/v6/quote?inputMint={input_mint}&outputMint={output_mint}&amount={amount}&slippageBps={slippage_bps}' quote_response = requests.get(api_url).json()

swap_transaction_response = requests.post('https://quote-api.jup.ag/v6/swap', json= { 'quoteResponse': quote_response, 'userPublicKey': str(public_key), 'wrapAndUnwrapSol': True, })

swap_transaction = swap_transaction_response.json()['swapTransaction'] tx = Transaction.deserialize(base64.b64decode(swap_transaction)) print(tx)

Randomly gives errors:

  1. line 320, in deserialize return cls.from_solders(SoldersTx.from_bytes(raw_transaction)) ValueError: invalid value: continue signal on byte-three, expected a terminal signal on or before byte-three

  2. line 320, in deserialize return cls.from_solders(SoldersTx.from_bytes(raw_transaction)) ValueError: invalid value: alias encoding, expected strict form encoding

  3. line 320, in deserialize return cls.from_solders(SoldersTx.from_bytes(raw_transaction)) ValueError: io error: unexpected end of file

OR

Can randomly pass: <solana.transaction.Transaction object at 0x0000017316C11130>

(As it should)

uy5cu71 avatar Nov 08 '23 16:11 uy5cu71

can you check if the randomness is in solders or the API response?

kevinheavey avatar Nov 25 '23 11:11 kevinheavey

can you check if the randomness is in solders or the API response?

The exact same error occurs to me as well, I believe the randomness of the errors are occuring in solders.

enzomarioaiello avatar Dec 22 '23 12:12 enzomarioaiello

same here

shifenhutu avatar Dec 23 '23 05:12 shifenhutu

Doesn't the Jup API give a VersionedTransaction instead of a legacy Transaction?

kevinheavey avatar Jan 01 '24 13:01 kevinheavey

Anyone found a way to fix this?Im facing the same issue

Genza999 avatar Feb 03 '24 15:02 Genza999

@Genza999 have you tried using VersionedTransaction instead of Transaction?

kevinheavey avatar Feb 03 '24 15:02 kevinheavey

Thanks, worked with the VersionedTransaction

Genza999 avatar Feb 08 '24 08:02 Genza999

@Genza999 have you tried using VersionedTransaction instead of Transaction?

Even if u are using VersionedTransaction, it can randomly throw "ValueError: invalid value: alias encoding, expected strict form encoding". You can try for yourself. Make several requests. Some of them will throw error

uy5cu71 avatar Feb 14 '24 16:02 uy5cu71

@uy5cu71 I've been using the following line to to fix the issue entirely. Since I made this adjustment this issue hasn't presented itself again.

rawTransaction = VersionedTransaction.from_bytes(base64.b64decode(swap_transaction))

enzomarioaiello avatar Feb 15 '24 07:02 enzomarioaiello