1

hello guys pls i get the error ( ERROR - Error sending transaction: 'result') in my below code, i'm making use of sol version 0.24.0 & python

def transfer_to_central_wallet(private_key: str, amount: float) -> bool: try: from_keypair = Keypair.from_secret_key(b58decode(private_key)) to_pubkey = PublicKey(CENTRAL_WALLET_ADDRESS)

    # Get recent blockhash
    recent_blockhash_resp = client.get_recent_blockhash()
    recent_blockhash = recent_blockhash_resp['result']['value']['blockhash']

    # Create transaction
    lamports = int(amount * 1_000_000_000)  # Convert SOL to lamports

    tx = Transaction(recent_blockhash=recent_blockhash)
    tx.add(
        transfer(
            TransferParams(
                from_pubkey=from_keypair.public_key,
                to_pubkey=to_pubkey,
                lamports=lamports
            )
        )
    )

    # Sign transaction
    tx.sign(from_keypair)

    # Send transaction with TxOpts
    opts = TxOpts(skip_preflight=False, preflight_commitment='confirmed')
    response = client.send_raw_transaction(tx.serialize(), opts=opts)
    logger.info(f"Transaction sent with signature: {response['result']}")
    return True
except Exception as e:
    logger.error(f"Error sending transaction: {str(e)}")
    return False

1 Answer 1

0

The get_recent_blockhash RPC call was removed in v2 of the Solana validator. Be sure to update your solana-py library and use get_latest_blockhash instead:

    recent_blockhash = client.get_latest_blockhash().value.blockhash

Here's the source code for the new function, which comes with an example: https://github.com/michaelhly/solana-py/blob/2119e9da2f86f700730c69d86392243b5ef3dcea/src/solana/rpc/api.py#L690

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.