1

and apologies if there's a obvious better place to ask this.

I'm writing experimental Python 3.12 code to move SOL from/to an address I create "by hand" and a centralized exchange (Kraken), like this:

from solders.keypair import Keypair
import base58

# Create keys and a Solana address
by_hand_keypair = Keypair()
by_hand_sol_address = base58.b58encode(bytes(by_hand_keypair.pubkey())).decode("utf-8")

Now I then transferred 0.03 SOL to my new address via Kraken Pro and wait a bit...

# ... and check if it's there:
    
from solana.rpc.api import Client 
   
client = Client("https://api.mainnet-beta.solana.com/")
print(f"New Solana address balance: {client.get_balance(by_hand_keypair.pubkey()).value}")

It is, showing the right balance (30000000)

Now I try to transfer some back

from solders.pubkey import Pubkey
from solana.transaction import Transaction
from solders.system_program import transfer
from solders.system_program import TransferParams
    
kraken_sol_address = "C2od3xYdTh4nbt9WP3mSN67rFhDZ3MGKood8LtyJGaui"
kraken_pub_key = Pubkey(base58.b58decode(kraken_sol_address))
    
blockhash = client.get_latest_blockhash().value.blockhash
transaction = Transaction(fee_payer=by_hand_keypair.pubkey(), recent_blockhash=blockhash)
transaction.add(
    transfer(
        TransferParams(
            from_pubkey=by_hand_keypair.pubkey(),
            to_pubkey=kraken_pub_key,
            lamports=10000000
        )
    )
)
transaction.sign(by_hand_keypair)
response = client.send_transaction(transaction)

It's here I get the SignerError: not enough signers

What have I misunderstood?

1 Answer 1

1

It's subtle, but send_transaction resigns the transaction with the provided signers, so you should be able to fix it by removing the call to sign and instead passing the signer to send_transaction:

response = client.send_transaction(transaction, by_hand_keypair)

Looking at the code at https://github.com/michaelhly/solana-py/blob/36ab2b5343d3f45cbe562df86e2d04101e101e71/src/solana/rpc/api.py#L998 and a test using send_transaction at https://github.com/michaelhly/solana-py/blob/36ab2b5343d3f45cbe562df86e2d04101e101e71/tests/integration/test_http_client.py#L89

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.