Skip to content

Vote Program

solana.vote_program

Library to interface with the vote program.

withdraw_from_vote_account(params)

Generate an instruction that transfers lamports from a vote account to any other.

Example

from solders.pubkey import Pubkey from solders.keypair import Keypair from solana.models import WithdrawFromVoteAccountParams vote = Pubkey([0] * 31 + [1]) withdrawer = Keypair.from_seed(bytes([0]*32)) instruction = withdraw_from_vote_account( ... WithdrawFromVoteAccountParams( ... vote_account_from_pubkey=vote, ... to_pubkey=withdrawer.pubkey(), ... withdrawer=withdrawer.pubkey(), ... lamports=3_000_000_000, ... ) ... ) type(instruction)

Returns:

Type Description
Instruction

The generated instruction.

Source code in src/solana/vote_program.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
def withdraw_from_vote_account(
    params: models.WithdrawFromVoteAccountParams,
) -> Instruction:
    """Generate an instruction that transfers lamports from a vote account to any other.

    Example:
        >>> from solders.pubkey import Pubkey
        >>> from solders.keypair import Keypair
        >>> from solana.models import WithdrawFromVoteAccountParams
        >>> vote = Pubkey([0] * 31 + [1])
        >>> withdrawer = Keypair.from_seed(bytes([0]*32))
        >>> instruction = withdraw_from_vote_account(
        ...    WithdrawFromVoteAccountParams(
        ...        vote_account_from_pubkey=vote,
        ...        to_pubkey=withdrawer.pubkey(),
        ...        withdrawer=withdrawer.pubkey(),
        ...        lamports=3_000_000_000,
        ...    )
        ... )
        >>> type(instruction)
        <class 'solders.instruction.Instruction'>

    Returns:
        The generated instruction.
    """
    data = VOTE_INSTRUCTIONS_LAYOUT.build(
        {
            "instruction_type": InstructionType.WITHDRAW_FROM_VOTE_ACCOUNT,
            "args": {"lamports": params.lamports},
        }
    )

    return Instruction(
        accounts=[
            AccountMeta(
                pubkey=params.vote_account_from_pubkey,
                is_signer=False,
                is_writable=True,
            ),
            AccountMeta(pubkey=params.to_pubkey, is_signer=False, is_writable=True),
            AccountMeta(pubkey=params.withdrawer, is_signer=True, is_writable=True),
        ],
        program_id=VOTE_PROGRAM_ID,
        data=data,
    )