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

Solana Transaction Error #419

Open
Anthonyslav1 opened this issue Apr 18, 2024 · 2 comments
Open

Solana Transaction Error #419

Anthonyslav1 opened this issue Apr 18, 2024 · 2 comments

Comments

@Anthonyslav1
Copy link

I have this error while trying to create a python code to do solana transfer

Traceback (most recent call last):
File "/workspaces/Web3-Wallet/transfer.py", line 118, in
Sol_Transfer(1, 'EccxYg7rViwYfn9EMoNu7sUaV82QGyFt6ewiQaH1GYjv', 9)
File "/workspaces/Web3-Wallet/transfer.py", line 114, in Sol_Transfer
return solana_client.send_transaction(txn)
File "/home/codespace/.python/current/lib/python3.10/site-packages/solana/rpc/api.py", line 1048, in send_transaction
txn.recent_blockhash = recent_blockhash
AttributeError: 'solders.transaction.Transaction' object has no attribute 'recent_blockhash'

' ' '
Python

def Sol_Transfer(user_number, recipient: str, amount: float):

    private_key = Gen_private_key.get_private_key(user_number)

    private_key_bytes = bytes.fromhex(private_key)


    # Ensure the private key bytes are 32 bytes long
    if len(private_key_bytes) != 32:
        raise ValueError("Private key must be 32 bytes long")

    # Create a Keypair from the 32-byte private key
    sender_keypair = Keypair.from_seed(private_key_bytes)

    # Correctly derive the public key from the Keypair
    sender_pubkey = sender_keypair.pubkey()

    # Create a Message instance
    message = Message(
        # account_keys=[sender_pubkey, PublicKey.from_string(recipient)],
        instructions=[transfer(TransferParams(from_pubkey=sender_pubkey, to_pubkey=PublicKey.from_string(recipient), lamports=amount * 1_000_000))],
    )

    # Get a recent blockhash
    solana_client = Client("https://api.mainnet-beta.solana.com")
    # Get the latest blockhash
    latest_blockhash_resp = solana_client.get_latest_blockhash()
    recent_blockha = getattr(latest_blockhash_resp.value, 'blockhash', None) 
    # Assuming recent_blockhash is already obtained as shown in your code
    # Create a Transaction instance
    txn = Transaction([sender_keypair],message,recent_blockha)

    # Sign the transaction with the recent_blockhash
    txn.sign([sender_keypair], recent_blockha)

    # Send the transaction
    return solana_client.send_transaction(txn)

' ' '

i am referred to /solana/rpc/api.py

if recent_blockhash is None:
blockhash_resp = self.get_latest_blockhash(Finalized)
recent_blockhash = self.parse_recent_blockhash(blockhash_resp)
last_valid_block_height = blockhash_resp.value.last_valid_block_height
txn.recent_blockhash = recent_blockhash

@michaelhly michaelhly added help wanted Extra attention is needed and removed help wanted Extra attention is needed labels Apr 24, 2024
@medvi
Copy link

medvi commented Jul 17, 2024

I have the same problem. It looks like a bug..?

I use the following versions of solders and solana:

solders = "^0.21.0"
solana = "^0.34.2"

and python version 3.11.4

Did you find a solution?

@kevinheavey
Copy link
Collaborator

kevinheavey commented Jul 17, 2024

this is not a bug because using a Solders legacy Transaction in send_transaction isn't supported, but it is confusing so we are considering removing the solana-py Transaction class entirely to avoid this confusion #442

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

4 participants