Skip to main content
5 of 5
added 2623 characters in body

Keypair-pubkey mismatch when partial signing - Python

I am trying to create and partial sign a transaction for create an account, but I keep receiving a keypair mismatch error. My code looks like this:

from spl.token.instructions import create_associated_token_account
from solana.keypair import Keypair
from solana.publickey import PublicKey
from solana.transaction import Transaction

signer = Keypair()

create_transaction_instruction = create_associated_token_account(
    payer=PublicKey(mintFeePayer), owner=signer.public_key, mint=PublicKey(mintPublicKey)
)

transaction = Transaction()
transaction.add(
    create_transaction_instruction
)

transaction.sign_partial(signer)

I am using https://github.com/michaelhly/solana-py which apparently is the most python unofficial library for this, I am open to use something else if it works.

And I always get:

Traceback (most recent call last):
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "kinetic_sdk/__main__.py", line 49, in <module>
    transaction.sign_partial(signer)
  File "/Users/alexramirez/Library/Caches/pypoetry/virtualenvs/kinetic-sdk--u4hmztD-py3.8/lib/python3.8/site-packages/solana/transaction.py", line 299, in sign_partial
    self._solders.partial_sign(underlying_signers, self._solders.message.recent_blockhash)
solders.SignerError: keypair-pubkey mismatch
make: *** [run_sdk] Error 1

Thanks.

Updated code just using solders:

from solders.message import Message
from solders.keypair import Keypair
from solders.instruction import Instruction, AccountMeta
from solders.hash import Hash
from solders.transaction import Transaction
from solders.pubkey import Pubkey

TOKEN_PROGRAM_ID = Pubkey.from_string('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA')
ASSOCIATED_TOKEN_PROGRAM_ID = Pubkey.from_string('ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL')
SYSVAR_RENT_PUBKEY = Pubkey.from_string('SysvarRent111111111111111111111111111111111')
ZERO_BYTES = bytes([0])
SYSTEM_PROGRAM_PROGRAM_ID = Pubkey.from_string('11111111111111111111111111111111')

owner = Keypair.from_base58_string('2an9mq3qY6e7PhGxHYRcw3JbpHLrBYgRzH5QBKgJZSxUUszYrgXQbRFZicuVWZLNiBzeUE3rgDma2EnYQKse8UpB')
fee_payer = Pubkey.from_string('MogXFseNqiFnRtk6wrDL9BDfKRZhjP5VBSiE1E35zeJ')

associated_token_address = Pubkey.from_string('3FuYhW79b3xbyixukA8pav6P9TgEwtCKPEhC1sULxBxG')

instruction = Instruction(
    ASSOCIATED_TOKEN_PROGRAM_ID,
    ZERO_BYTES,
    [
        AccountMeta(fee_payer, True, True),
        AccountMeta(associated_token_address, False, True),
        AccountMeta(owner.pubkey(), False, False),
        AccountMeta(SYSTEM_PROGRAM_PROGRAM_ID, False, False),
        AccountMeta(TOKEN_PROGRAM_ID, False, False),
        AccountMeta(SYSVAR_RENT_PUBKEY, False, False),
    ],
)

null_signer = NullSigner(owner.pubkey())

message = Message([instruction], owner.pubkey())
blockhash = Hash.default()  # replace with a real blockhash
transaction = Transaction([owner], message, blockhash)

print(transaction)

New Error:

thread '<unnamed>' panicked at 'Transaction::sign failed with error NotEnoughSigners', /Users/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/solana-sdk-1.10.25/src/transaction/mod.rs:710:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Traceback (most recent call last):
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "src/__main__.py", line 88, in <module>
    transaction = Transaction([owner], message, blockhash)
pyo3_runtime.PanicException: Transaction::sign failed with error NotEnoughSigners
make: *** [start] Error 1