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

cannot convert 'Transaction' object to bytes #1

Open
creosmart opened this issue Oct 21, 2024 · 11 comments
Open

cannot convert 'Transaction' object to bytes #1

creosmart opened this issue Oct 21, 2024 · 11 comments
Assignees

Comments

@creosmart
Copy link

Hello, seems there's an error when running trade.py:

"Attempt 1 to create associated token account failed: cannot convert 'Transaction' object to bytes"

Thanks

@akegaviar
Copy link
Contributor

That's most likely due to the mismatch between the data you received from blockSubscribe and the chain data. What this means ultimately is you need to increase the cooldown period to allow the chain data to catch up from the moment you receive it over blockSubscribe and have the actual chain data. See the relevant issue anza-xyz/agave#3074

@AidHamza
Copy link

As @akegaviar mentioned, sleep is a workaround, for my case, I kind of decoupled the logic, and separated the buy event, instead of waiting, you can rerun with retries till the expected result is satisfied. It had a great impact on the bot results

@creosmart
Copy link
Author

@akegaviar I increased the cooldown to 120 await asyncio.sleep(120) but still getting the same error, any suggestions? @AidHamza I was hoping to be one of the first buyers of the token, can this be achieved with the logic you mentioned?

@akegaviar
Copy link
Contributor

@creosmart I suggest you add logging to see at what the stage the issue is.

@nickatnight
Copy link

nickatnight commented Oct 24, 2024

@creosmart I encountered this same issue. I fixed it by using solana version 0.34.0 instead of 0.35.0

@akegaviar
Copy link
Contributor

Thanks for the help @nickatnight . I should have included requirements.txt right from the start but missed that and only added it yesterday.

@creosmart
Copy link
Author

Thanks a lot @nickatnight, as a beginner I couldn't figure it out and it was doing my head in 😁

@Avinaash7
Copy link

@creosmart I encountered this same issue. I fixed it by using solana version 0.34.0 instead of 0.35.0

Facing the same issue even in version 0.34.0

@teletonn
Copy link

There should be solana==0.34.3 in requirements.txt, or it will install 35 version thats not working.

@smypmsa
Copy link

smypmsa commented Oct 26, 2024

The problem is in Transaction object imported from solana. It works fine if you replace it with the one from solders.transaction.

For example, the transaction for ATA creation will look like this:

                    msg = Message([create_ata_ix], payer.pubkey())
                    tx_ata = await client.send_transaction(
                        Transaction([payer], msg, (await client.get_latest_blockhash()).value.blockhash),
                        opts=TxOpts(skip_preflight=True, preflight_commitment=Confirmed)
                        )
                    
                    await client.confirm_transaction(tx_ata.value, commitment="confirmed")

The transaction for buying a token (with the set_compute_unit_price instruction to speed up its landing):

                msg = Message([set_compute_unit_price(1_000), buy_ix], payer.pubkey())
                tx_buy = await client.send_transaction(
                    Transaction([payer], msg, (await client.get_latest_blockhash()).value.blockhash),
                    opts=TxOpts(skip_preflight=True, preflight_commitment=Confirmed)
                    )

@AidHamza
Copy link

@akegaviar I increased the cooldown to 120 await asyncio.sleep(120) but still getting the same error, any suggestions? @AidHamza I was hoping to be one of the first buyers of the token, can this be achieved with the logic you mentioned?

No guarantee that you can be the first one buying, it depends on so many factor, including the used node, latency, tasking the operations needed will just make things simpler, trackable, and gives you a better observability. Also easy to scale your operations if you wish to try multiple strategies and study the result

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

7 participants