[Python] Manage anchorpy function call with no signers required

Discussão em 'Python' iniciado por Stack, Março 5, 2025.

  1. Stack

    Stack Membro Participativo

    everyone, I have a problem with my code. This is the anchorpy function which has been generated from the IDL:

    class TimeoutAccounts(typing.TypedDict):
    participant1: Pubkey
    participant2: Pubkey
    bet_info: Pubkey


    def timeout(
    accounts: TimeoutAccounts,
    program_id: Pubkey = PROGRAM_ID,
    remaining_accounts: typing.Optional[typing.List[AccountMeta]] = None,
    ) -> Instruction:
    keys: list[AccountMeta] = [
    AccountMeta(pubkey=accounts["participant1"], is_signer=False, is_writable=True),
    AccountMeta(pubkey=accounts["participant2"], is_signer=False, is_writable=True),
    AccountMeta(pubkey=accounts["bet_info"], is_signer=False, is_writable=True),
    AccountMeta(pubkey=SYS_PROGRAM_ID, is_signer=False, is_writable=False),
    ]
    if remaining_accounts is not None:
    keys += remaining_accounts
    identifier = b"\t6.\xa9\x9c\xbdP\xf7"
    encoded_args = b""
    data = identifier + encoded_args
    return Instruction(program_id, data, keys)


    As you can see, this code does not require any signer. However, when if I try to call:

    tx.sign(signers)


    with an empty list of signers, an error is given to me:


    solders.SignerError: not enough signers
    ​

    If instead, I try to skip the tx.sign() if there are no signers required, I receive an error since the transactions always need to be signed.

    Finally, if I sign the transaction with a random wallet, I receive this error:


    self._solders.sign(signers, self._solders.message.recent_blockhash) solders.SignerError: keypair-pubkey mismatch
    ​

    How can I approach this kind of function calls? Thank you

    Continue reading...

Compartilhe esta Página