michaelhly / solana-py

Solana Python SDK
https://michaelhly.github.io/solana-py
MIT License
1.04k stars 273 forks source link

Simple transfer in Python: 'not enough signers' #392

Closed rthickling closed 9 months ago

rthickling commented 9 months ago

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?

rthickling commented 9 months ago

I've got this to work.

rust-master commented 6 months ago

@rthickling can you explain, how