Skip to content

Instructions

spl.token.instructions

SPL token instructions.

amount_to_ui_amount(params)

Converts a raw token amount to a UiAmount string using the given mint.

Source code in src/spl/token/instructions.py
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
def amount_to_ui_amount(params: models.AmountToUiAmountParams) -> Instruction:
    """Converts a raw token amount to a UiAmount string using the given mint."""
    data = INSTRUCTIONS_LAYOUT.build(
        {
            "instruction_type": InstructionType.AMOUNT_TO_UI_AMOUNT,
            "args": {"amount": params.amount},
        }
    )
    return Instruction(
        accounts=[AccountMeta(pubkey=params.mint, is_signer=False, is_writable=False)],
        program_id=params.program_id,
        data=data,
    )

approve(params)

Creates a transaction instruction to approve a delegate.

Example

from spl.token.models import ApproveParams leading_zeros = [0] * 31 pubkeys = [Pubkey(leading_zeros + [i + 1]) for i in range(4)] delegate, owner, source, token = pubkeys params = ApproveParams( ... amount=123, ... delegate=delegate, ... owner=owner, ... program_id=token, ... source=source ... ) type(approve(params))

Returns:

Type Description
Instruction

The approve instruction.

Source code in src/spl/token/instructions.py
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
def approve(params: models.ApproveParams) -> Instruction:
    """Creates a transaction instruction to approve a delegate.

    Example:
        >>> from spl.token.models import ApproveParams
        >>> leading_zeros = [0] * 31
        >>> pubkeys = [Pubkey(leading_zeros + [i + 1]) for i in range(4)]
        >>> delegate, owner, source, token = pubkeys
        >>> params = ApproveParams(
        ...     amount=123,
        ...     delegate=delegate,
        ...     owner=owner,
        ...     program_id=token,
        ...     source=source
        ... )
        >>> type(approve(params))
        <class 'solders.instruction.Instruction'>

    Returns:
        The approve instruction.
    """
    data = INSTRUCTIONS_LAYOUT.build({"instruction_type": InstructionType.APPROVE, "args": {"amount": params.amount}})
    keys = [
        AccountMeta(pubkey=params.source, is_signer=False, is_writable=True),
        AccountMeta(pubkey=params.delegate, is_signer=False, is_writable=False),
    ]
    __add_signers(keys, params.owner, params.signers)

    return Instruction(accounts=keys, program_id=params.program_id, data=data)

approve_checked(params)

This instruction differs from approve in that the token mint and decimals value is asserted by the caller.

Example

from spl.token.models import ApproveCheckedParams leading_zeros = [0] * 31 pubkeys = [Pubkey(leading_zeros + [i + 1]) for i in range(5)] delegate, mint, owner, source, token = pubkeys params = ApproveCheckedParams( ... amount=1000, ... decimals=6, ... delegate=delegate, ... mint=mint, ... owner=owner, ... program_id=token, ... source=source, ... ) type(approve_checked(params))

Returns:

Type Description
Instruction

The approve-checked instruction.

Source code in src/spl/token/instructions.py
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
def approve_checked(params: models.ApproveCheckedParams) -> Instruction:
    """This instruction differs from `approve` in that the token mint and decimals value is asserted by the caller.

    Example:
        >>> from spl.token.models import ApproveCheckedParams
        >>> leading_zeros = [0] * 31
        >>> pubkeys = [Pubkey(leading_zeros + [i + 1]) for i in range(5)]
        >>> delegate, mint, owner, source, token = pubkeys
        >>> params = ApproveCheckedParams(
        ...     amount=1000,
        ...     decimals=6,
        ...     delegate=delegate,
        ...     mint=mint,
        ...     owner=owner,
        ...     program_id=token,
        ...     source=source,
        ... )
        >>> type(approve_checked(params))
        <class 'solders.instruction.Instruction'>

    Returns:
        The approve-checked instruction.
    """
    data = INSTRUCTIONS_LAYOUT.build(
        {
            "instruction_type": InstructionType.APPROVE2,
            "args": {"amount": params.amount, "decimals": params.decimals},
        }
    )
    keys = [
        AccountMeta(pubkey=params.source, is_signer=False, is_writable=True),
        AccountMeta(pubkey=params.mint, is_signer=False, is_writable=False),
        AccountMeta(pubkey=params.delegate, is_signer=False, is_writable=False),
    ]
    __add_signers(keys, params.owner, params.signers)

    return Instruction(accounts=keys, program_id=params.program_id, data=data)

burn(params)

Creates a transaction instruction to burns tokens by removing them from an account.

Example

from spl.token.models import BurnParams leading_zeros = [0] * 31 pubkeys = [Pubkey(leading_zeros + [i + 1]) for i in range(4)] account, mint, owner, token = pubkeys params = BurnParams( ... amount=123, account=account, mint=mint, owner=owner, program_id=token, ... ) type(burn(params))

Returns:

Type Description
Instruction

The burn instruction.

Source code in src/spl/token/instructions.py
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
def burn(params: models.BurnParams) -> Instruction:
    """Creates a transaction instruction to burns tokens by removing them from an account.

    Example:
        >>> from spl.token.models import BurnParams
        >>> leading_zeros = [0] * 31
        >>> pubkeys = [Pubkey(leading_zeros + [i + 1]) for i in range(4)]
        >>> account, mint, owner, token = pubkeys
        >>> params = BurnParams(
        ...     amount=123, account=account, mint=mint, owner=owner, program_id=token,
        ... )
        >>> type(burn(params))
        <class 'solders.instruction.Instruction'>

    Returns:
        The burn instruction.
    """
    data = INSTRUCTIONS_LAYOUT.build({"instruction_type": InstructionType.BURN, "args": {"amount": params.amount}})
    return __burn_instruction(params, data)

burn_checked(params)

This instruction differs from burn in that the decimals value is asserted by the caller.

Example

from spl.token.models import BurnCheckedParams leading_zeros = [0] * 31 pubkeys = [Pubkey(leading_zeros + [i + 1]) for i in range(4)] account, mint, owner, token = pubkeys params = BurnCheckedParams( ... amount=123, account=account, decimals=6, mint=mint, owner=owner, program_id=token, ... ) type(burn_checked(params))

Returns:

Type Description
Instruction

The burn-checked instruction.

Source code in src/spl/token/instructions.py
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
def burn_checked(params: models.BurnCheckedParams) -> Instruction:
    """This instruction differs from `burn` in that the decimals value is asserted by the caller.

    Example:
        >>> from spl.token.models import BurnCheckedParams
        >>> leading_zeros = [0] * 31
        >>> pubkeys = [Pubkey(leading_zeros + [i + 1]) for i in range(4)]
        >>> account, mint, owner, token = pubkeys
        >>> params = BurnCheckedParams(
        ...     amount=123, account=account, decimals=6, mint=mint, owner=owner, program_id=token,
        ... )
        >>> type(burn_checked(params))
        <class 'solders.instruction.Instruction'>

    Returns:
        The burn-checked instruction.
    """
    data = INSTRUCTIONS_LAYOUT.build(
        {
            "instruction_type": InstructionType.BURN2,
            "args": {"amount": params.amount, "decimals": params.decimals},
        }
    )
    return __burn_instruction(params, data)

close_account(params)

Creates a transaction instruction to close an account by transferring all its SOL to the destination account.

Non-native accounts may only be closed if its token amount is zero.

Example

from spl.token.models import CloseAccountParams leading_zeros = [0] * 31 pubkeys = [Pubkey(leading_zeros + [i + 1]) for i in range(4)] account, dest, owner, token = pubkeys params = CloseAccountParams( ... account=account, dest=dest, owner=owner, program_id=token) type(close_account(params))

Returns:

Type Description
Instruction

The close-account instruction.

Source code in src/spl/token/instructions.py
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
def close_account(params: models.CloseAccountParams) -> Instruction:
    """Creates a transaction instruction to close an account by transferring all its SOL to the destination account.

    Non-native accounts may only be closed if its token amount is zero.

    Example:
        >>> from spl.token.models import CloseAccountParams
        >>> leading_zeros = [0] * 31
        >>> pubkeys = [Pubkey(leading_zeros + [i + 1]) for i in range(4)]
        >>> account, dest, owner, token = pubkeys
        >>> params = CloseAccountParams(
        ...     account=account, dest=dest, owner=owner, program_id=token)
        >>> type(close_account(params))
        <class 'solders.instruction.Instruction'>

    Returns:
        The close-account instruction.
    """
    data = INSTRUCTIONS_LAYOUT.build({"instruction_type": InstructionType.CLOSE_ACCOUNT, "args": None})
    keys = [
        AccountMeta(pubkey=params.account, is_signer=False, is_writable=True),
        AccountMeta(pubkey=params.dest, is_signer=False, is_writable=True),
    ]
    __add_signers(keys, params.owner, params.signers)

    return Instruction(accounts=keys, program_id=params.program_id, data=data)

create_associated_token_account(payer, owner, mint, token_program_id=TOKEN_PROGRAM_ID)

Creates a transaction instruction to create an associated token account.

Parameters:

Name Type Description Default
payer Pubkey

Payer's wallet address.

required
owner Pubkey

Owner's wallet address.

required
mint Pubkey

The token mint address.

required
token_program_id Pubkey

The token program ID. Must be either spl.token.constants.TOKEN_PROGRAM_ID or spl.token.constants.TOKEN_2022_PROGRAM_ID (default is TOKEN_PROGRAM_ID).

TOKEN_PROGRAM_ID

Returns:

Type Description
Instruction

The instruction to create the associated token account.

Raises:

Type Description
ValueError

If an invalid token_program_id is provided.

Source code in src/spl/token/instructions.py
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
def create_associated_token_account(
    payer: Pubkey,
    owner: Pubkey,
    mint: Pubkey,
    token_program_id: Pubkey = TOKEN_PROGRAM_ID,
) -> Instruction:
    """Creates a transaction instruction to create an associated token account.

    Args:
        payer (Pubkey): Payer's wallet address.
        owner (Pubkey): Owner's wallet address.
        mint (Pubkey): The token mint address.
        token_program_id (Pubkey, optional): The token program ID. Must be either `spl.token.constants.TOKEN_PROGRAM_ID`
            or `spl.token.constants.TOKEN_2022_PROGRAM_ID` (default is `TOKEN_PROGRAM_ID`).

    Returns:
        The instruction to create the associated token account.

    Raises:
        ValueError: If an invalid `token_program_id` is provided.
    """
    if token_program_id not in [TOKEN_PROGRAM_ID, TOKEN_2022_PROGRAM_ID]:
        raise ValueError("token_program_id must be one of TOKEN_PROGRAM_ID or TOKEN_2022_PROGRAM_ID.")
    associated_token_address = get_associated_token_address(owner, mint, token_program_id)
    return Instruction(
        accounts=[
            AccountMeta(pubkey=payer, is_signer=True, is_writable=True),
            AccountMeta(pubkey=associated_token_address, is_signer=False, is_writable=True),
            AccountMeta(pubkey=owner, is_signer=False, is_writable=False),
            AccountMeta(pubkey=mint, is_signer=False, is_writable=False),
            AccountMeta(pubkey=SYS_PROGRAM_ID, is_signer=False, is_writable=False),
            AccountMeta(pubkey=token_program_id, is_signer=False, is_writable=False),
            AccountMeta(pubkey=RENT, is_signer=False, is_writable=False),
        ],
        program_id=ASSOCIATED_TOKEN_PROGRAM_ID,
        data=bytes(0),
    )

create_idempotent_associated_token_account(payer, owner, mint, token_program_id=TOKEN_PROGRAM_ID)

Creates an associated token account for the given address/token mint if it not exists.

Returns:

Type Description
Instruction

The instruction to create the associated token account.

Source code in src/spl/token/instructions.py
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
def create_idempotent_associated_token_account(
    payer: Pubkey,
    owner: Pubkey,
    mint: Pubkey,
    token_program_id: Pubkey = TOKEN_PROGRAM_ID,
) -> Instruction:
    """Creates an associated token account for the given address/token mint if it not exists.

    Returns:
        The instruction to create the associated token account.
    """
    if token_program_id not in [TOKEN_PROGRAM_ID, TOKEN_2022_PROGRAM_ID]:
        raise ValueError("token_program_id must be one of TOKEN_PROGRAM_ID or TOKEN_2022_PROGRAM_ID.")
    associated_token_address = get_associated_token_address(owner, mint, token_program_id)
    return Instruction(
        accounts=[
            AccountMeta(pubkey=payer, is_signer=True, is_writable=True),
            AccountMeta(pubkey=associated_token_address, is_signer=False, is_writable=True),
            AccountMeta(pubkey=owner, is_signer=False, is_writable=False),
            AccountMeta(pubkey=mint, is_signer=False, is_writable=False),
            AccountMeta(pubkey=SYS_PROGRAM_ID, is_signer=False, is_writable=False),
            AccountMeta(pubkey=token_program_id, is_signer=False, is_writable=False),
        ],
        program_id=ASSOCIATED_TOKEN_PROGRAM_ID,
        data=bytes([1]),
    )

decode_amount_to_ui_amount(instruction)

Decode an amount_to_ui_amount token transaction and retrieve the instruction params.

Source code in src/spl/token/instructions.py
534
535
536
537
538
539
540
541
542
543
def decode_amount_to_ui_amount(
    instruction: Instruction,
) -> models.AmountToUiAmountParams:
    """Decode an amount_to_ui_amount token transaction and retrieve the instruction params."""
    parsed_data = __parse_and_validate_instruction(instruction, 1, InstructionType.AMOUNT_TO_UI_AMOUNT)
    return models.AmountToUiAmountParams(
        program_id=instruction.program_id,
        mint=instruction.accounts[0].pubkey,
        amount=parsed_data.args.amount,
    )

decode_approve(instruction)

Decode a approve token transaction and retrieve the instruction params.

Parameters:

Name Type Description Default
instruction Instruction

The instruction to decode.

required

Returns:

Type Description
ApproveParams

The decoded instruction.

Source code in src/spl/token/instructions.py
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
def decode_approve(instruction: Instruction) -> models.ApproveParams:
    """Decode a approve token transaction and retrieve the instruction params.

    Args:
        instruction: The instruction to decode.

    Returns:
        The decoded instruction.
    """
    parsed_data = __parse_and_validate_instruction(instruction, 3, InstructionType.APPROVE)
    return models.ApproveParams(
        program_id=instruction.program_id,
        source=instruction.accounts[0].pubkey,
        delegate=instruction.accounts[1].pubkey,
        owner=instruction.accounts[2].pubkey,
        signers=[signer.pubkey for signer in instruction.accounts[3:]],
        amount=parsed_data.args.amount,
    )

decode_approve_checked(instruction)

Decode a approve_checked token transaction and retrieve the instruction params.

Parameters:

Name Type Description Default
instruction Instruction

The instruction to decode.

required

Returns:

Type Description
ApproveCheckedParams

The decoded instruction.

Source code in src/spl/token/instructions.py
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
def decode_approve_checked(instruction: Instruction) -> models.ApproveCheckedParams:
    """Decode a approve_checked token transaction and retrieve the instruction params.

    Args:
        instruction: The instruction to decode.

    Returns:
        The decoded instruction.
    """
    parsed_data = __parse_and_validate_instruction(instruction, 4, InstructionType.APPROVE2)
    return models.ApproveCheckedParams(
        program_id=instruction.program_id,
        amount=parsed_data.args.amount,
        decimals=parsed_data.args.decimals,
        source=instruction.accounts[0].pubkey,
        mint=instruction.accounts[1].pubkey,
        delegate=instruction.accounts[2].pubkey,
        owner=instruction.accounts[3].pubkey,
        signers=[signer.pubkey for signer in instruction.accounts[4:]],
    )

decode_burn(instruction)

Decode a burn token transaction and retrieve the instruction params.

Parameters:

Name Type Description Default
instruction Instruction

The instruction to decode.

required

Returns:

Type Description
BurnParams

The decoded instruction.

Source code in src/spl/token/instructions.py
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
def decode_burn(instruction: Instruction) -> models.BurnParams:
    """Decode a burn token transaction and retrieve the instruction params.

    Args:
        instruction: The instruction to decode.

    Returns:
        The decoded instruction.
    """
    parsed_data = __parse_and_validate_instruction(instruction, 3, InstructionType.BURN)
    return models.BurnParams(
        program_id=instruction.program_id,
        amount=parsed_data.args.amount,
        account=instruction.accounts[0].pubkey,
        mint=instruction.accounts[1].pubkey,
        owner=instruction.accounts[2].pubkey,
        signers=[signer.pubkey for signer in instruction.accounts[3:]],
    )

decode_burn_checked(instruction)

Decode a burn_checked token transaction and retrieve the instruction params.

Parameters:

Name Type Description Default
instruction Instruction

The instruction to decode.

required

Returns:

Type Description
BurnCheckedParams

The decoded instruction.

Source code in src/spl/token/instructions.py
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
def decode_burn_checked(instruction: Instruction) -> models.BurnCheckedParams:
    """Decode a burn_checked token transaction and retrieve the instruction params.

    Args:
        instruction: The instruction to decode.

    Returns:
        The decoded instruction.
    """
    parsed_data = __parse_and_validate_instruction(instruction, 3, InstructionType.BURN2)
    return models.BurnCheckedParams(
        program_id=instruction.program_id,
        amount=parsed_data.args.amount,
        decimals=parsed_data.args.decimals,
        account=instruction.accounts[0].pubkey,
        mint=instruction.accounts[1].pubkey,
        owner=instruction.accounts[2].pubkey,
        signers=[signer.pubkey for signer in instruction.accounts[3:]],
    )

decode_close_account(instruction)

Decode a close account token transaction and retrieve the instruction params.

Parameters:

Name Type Description Default
instruction Instruction

The instruction to decode.

required

Returns:

Type Description
CloseAccountParams

The decoded instruction.

Source code in src/spl/token/instructions.py
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
def decode_close_account(instruction: Instruction) -> models.CloseAccountParams:
    """Decode a close account token transaction and retrieve the instruction params.

    Args:
        instruction: The instruction to decode.

    Returns:
        The decoded instruction.
    """
    _ = __parse_and_validate_instruction(instruction, 3, InstructionType.CLOSE_ACCOUNT)
    return models.CloseAccountParams(
        program_id=instruction.program_id,
        account=instruction.accounts[0].pubkey,
        dest=instruction.accounts[1].pubkey,
        owner=instruction.accounts[2].pubkey,
        signers=[signer.pubkey for signer in instruction.accounts[3:]],
    )

decode_freeze_account(instruction)

Decode a freeze account token transaction and retrieve the instruction params.

Parameters:

Name Type Description Default
instruction Instruction

The instruction to decode.

required

Returns:

Type Description
FreezeAccountParams

The decoded instruction.

Source code in src/spl/token/instructions.py
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
def decode_freeze_account(instruction: Instruction) -> models.FreezeAccountParams:
    """Decode a freeze account token transaction and retrieve the instruction params.

    Args:
        instruction: The instruction to decode.

    Returns:
        The decoded instruction.
    """
    _ = __parse_and_validate_instruction(instruction, 3, InstructionType.FREEZE_ACCOUNT)
    return models.FreezeAccountParams(
        program_id=instruction.program_id,
        account=instruction.accounts[0].pubkey,
        mint=instruction.accounts[1].pubkey,
        authority=instruction.accounts[2].pubkey,
        multi_signers=[signer.pubkey for signer in instruction.accounts[3:]],
    )

decode_get_account_data_size(instruction)

Decode a get_account_data_size token transaction and retrieve the instruction params.

Source code in src/spl/token/instructions.py
434
435
436
437
438
439
440
441
442
def decode_get_account_data_size(
    instruction: Instruction,
) -> models.GetAccountDataSizeParams:
    """Decode a get_account_data_size token transaction and retrieve the instruction params."""
    _ = __parse_and_validate_instruction(instruction, 1, InstructionType.GET_ACCOUNT_DATA_SIZE)
    return models.GetAccountDataSizeParams(
        program_id=instruction.program_id,
        mint=instruction.accounts[0].pubkey,
    )

decode_harvest_withheld_tokens_to_mint(instruction)

Decode a harvest_withheld_tokens_to_mint token transaction and retrieve the instruction params.

Source code in src/spl/token/instructions.py
520
521
522
523
524
525
526
527
528
529
530
531
def decode_harvest_withheld_tokens_to_mint(
    instruction: Instruction,
) -> models.HarvestWithheldTokensToMintParams:
    """Decode a harvest_withheld_tokens_to_mint token transaction and retrieve the instruction params."""
    parsed_data = __parse_and_validate_instruction(instruction, 1, InstructionType.TRANSFER_FEE_EXTENSION)
    if parsed_data.args.transfer_fee_instruction_type != TransferFeeInstructionType.HARVEST_WITHHELD_TOKENS_TO_MINT:
        raise ValueError("invalid transfer fee instruction type")
    return models.HarvestWithheldTokensToMintParams(
        program_id=instruction.program_id,
        mint=instruction.accounts[0].pubkey,
        sources=[source.pubkey for source in instruction.accounts[1:]],
    )

decode_initialize_account(instruction)

Decode an initialize account token instruction and retrieve the instruction params.

Parameters:

Name Type Description Default
instruction Instruction

The instruction to decode.

required

Returns:

Type Description
InitializeAccountParams

The decoded instruction.

Source code in src/spl/token/instructions.py
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
def decode_initialize_account(
    instruction: Instruction,
) -> models.InitializeAccountParams:
    """Decode an initialize account token instruction and retrieve the instruction params.

    Args:
        instruction: The instruction to decode.

    Returns:
        The decoded instruction.
    """
    _ = __parse_and_validate_instruction(instruction, 4, InstructionType.INITIALIZE_ACCOUNT)
    return models.InitializeAccountParams(
        program_id=instruction.program_id,
        account=instruction.accounts[0].pubkey,
        mint=instruction.accounts[1].pubkey,
        owner=instruction.accounts[2].pubkey,
    )

decode_initialize_account2(instruction)

Decode an initialize account2 token instruction and retrieve the instruction params.

Source code in src/spl/token/instructions.py
 94
 95
 96
 97
 98
 99
100
101
102
103
104
def decode_initialize_account2(
    instruction: Instruction,
) -> models.InitializeAccount2Params:
    """Decode an initialize account2 token instruction and retrieve the instruction params."""
    parsed_data = __parse_and_validate_instruction(instruction, 3, InstructionType.INITIALIZE_ACCOUNT2)
    return models.InitializeAccount2Params(
        program_id=instruction.program_id,
        account=instruction.accounts[0].pubkey,
        mint=instruction.accounts[1].pubkey,
        owner=Pubkey(parsed_data.args.owner),
    )

decode_initialize_account3(instruction)

Decode an initialize account3 token instruction and retrieve the instruction params.

Source code in src/spl/token/instructions.py
107
108
109
110
111
112
113
114
115
116
117
def decode_initialize_account3(
    instruction: Instruction,
) -> models.InitializeAccount3Params:
    """Decode an initialize account3 token instruction and retrieve the instruction params."""
    parsed_data = __parse_and_validate_instruction(instruction, 2, InstructionType.INITIALIZE_ACCOUNT3)
    return models.InitializeAccount3Params(
        program_id=instruction.program_id,
        account=instruction.accounts[0].pubkey,
        mint=instruction.accounts[1].pubkey,
        owner=Pubkey(parsed_data.args.owner),
    )

decode_initialize_immutable_owner(instruction)

Decode an initialize_immutable_owner token transaction and retrieve the instruction params.

Source code in src/spl/token/instructions.py
445
446
447
448
449
450
451
452
453
def decode_initialize_immutable_owner(
    instruction: Instruction,
) -> models.InitializeImmutableOwnerParams:
    """Decode an initialize_immutable_owner token transaction and retrieve the instruction params."""
    _ = __parse_and_validate_instruction(instruction, 1, InstructionType.INITIALIZE_IMMUTABLE_OWNER)
    return models.InitializeImmutableOwnerParams(
        program_id=instruction.program_id,
        account=instruction.accounts[0].pubkey,
    )

decode_initialize_mint(instruction)

Decode an initialize mint token instruction and retrieve the instruction params.

Parameters:

Name Type Description Default
instruction Instruction

The instruction to decode.

required

Returns:

Type Description
InitializeMintParams

The decoded instruction.

Source code in src/spl/token/instructions.py
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
def decode_initialize_mint(instruction: Instruction) -> models.InitializeMintParams:
    """Decode an initialize mint token instruction and retrieve the instruction params.

    Args:
        instruction: The instruction to decode.

    Returns:
        The decoded instruction.
    """
    parsed_data = __parse_and_validate_instruction(instruction, 2, InstructionType.INITIALIZE_MINT)
    return models.InitializeMintParams(
        decimals=parsed_data.args.decimals,
        program_id=instruction.program_id,
        mint=instruction.accounts[0].pubkey,
        mint_authority=Pubkey(parsed_data.args.mint_authority),
        freeze_authority=(
            Pubkey(parsed_data.args.freeze_authority) if parsed_data.args.freeze_authority_option else None
        ),
    )

decode_initialize_mint2(instruction)

Decode an initialize mint2 token instruction and retrieve the instruction params.

Source code in src/spl/token/instructions.py
60
61
62
63
64
65
66
67
68
69
70
71
def decode_initialize_mint2(instruction: Instruction) -> models.InitializeMint2Params:
    """Decode an initialize mint2 token instruction and retrieve the instruction params."""
    parsed_data = __parse_and_validate_instruction(instruction, 1, InstructionType.INITIALIZE_MINT2)
    return models.InitializeMint2Params(
        decimals=parsed_data.args.decimals,
        program_id=instruction.program_id,
        mint=instruction.accounts[0].pubkey,
        mint_authority=Pubkey(parsed_data.args.mint_authority),
        freeze_authority=(
            Pubkey(parsed_data.args.freeze_authority) if parsed_data.args.freeze_authority_option else None
        ),
    )

decode_initialize_multisig(instruction)

Decode an initialize multisig account token instruction and retrieve the instruction params.

Parameters:

Name Type Description Default
instruction Instruction

The instruction to decode.

required

Returns:

Type Description
InitializeMultisigParams

The decoded instruction.

Source code in src/spl/token/instructions.py
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
def decode_initialize_multisig(
    instruction: Instruction,
) -> models.InitializeMultisigParams:
    """Decode an initialize multisig account token instruction and retrieve the instruction params.

    Args:
        instruction: The instruction to decode.

    Returns:
        The decoded instruction.
    """
    parsed_data = __parse_and_validate_instruction(instruction, 2, InstructionType.INITIALIZE_MULTISIG)
    num_signers = parsed_data.args.m
    validate_instruction_keys(instruction, 2 + num_signers)
    return models.InitializeMultisigParams(
        program_id=instruction.program_id,
        multisig=instruction.accounts[0].pubkey,
        signers=[signer.pubkey for signer in instruction.accounts[-num_signers:]],
        m=num_signers,
    )

decode_initialize_multisig2(instruction)

Decode an initialize multisig2 account token instruction and retrieve the instruction params.

Source code in src/spl/token/instructions.py
142
143
144
145
146
147
148
149
150
151
152
153
154
155
def decode_initialize_multisig2(
    instruction: Instruction,
) -> models.InitializeMultisig2Params:
    """Decode an initialize multisig2 account token instruction and retrieve the instruction params."""
    parsed_data = __parse_and_validate_instruction(instruction, 1, InstructionType.INITIALIZE_MULTISIG2)
    num_signers = parsed_data.args.m
    validate_instruction_keys(instruction, 1 + num_signers)
    signers: List[Pubkey] = [signer.pubkey for signer in instruction.accounts[-num_signers:]] if num_signers else []
    return models.InitializeMultisig2Params(
        program_id=instruction.program_id,
        multisig=instruction.accounts[0].pubkey,
        signers=signers,
        m=num_signers,
    )

decode_initialize_transfer_fee_config(instruction)

Decode an initialize_transfer_fee_config token transaction and retrieve the instruction params.

Source code in src/spl/token/instructions.py
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
def decode_initialize_transfer_fee_config(
    instruction: Instruction,
) -> models.InitializeTransferFeeConfigParams:
    """Decode an initialize_transfer_fee_config token transaction and retrieve the instruction params."""
    parsed_data = __parse_and_validate_instruction(instruction, 1, InstructionType.TRANSFER_FEE_EXTENSION)
    if parsed_data.args.transfer_fee_instruction_type != TransferFeeInstructionType.INITIALIZE_TRANSFER_FEE_CONFIG:
        raise ValueError("invalid transfer fee instruction type")
    args = parsed_data.args.args
    transfer_fee_config_authority = args.transfer_fee_config_authority
    withdraw_withheld_authority = args.withdraw_withheld_authority
    return models.InitializeTransferFeeConfigParams(
        program_id=instruction.program_id,
        mint=instruction.accounts[0].pubkey,
        transfer_fee_config_authority=(
            Pubkey(transfer_fee_config_authority.pubkey) if transfer_fee_config_authority.option else None
        ),
        withdraw_withheld_authority=(
            Pubkey(withdraw_withheld_authority.pubkey) if withdraw_withheld_authority.option else None
        ),
        transfer_fee_basis_points=args.transfer_fee_basis_points,
        maximum_fee=args.maximum_fee,
    )

decode_mint_to(instruction)

Decode a mint to token transaction and retrieve the instruction params.

Parameters:

Name Type Description Default
instruction Instruction

The instruction to decode.

required

Returns:

Type Description
MintToParams

The decoded instruction.

Source code in src/spl/token/instructions.py
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
def decode_mint_to(instruction: Instruction) -> models.MintToParams:
    """Decode a mint to token transaction and retrieve the instruction params.

    Args:
        instruction: The instruction to decode.

    Returns:
        The decoded instruction.
    """
    parsed_data = __parse_and_validate_instruction(instruction, 3, InstructionType.MINT_TO)
    return models.MintToParams(
        program_id=instruction.program_id,
        amount=parsed_data.args.amount,
        mint=instruction.accounts[0].pubkey,
        dest=instruction.accounts[1].pubkey,
        mint_authority=instruction.accounts[2].pubkey,
        signers=[signer.pubkey for signer in instruction.accounts[3:]],
    )

decode_mint_to_checked(instruction)

Decode a mintTo2 token transaction and retrieve the instruction params.

Parameters:

Name Type Description Default
instruction Instruction

The instruction to decode.

required

Returns:

Type Description
MintToCheckedParams

The decoded instruction.

Source code in src/spl/token/instructions.py
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
def decode_mint_to_checked(instruction: Instruction) -> models.MintToCheckedParams:
    """Decode a mintTo2 token transaction and retrieve the instruction params.

    Args:
        instruction: The instruction to decode.

    Returns:
        The decoded instruction.
    """
    parsed_data = __parse_and_validate_instruction(instruction, 3, InstructionType.MINT_TO2)
    return models.MintToCheckedParams(
        program_id=instruction.program_id,
        amount=parsed_data.args.amount,
        decimals=parsed_data.args.decimals,
        mint=instruction.accounts[0].pubkey,
        dest=instruction.accounts[1].pubkey,
        mint_authority=instruction.accounts[2].pubkey,
        signers=[signer.pubkey for signer in instruction.accounts[3:]],
    )

decode_revoke(instruction)

Decode a revoke token transaction and retrieve the instruction params.

Parameters:

Name Type Description Default
instruction Instruction

The instruction to decode.

required

Returns:

Type Description
RevokeParams

The decoded instruction.

Source code in src/spl/token/instructions.py
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
def decode_revoke(instruction: Instruction) -> models.RevokeParams:
    """Decode a revoke token transaction and retrieve the instruction params.

    Args:
        instruction: The instruction to decode.

    Returns:
        The decoded instruction.
    """
    _ = __parse_and_validate_instruction(instruction, 2, InstructionType.REVOKE)
    return models.RevokeParams(
        program_id=instruction.program_id,
        account=instruction.accounts[0].pubkey,
        owner=instruction.accounts[1].pubkey,
        signers=[signer.pubkey for signer in instruction.accounts[2:]],
    )

decode_set_authority(instruction)

Decode a set authority token transaction and retrieve the instruction params.

Parameters:

Name Type Description Default
instruction Instruction

The instruction to decode.

required

Returns:

Type Description
SetAuthorityParams

The decoded instruction.

Source code in src/spl/token/instructions.py
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
def decode_set_authority(instruction: Instruction) -> models.SetAuthorityParams:
    """Decode a set authority token transaction and retrieve the instruction params.

    Args:
        instruction: The instruction to decode.

    Returns:
        The decoded instruction.
    """
    parsed_data = __parse_and_validate_instruction(instruction, 2, InstructionType.SET_AUTHORITY)
    return models.SetAuthorityParams(
        program_id=instruction.program_id,
        account=instruction.accounts[0].pubkey,
        authority=AuthorityType(parsed_data.args.authority_type),
        new_authority=(Pubkey(parsed_data.args.new_authority) if parsed_data.args.new_authority_option else None),
        current_authority=instruction.accounts[1].pubkey,
        signers=[signer.pubkey for signer in instruction.accounts[2:]],
    )

decode_sync_native(instruction)

Decode a burn_checked token transaction and retrieve the instruction params.

Parameters:

Name Type Description Default
instruction Instruction

The instruction to decode.

required

Returns:

Type Description
SyncNativeParams

The decoded instruction.

Source code in src/spl/token/instructions.py
419
420
421
422
423
424
425
426
427
428
429
430
431
def decode_sync_native(instruction: Instruction) -> models.SyncNativeParams:
    """Decode a burn_checked token transaction and retrieve the instruction params.

    Args:
        instruction: The instruction to decode.

    Returns:
        The decoded instruction.
    """
    return models.SyncNativeParams(
        program_id=instruction.program_id,
        account=instruction.accounts[0].pubkey,
    )

decode_thaw_account(instruction)

Decode a thaw account token transaction and retrieve the instruction params.

Parameters:

Name Type Description Default
instruction Instruction

The instruction to decode.

required

Returns:

Type Description
ThawAccountParams

The decoded instruction.

Source code in src/spl/token/instructions.py
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
def decode_thaw_account(instruction: Instruction) -> models.ThawAccountParams:
    """Decode a thaw account token transaction and retrieve the instruction params.

    Args:
        instruction: The instruction to decode.

    Returns:
        The decoded instruction.
    """
    _ = __parse_and_validate_instruction(instruction, 3, InstructionType.THAW_ACCOUNT)
    return models.ThawAccountParams(
        program_id=instruction.program_id,
        account=instruction.accounts[0].pubkey,
        mint=instruction.accounts[1].pubkey,
        authority=instruction.accounts[2].pubkey,
        multi_signers=[signer.pubkey for signer in instruction.accounts[3:]],
    )

decode_transfer(instruction)

Decode a transfer token transaction and retrieve the instruction params.

Parameters:

Name Type Description Default
instruction Instruction

The instruction to decode.

required

Returns:

Type Description
TransferParams

The decoded instruction.

Source code in src/spl/token/instructions.py
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
def decode_transfer(instruction: Instruction) -> models.TransferParams:
    """Decode a transfer token transaction and retrieve the instruction params.

    Args:
        instruction: The instruction to decode.

    Returns:
        The decoded instruction.
    """
    parsed_data = __parse_and_validate_instruction(instruction, 3, InstructionType.TRANSFER)
    return models.TransferParams(
        program_id=instruction.program_id,
        source=instruction.accounts[0].pubkey,
        dest=instruction.accounts[1].pubkey,
        owner=instruction.accounts[2].pubkey,
        signers=[signer.pubkey for signer in instruction.accounts[3:]],
        amount=parsed_data.args.amount,
    )

decode_transfer_checked(instruction)

Decode a transfer_checked token transaction and retrieve the instruction params.

Parameters:

Name Type Description Default
instruction Instruction

The instruction to decode.

required

Returns:

Type Description
TransferCheckedParams

The decoded instruction.

Source code in src/spl/token/instructions.py
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
def decode_transfer_checked(instruction: Instruction) -> models.TransferCheckedParams:
    """Decode a transfer_checked token transaction and retrieve the instruction params.

    Args:
        instruction: The instruction to decode.

    Returns:
        The decoded instruction.
    """
    parsed_data = __parse_and_validate_instruction(instruction, 4, InstructionType.TRANSFER2)
    return models.TransferCheckedParams(
        program_id=instruction.program_id,
        amount=parsed_data.args.amount,
        decimals=parsed_data.args.decimals,
        source=instruction.accounts[0].pubkey,
        mint=instruction.accounts[1].pubkey,
        dest=instruction.accounts[2].pubkey,
        owner=instruction.accounts[3].pubkey,
        signers=[signer.pubkey for signer in instruction.accounts[4:]],
    )

decode_ui_amount_to_amount(instruction)

Decode a ui_amount_to_amount token transaction and retrieve the instruction params.

Source code in src/spl/token/instructions.py
546
547
548
549
550
551
552
553
554
555
556
def decode_ui_amount_to_amount(
    instruction: Instruction,
) -> models.UiAmountToAmountParams:
    """Decode a ui_amount_to_amount token transaction and retrieve the instruction params."""
    parsed_data = __parse_and_validate_instruction(instruction, 1, InstructionType.UI_AMOUNT_TO_AMOUNT)
    ui_amount_bytes: bytes = parsed_data.args.ui_amount
    return models.UiAmountToAmountParams(
        program_id=instruction.program_id,
        mint=instruction.accounts[0].pubkey,
        ui_amount=ui_amount_bytes.decode("utf-8"),
    )

decode_withdraw_withheld_tokens_from_accounts(instruction)

Decode a withdraw_withheld_tokens_from_accounts token transaction and retrieve the instruction params.

Source code in src/spl/token/instructions.py
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
def decode_withdraw_withheld_tokens_from_accounts(
    instruction: Instruction,
) -> models.WithdrawWithheldTokensFromAccountsParams:
    """Decode a withdraw_withheld_tokens_from_accounts token transaction and retrieve the instruction params."""
    parsed_data = __parse_and_validate_instruction(instruction, 3, InstructionType.TRANSFER_FEE_EXTENSION)
    if (
        parsed_data.args.transfer_fee_instruction_type
        != TransferFeeInstructionType.WITHDRAW_WITHHELD_TOKENS_FROM_ACCOUNTS
    ):
        raise ValueError("invalid transfer fee instruction type")
    num_token_accounts = parsed_data.args.args.num_token_accounts
    validate_instruction_keys(instruction, 3 + num_token_accounts)
    signers = instruction.accounts[3:-num_token_accounts] if num_token_accounts else instruction.accounts[3:]
    sources = instruction.accounts[-num_token_accounts:] if num_token_accounts else []
    return models.WithdrawWithheldTokensFromAccountsParams(
        program_id=instruction.program_id,
        mint=instruction.accounts[0].pubkey,
        dest=instruction.accounts[1].pubkey,
        authority=instruction.accounts[2].pubkey,
        signers=[signer.pubkey for signer in signers],
        sources=[source.pubkey for source in sources],
    )

decode_withdraw_withheld_tokens_from_mint(instruction)

Decode a withdraw_withheld_tokens_from_mint token transaction and retrieve the instruction params.

Source code in src/spl/token/instructions.py
504
505
506
507
508
509
510
511
512
513
514
515
516
517
def decode_withdraw_withheld_tokens_from_mint(
    instruction: Instruction,
) -> models.WithdrawWithheldTokensFromMintParams:
    """Decode a withdraw_withheld_tokens_from_mint token transaction and retrieve the instruction params."""
    parsed_data = __parse_and_validate_instruction(instruction, 3, InstructionType.TRANSFER_FEE_EXTENSION)
    if parsed_data.args.transfer_fee_instruction_type != TransferFeeInstructionType.WITHDRAW_WITHHELD_TOKENS_FROM_MINT:
        raise ValueError("invalid transfer fee instruction type")
    return models.WithdrawWithheldTokensFromMintParams(
        program_id=instruction.program_id,
        mint=instruction.accounts[0].pubkey,
        dest=instruction.accounts[1].pubkey,
        authority=instruction.accounts[2].pubkey,
        signers=[signer.pubkey for signer in instruction.accounts[3:]],
    )

freeze_account(params)

Creates a transaction instruction to freeze an initialized account using the mint's freeze_authority (if set).

Example

from spl.token.models import FreezeAccountParams leading_zeros = [0] * 31 pubkeys = [Pubkey(leading_zeros + [i + 1]) for i in range(4)] account, mint, authority, token = pubkeys params = FreezeAccountParams( ... account=account, mint=mint, authority=authority, program_id=token) type(freeze_account(params))

Returns:

Type Description
Instruction

The freeze-account instruction.

Source code in src/spl/token/instructions.py
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
def freeze_account(params: models.FreezeAccountParams) -> Instruction:
    """Creates a transaction instruction to freeze an initialized account using the mint's freeze_authority (if set).

    Example:
        >>> from spl.token.models import FreezeAccountParams
        >>> leading_zeros = [0] * 31
        >>> pubkeys = [Pubkey(leading_zeros + [i + 1]) for i in range(4)]
        >>> account, mint, authority, token = pubkeys
        >>> params = FreezeAccountParams(
        ...     account=account, mint=mint, authority=authority, program_id=token)
        >>> type(freeze_account(params))
        <class 'solders.instruction.Instruction'>

    Returns:
        The freeze-account instruction.
    """
    return __freeze_or_thaw_instruction(params, InstructionType.FREEZE_ACCOUNT)

get_account_data_size(params)

Gets the required size of an account for the given mint as a little-endian u64.

Source code in src/spl/token/instructions.py
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
def get_account_data_size(
    params: models.GetAccountDataSizeParams,
) -> Instruction:
    """Gets the required size of an account for the given mint as a little-endian u64."""
    data = INSTRUCTIONS_LAYOUT.build({"instruction_type": InstructionType.GET_ACCOUNT_DATA_SIZE, "args": None})
    return Instruction(
        accounts=[AccountMeta(pubkey=params.mint, is_signer=False, is_writable=False)],
        program_id=params.program_id,
        data=data,
    )

get_associated_token_address(owner, mint, token_program_id=TOKEN_PROGRAM_ID)

Derives the associated token address for the given wallet address and token mint.

Parameters:

Name Type Description Default
owner Pubkey

Owner's wallet address.

required
mint Pubkey

The token mint address.

required
token_program_id Pubkey

The token program ID. Must be either spl.token.constants.TOKEN_PROGRAM_ID or spl.token.constants.TOKEN_2022_PROGRAM_ID (default is TOKEN_PROGRAM_ID).

TOKEN_PROGRAM_ID

Returns:

Type Description
Pubkey

The public key of the derived associated token address.

Raises:

Type Description
ValueError

If an invalid token_program_id is provided.

Source code in src/spl/token/instructions.py
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
def get_associated_token_address(owner: Pubkey, mint: Pubkey, token_program_id: Pubkey = TOKEN_PROGRAM_ID) -> Pubkey:
    """Derives the associated token address for the given wallet address and token mint.

    Args:
        owner (Pubkey): Owner's wallet address.
        mint (Pubkey): The token mint address.
        token_program_id (Pubkey, optional): The token program ID. Must be either `spl.token.constants.TOKEN_PROGRAM_ID`
            or `spl.token.constants.TOKEN_2022_PROGRAM_ID` (default is `TOKEN_PROGRAM_ID`).

    Returns:
        The public key of the derived associated token address.

    Raises:
        ValueError: If an invalid `token_program_id` is provided.
    """
    if token_program_id not in [TOKEN_PROGRAM_ID, TOKEN_2022_PROGRAM_ID]:
        raise ValueError("token_program_id must be one of TOKEN_PROGRAM_ID or TOKEN_2022_PROGRAM_ID.")
    key, _ = Pubkey.find_program_address(
        seeds=[bytes(owner), bytes(token_program_id), bytes(mint)],
        program_id=ASSOCIATED_TOKEN_PROGRAM_ID,
    )
    return key

harvest_withheld_tokens_to_mint(params)

Harvests withheld tokens from token accounts to the mint.

Source code in src/spl/token/instructions.py
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
def harvest_withheld_tokens_to_mint(
    params: models.HarvestWithheldTokensToMintParams,
) -> Instruction:
    """Harvests withheld tokens from token accounts to the mint."""
    data = INSTRUCTIONS_LAYOUT.build(
        {
            "instruction_type": InstructionType.TRANSFER_FEE_EXTENSION,
            "args": {
                "transfer_fee_instruction_type": TransferFeeInstructionType.HARVEST_WITHHELD_TOKENS_TO_MINT,
                "args": None,
            },
        }
    )
    keys = [AccountMeta(pubkey=params.mint, is_signer=False, is_writable=True)]
    keys.extend(AccountMeta(pubkey=source, is_signer=False, is_writable=True) for source in params.sources)
    return Instruction(
        accounts=keys,
        program_id=params.program_id,
        data=data,
    )

initialize_account(params)

Creates a transaction instruction to initialize a new account to hold tokens.

This instruction requires no signers and MUST be included within the same Transaction as the system program's CreateInstruction that creates the account being initialized. Otherwise another party can acquire ownership of the uninitialized account.

Example

from spl.token.models import InitializeAccountParams leading_zeros = [0] * 31 pubkeys = [Pubkey(leading_zeros + [i + 1]) for i in range(4)] account, mint, owner, token = pubkeys params = InitializeAccountParams( ... account=account, ... mint=mint, ... owner=owner, ... program_id=token, ... ) type(initialize_account(params))

Returns:

Type Description
Instruction

The instruction to initialize the account.

Source code in src/spl/token/instructions.py
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
def initialize_account(params: models.InitializeAccountParams) -> Instruction:
    """Creates a transaction instruction to initialize a new account to hold tokens.

    This instruction requires no signers and MUST be included within the same Transaction as
    the system program's `CreateInstruction` that creates the account being initialized.
    Otherwise another party can acquire ownership of the uninitialized account.

    Example:
        >>> from spl.token.models import InitializeAccountParams
        >>> leading_zeros = [0] * 31
        >>> pubkeys = [Pubkey(leading_zeros + [i + 1]) for i in range(4)]
        >>> account, mint, owner, token = pubkeys
        >>> params = InitializeAccountParams(
        ...     account=account,
        ...     mint=mint,
        ...     owner=owner,
        ...     program_id=token,
        ... )
        >>> type(initialize_account(params))
        <class 'solders.instruction.Instruction'>

    Returns:
        The instruction to initialize the account.
    """
    data = INSTRUCTIONS_LAYOUT.build({"instruction_type": InstructionType.INITIALIZE_ACCOUNT, "args": None})
    return Instruction(
        accounts=[
            AccountMeta(pubkey=params.account, is_signer=False, is_writable=True),
            AccountMeta(pubkey=params.mint, is_signer=False, is_writable=False),
            AccountMeta(pubkey=params.owner, is_signer=False, is_writable=False),
            AccountMeta(pubkey=RENT, is_signer=False, is_writable=False),
        ],
        program_id=params.program_id,
        data=data,
    )

initialize_account2(params)

Creates a transaction instruction to initialize a new account with owner passed in data.

Source code in src/spl/token/instructions.py
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
def initialize_account2(params: models.InitializeAccount2Params) -> Instruction:
    """Creates a transaction instruction to initialize a new account with owner passed in data."""
    data = INSTRUCTIONS_LAYOUT.build(
        {
            "instruction_type": InstructionType.INITIALIZE_ACCOUNT2,
            "args": {"owner": bytes(params.owner)},
        }
    )
    return Instruction(
        accounts=[
            AccountMeta(pubkey=params.account, is_signer=False, is_writable=True),
            AccountMeta(pubkey=params.mint, is_signer=False, is_writable=False),
            AccountMeta(pubkey=RENT, is_signer=False, is_writable=False),
        ],
        program_id=params.program_id,
        data=data,
    )

initialize_account3(params)

Creates a transaction instruction to initialize a new account with owner passed in data and no Rent sysvar.

Source code in src/spl/token/instructions.py
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
def initialize_account3(params: models.InitializeAccount3Params) -> Instruction:
    """Creates a transaction instruction to initialize a new account with owner passed in data and no Rent sysvar."""
    data = INSTRUCTIONS_LAYOUT.build(
        {
            "instruction_type": InstructionType.INITIALIZE_ACCOUNT3,
            "args": {"owner": bytes(params.owner)},
        }
    )
    return Instruction(
        accounts=[
            AccountMeta(pubkey=params.account, is_signer=False, is_writable=True),
            AccountMeta(pubkey=params.mint, is_signer=False, is_writable=False),
        ],
        program_id=params.program_id,
        data=data,
    )

initialize_immutable_owner(params)

Initializes the Immutable Owner extension for a token account.

Source code in src/spl/token/instructions.py
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
def initialize_immutable_owner(
    params: models.InitializeImmutableOwnerParams,
) -> Instruction:
    """Initializes the Immutable Owner extension for a token account."""
    data = INSTRUCTIONS_LAYOUT.build({"instruction_type": InstructionType.INITIALIZE_IMMUTABLE_OWNER, "args": None})
    return Instruction(
        accounts=[AccountMeta(pubkey=params.account, is_signer=False, is_writable=True)],
        program_id=params.program_id,
        data=data,
    )

initialize_mint(params)

Creates a transaction instruction to initialize a new mint newly.

This instruction requires no signers and MUST be included within the same Transaction as the system program's CreateInstruction that creates the account being initialized. Otherwise another party can acquire ownership of the uninitialized account.

Example

from spl.token.models import InitializeMintParams from spl.token.constants import TOKEN_PROGRAM_ID from solders.pubkey import Pubkey leading_zeros = [0] * 31 pubkeys = [Pubkey(leading_zeros + [i +1]) for i in range(4)] mint_account, mint_authority, freeze_authority, owner = pubkeys params = InitializeMintParams( ... decimals=6, ... freeze_authority=freeze_authority, ... mint=mint_account, ... mint_authority=mint_authority, ... program_id=TOKEN_PROGRAM_ID, ... ) type(initialize_mint(params))

Returns:

Type Description
Instruction

The instruction to initialize the mint.

Source code in src/spl/token/instructions.py
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
def initialize_mint(params: models.InitializeMintParams) -> Instruction:
    """Creates a transaction instruction to initialize a new mint newly.

    This instruction requires no signers and MUST be included within the same Transaction as
    the system program's `CreateInstruction` that creates the account being initialized.
    Otherwise another party can acquire ownership of the uninitialized account.

    Example:
        >>> from spl.token.models import InitializeMintParams
        >>> from spl.token.constants import TOKEN_PROGRAM_ID
        >>> from solders.pubkey import Pubkey
        >>> leading_zeros = [0] * 31
        >>> pubkeys = [Pubkey(leading_zeros + [i +1]) for i in range(4)]
        >>> mint_account, mint_authority, freeze_authority, owner = pubkeys
        >>> params = InitializeMintParams(
        ...     decimals=6,
        ...     freeze_authority=freeze_authority,
        ...     mint=mint_account,
        ...     mint_authority=mint_authority,
        ...     program_id=TOKEN_PROGRAM_ID,
        ... )
        >>> type(initialize_mint(params))
        <class 'solders.instruction.Instruction'>

    Returns:
        The instruction to initialize the mint.
    """
    freeze_authority, opt = (params.freeze_authority, 1) if params.freeze_authority else (Pubkey([0] * 31 + [0]), 0)
    data = INSTRUCTIONS_LAYOUT.build(
        {
            "instruction_type": InstructionType.INITIALIZE_MINT,
            "args": {
                "decimals": params.decimals,
                "mint_authority": bytes(params.mint_authority),
                "freeze_authority_option": opt,
                "freeze_authority": bytes(freeze_authority),
            },
        }
    )
    return Instruction(
        accounts=[
            AccountMeta(pubkey=params.mint, is_signer=False, is_writable=True),
            AccountMeta(pubkey=RENT, is_signer=False, is_writable=False),
        ],
        program_id=params.program_id,
        data=data,
    )

initialize_mint2(params)

Creates a transaction instruction to initialize a new mint without providing the Rent sysvar.

Source code in src/spl/token/instructions.py
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
def initialize_mint2(params: models.InitializeMint2Params) -> Instruction:
    """Creates a transaction instruction to initialize a new mint without providing the Rent sysvar."""
    freeze_authority, opt = (params.freeze_authority, 1) if params.freeze_authority else (Pubkey([0] * 31 + [0]), 0)
    data = INSTRUCTIONS_LAYOUT.build(
        {
            "instruction_type": InstructionType.INITIALIZE_MINT2,
            "args": {
                "decimals": params.decimals,
                "mint_authority": bytes(params.mint_authority),
                "freeze_authority_option": opt,
                "freeze_authority": bytes(freeze_authority),
            },
        }
    )
    return Instruction(
        accounts=[
            AccountMeta(pubkey=params.mint, is_signer=False, is_writable=True),
        ],
        program_id=params.program_id,
        data=data,
    )

initialize_multisig(params)

Creates a transaction instruction to initialize a multisignature account with N provided signers.

This instruction requires no signers and MUST be included within the same Transaction as the system program's CreateInstruction that creates the account being initialized. Otherwise another party can acquire ownership of the uninitialized account.

Example

from spl.token.models import InitializeMultisigParams m = 2 # Two signers signers = [Pubkey([0] * 31 + [i]) for i in range(m)] leading_zeros = [0] * 31 multisig_account, token = Pubkey(leading_zeros + [1]), Pubkey(leading_zeros + [2]) params = InitializeMultisigParams( ... m=m, ... multisig=multisig_account, ... signers=signers, ... program_id=token, ... ) type(initialize_multisig(params))

Returns:

Type Description
Instruction

The instruction to initialize the multisig.

Source code in src/spl/token/instructions.py
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
def initialize_multisig(params: models.InitializeMultisigParams) -> Instruction:
    """Creates a transaction instruction to initialize a multisignature account with N provided signers.

    This instruction requires no signers and MUST be included within the same Transaction as
    the system program's `CreateInstruction` that creates the account being initialized.
    Otherwise another party can acquire ownership of the uninitialized account.

    Example:
        >>> from spl.token.models import InitializeMultisigParams
        >>> m = 2   # Two signers
        >>> signers = [Pubkey([0] * 31 + [i]) for i in range(m)]
        >>> leading_zeros = [0] * 31
        >>> multisig_account, token = Pubkey(leading_zeros + [1]), Pubkey(leading_zeros + [2])
        >>> params = InitializeMultisigParams(
        ...     m=m,
        ...     multisig=multisig_account,
        ...     signers=signers,
        ...     program_id=token,
        ... )
        >>> type(initialize_multisig(params))
        <class 'solders.instruction.Instruction'>

    Returns:
        The instruction to initialize the multisig.
    """
    data = INSTRUCTIONS_LAYOUT.build(
        {
            "instruction_type": InstructionType.INITIALIZE_MULTISIG,
            "args": {"m": params.m},
        }
    )
    keys = [
        AccountMeta(pubkey=params.multisig, is_signer=False, is_writable=True),
        AccountMeta(pubkey=RENT, is_signer=False, is_writable=False),
    ]
    for signer in params.signers:
        keys.append(AccountMeta(pubkey=signer, is_signer=False, is_writable=False))

    return Instruction(accounts=keys, program_id=params.program_id, data=data)

initialize_multisig2(params)

Creates a transaction instruction to initialize a multisignature account without providing the Rent sysvar.

Source code in src/spl/token/instructions.py
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
def initialize_multisig2(
    params: models.InitializeMultisig2Params,
) -> Instruction:
    """Creates a transaction instruction to initialize a multisignature account without providing the Rent sysvar."""
    data = INSTRUCTIONS_LAYOUT.build(
        {
            "instruction_type": InstructionType.INITIALIZE_MULTISIG2,
            "args": {"m": params.m},
        }
    )
    keys = [
        AccountMeta(pubkey=params.multisig, is_signer=False, is_writable=True),
    ]
    for signer in params.signers:
        keys.append(AccountMeta(pubkey=signer, is_signer=False, is_writable=False))
    return Instruction(accounts=keys, program_id=params.program_id, data=data)

initialize_transfer_fee_config(params)

Initializes the TransferFeeConfig extension for a mint.

Source code in src/spl/token/instructions.py
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
def initialize_transfer_fee_config(
    params: models.InitializeTransferFeeConfigParams,
) -> Instruction:
    """Initializes the TransferFeeConfig extension for a mint."""
    transfer_fee_config_authority = (
        {"option": 1, "pubkey": bytes(params.transfer_fee_config_authority)}
        if params.transfer_fee_config_authority
        else {"option": 0, "pubkey": None}
    )
    withdraw_withheld_authority = (
        {"option": 1, "pubkey": bytes(params.withdraw_withheld_authority)}
        if params.withdraw_withheld_authority
        else {"option": 0, "pubkey": None}
    )
    data = INSTRUCTIONS_LAYOUT.build(
        {
            "instruction_type": InstructionType.TRANSFER_FEE_EXTENSION,
            "args": {
                "transfer_fee_instruction_type": TransferFeeInstructionType.INITIALIZE_TRANSFER_FEE_CONFIG,
                "args": {
                    "transfer_fee_config_authority": transfer_fee_config_authority,
                    "withdraw_withheld_authority": withdraw_withheld_authority,
                    "transfer_fee_basis_points": params.transfer_fee_basis_points,
                    "maximum_fee": params.maximum_fee,
                },
            },
        }
    )
    return Instruction(
        accounts=[AccountMeta(pubkey=params.mint, is_signer=False, is_writable=True)],
        program_id=params.program_id,
        data=data,
    )

mint_to(params)

Creates a transaction instruction to mint new tokens to an account.

The native mint does not support minting.

Example

from spl.token.models import MintToParams leading_zeros = [0] * 31 pubkeys = [Pubkey(leading_zeros + [i + 1]) for i in range(4)] dest, mint, mint_authority, token = pubkeys params = MintToParams( ... amount=123, ... dest=dest, ... mint=mint, ... mint_authority=mint_authority, ... program_id=token, ... ) type(mint_to(params))

Returns:

Type Description
Instruction

The mint-to instruction.

Source code in src/spl/token/instructions.py
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
def mint_to(params: models.MintToParams) -> Instruction:
    """Creates a transaction instruction to mint new tokens to an account.

    The native mint does not support minting.

    Example:
        >>> from spl.token.models import MintToParams
        >>> leading_zeros = [0] * 31
        >>> pubkeys = [Pubkey(leading_zeros + [i + 1]) for i in range(4)]
        >>> dest, mint, mint_authority, token = pubkeys
        >>> params = MintToParams(
        ...     amount=123,
        ...     dest=dest,
        ...     mint=mint,
        ...     mint_authority=mint_authority,
        ...     program_id=token,
        ... )
        >>> type(mint_to(params))
        <class 'solders.instruction.Instruction'>

    Returns:
        The mint-to instruction.
    """
    data = INSTRUCTIONS_LAYOUT.build({"instruction_type": InstructionType.MINT_TO, "args": {"amount": params.amount}})
    return __mint_to_instruction(params, data)

mint_to_checked(params)

This instruction differs from mint_to in that the decimals value is asserted by the caller.

Example

from spl.token.models import MintToCheckedParams leading_zeros = [0] * 31 pubkeys = [Pubkey(leading_zeros + [i + 1]) for i in range(4)] dest, mint, mint_authority, token = pubkeys params = MintToCheckedParams( ... amount=123, ... decimals=6, ... dest=dest, ... mint=mint, ... mint_authority=mint_authority, ... program_id=token, ... ) type(mint_to_checked(params))

Returns:

Type Description
Instruction

The mint-to-checked instruction.

Source code in src/spl/token/instructions.py
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
def mint_to_checked(params: models.MintToCheckedParams) -> Instruction:
    """This instruction differs from `mint_to` in that the decimals value is asserted by the caller.

    Example:
        >>> from spl.token.models import MintToCheckedParams
        >>> leading_zeros = [0] * 31
        >>> pubkeys = [Pubkey(leading_zeros + [i + 1]) for i in range(4)]
        >>> dest, mint, mint_authority, token = pubkeys
        >>> params = MintToCheckedParams(
        ...     amount=123,
        ...     decimals=6,
        ...     dest=dest,
        ...     mint=mint,
        ...     mint_authority=mint_authority,
        ...     program_id=token,
        ... )
        >>> type(mint_to_checked(params))
        <class 'solders.instruction.Instruction'>

    Returns:
        The mint-to-checked instruction.
    """
    data = INSTRUCTIONS_LAYOUT.build(
        {
            "instruction_type": InstructionType.MINT_TO2,
            "args": {"amount": params.amount, "decimals": params.decimals},
        }
    )
    return __mint_to_instruction(params, data)

revoke(params)

Creates a transaction instruction that revokes delegate authority for a given account.

Example

from spl.token.models import RevokeParams leading_zeros = [0] * 31 pubkeys = [Pubkey(leading_zeros + [i + 1]) for i in range(3)] account, owner, token = pubkeys params = RevokeParams( ... account=account, owner=owner, program_id=token ... ) type(revoke(params))

Returns:

Type Description
Instruction

The revoke instruction.

Source code in src/spl/token/instructions.py
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
def revoke(params: models.RevokeParams) -> Instruction:
    """Creates a transaction instruction that revokes delegate authority for a given account.

    Example:
        >>> from spl.token.models import RevokeParams
        >>> leading_zeros = [0] * 31
        >>> pubkeys = [Pubkey(leading_zeros + [i + 1]) for i in range(3)]
        >>> account, owner, token = pubkeys
        >>> params = RevokeParams(
        ...     account=account, owner=owner, program_id=token
        ... )
        >>> type(revoke(params))
        <class 'solders.instruction.Instruction'>

    Returns:
        The revoke instruction.
    """
    data = INSTRUCTIONS_LAYOUT.build({"instruction_type": InstructionType.REVOKE, "args": None})
    keys = [AccountMeta(pubkey=params.account, is_signer=False, is_writable=True)]
    __add_signers(keys, params.owner, params.signers)

    return Instruction(accounts=keys, program_id=params.program_id, data=data)

set_authority(params)

Creates a transaction instruction to sets a new authority of a mint or account.

Example

from spl.token.models import SetAuthorityParams leading_zeros = [0] * 31 pubkeys = [Pubkey(leading_zeros + [i + 1]) for i in range(4)] account, current_authority, new_authority, token = pubkeys params = SetAuthorityParams( ... account=account, ... authority=AuthorityType.ACCOUNT_OWNER, ... current_authority=current_authority, ... new_authority=new_authority, ... program_id=token, ... ) type(set_authority(params))

Returns:

Type Description
Instruction

The set authority instruction.

Source code in src/spl/token/instructions.py
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
def set_authority(params: models.SetAuthorityParams) -> Instruction:
    """Creates a transaction instruction to sets a new authority of a mint or account.

    Example:
        >>> from spl.token.models import SetAuthorityParams
        >>> leading_zeros = [0] * 31
        >>> pubkeys = [Pubkey(leading_zeros + [i + 1]) for i in range(4)]
        >>> account, current_authority, new_authority, token = pubkeys
        >>> params = SetAuthorityParams(
        ...     account=account,
        ...     authority=AuthorityType.ACCOUNT_OWNER,
        ...     current_authority=current_authority,
        ...     new_authority=new_authority,
        ...     program_id=token,
        ... )
        >>> type(set_authority(params))
        <class 'solders.instruction.Instruction'>

    Returns:
        The set authority instruction.
    """
    new_authority, opt = (params.new_authority, 1) if params.new_authority else (Pubkey([0] * 31 + [0]), 0)
    data = INSTRUCTIONS_LAYOUT.build(
        {
            "instruction_type": InstructionType.SET_AUTHORITY,
            "args": {
                "authority_type": params.authority,
                "new_authority_option": opt,
                "new_authority": bytes(new_authority),
            },
        }
    )
    keys = [AccountMeta(pubkey=params.account, is_signer=False, is_writable=True)]
    __add_signers(keys, params.current_authority, params.signers)

    return Instruction(accounts=keys, program_id=params.program_id, data=data)

sync_native(params)

Syncs the amount field with the number of lamports of the account.

Example

from spl.token.models import SyncNativeParams account = Pubkey.default() params = SyncNativeParams( ... program_id=TOKEN_PROGRAM_ID, account=account, ... ) type(sync_native(params))

Returns:

Type Description
Instruction

The sync-native instruction.

Source code in src/spl/token/instructions.py
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
def sync_native(params: models.SyncNativeParams) -> Instruction:
    """Syncs the amount field with the number of lamports of the account.

    Example:
        >>> from spl.token.models import SyncNativeParams
        >>> account = Pubkey.default()
        >>> params = SyncNativeParams(
        ...     program_id=TOKEN_PROGRAM_ID, account=account,
        ... )
        >>> type(sync_native(params))
        <class 'solders.instruction.Instruction'>

    Returns:
        The sync-native instruction.
    """
    data = INSTRUCTIONS_LAYOUT.build(
        {
            "instruction_type": InstructionType.SYNC_NATIVE,
            "args": {},
        }
    )
    return __sync_native_instruction(params, data)

thaw_account(params)

Creates a transaction instruction to thaw a frozen account using the Mint's freeze_authority (if set).

Example

from spl.token.models import ThawAccountParams leading_zeros = [0] * 31 pubkeys = [Pubkey(leading_zeros + [i + 1]) for i in range(4)] account, mint, authority, token = pubkeys params = ThawAccountParams( ... account=account, mint=mint, authority=authority, program_id=token) type(thaw_account(params))

Returns:

Type Description
Instruction

The thaw-account instruction.

Source code in src/spl/token/instructions.py
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
def thaw_account(params: models.ThawAccountParams) -> Instruction:
    """Creates a transaction instruction to thaw a frozen account using the Mint's freeze_authority (if set).

    Example:
        >>> from spl.token.models import ThawAccountParams
        >>> leading_zeros = [0] * 31
        >>> pubkeys = [Pubkey(leading_zeros + [i + 1]) for i in range(4)]
        >>> account, mint, authority, token = pubkeys
        >>> params = ThawAccountParams(
        ...     account=account, mint=mint, authority=authority, program_id=token)
        >>> type(thaw_account(params))
        <class 'solders.instruction.Instruction'>

    Returns:
        The thaw-account instruction.
    """
    return __freeze_or_thaw_instruction(params, InstructionType.THAW_ACCOUNT)

transfer(params)

Creates a transaction instruction to transfers tokens from one account to another.

Either directly or via a delegate.

Example

from spl.token.models import TransferParams leading_zeros = [0] * 31 pubkeys = [Pubkey(leading_zeros + [i + 1]) for i in range(4)] dest, owner, source, token = pubkeys params = TransferParams( ... amount=1000, ... dest=dest, ... owner=owner, ... program_id=token, ... source=source, ... ) type(transfer(params))

Returns:

Type Description
Instruction

The transfer instruction.

Source code in src/spl/token/instructions.py
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
def transfer(params: models.TransferParams) -> Instruction:
    """Creates a transaction instruction to transfers tokens from one account to another.

    Either directly or via a delegate.

    Example:
        >>> from spl.token.models import TransferParams
        >>> leading_zeros = [0] * 31
        >>> pubkeys = [Pubkey(leading_zeros + [i + 1]) for i in range(4)]
        >>> dest, owner, source, token = pubkeys
        >>> params = TransferParams(
        ...     amount=1000,
        ...     dest=dest,
        ...     owner=owner,
        ...     program_id=token,
        ...     source=source,
        ... )
        >>> type(transfer(params))
        <class 'solders.instruction.Instruction'>

    Returns:
        The transfer instruction.
    """
    data = INSTRUCTIONS_LAYOUT.build(
        {
            "instruction_type": InstructionType.TRANSFER,
            "args": {"amount": params.amount},
        }
    )
    keys = [
        AccountMeta(pubkey=params.source, is_signer=False, is_writable=True),
        AccountMeta(pubkey=params.dest, is_signer=False, is_writable=True),
    ]
    __add_signers(keys, params.owner, params.signers)

    return Instruction(accounts=keys, program_id=params.program_id, data=data)

transfer_checked(params)

This instruction differs from transfer in that the token mint and decimals value is asserted by the caller.

Example

from spl.token.models import TransferCheckedParams leading_zeros = [0] * 31 pubkeys = [Pubkey(leading_zeros + [i + 1]) for i in range(5)] dest, mint, owner, source, token = pubkeys params = TransferCheckedParams( ... amount=1000, ... decimals=6, ... dest=dest, ... mint=mint, ... owner=owner, ... program_id=token, ... source=source, ... ) type(transfer_checked(params))

Returns:

Type Description
Instruction

The transfer-checked instruction.

Source code in src/spl/token/instructions.py
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
def transfer_checked(params: models.TransferCheckedParams) -> Instruction:
    """This instruction differs from `transfer` in that the token mint and decimals value is asserted by the caller.

    Example:
        >>> from spl.token.models import TransferCheckedParams
        >>> leading_zeros = [0] * 31
        >>> pubkeys = [Pubkey(leading_zeros + [i + 1]) for i in range(5)]
        >>> dest, mint, owner, source, token = pubkeys
        >>> params = TransferCheckedParams(
        ...     amount=1000,
        ...     decimals=6,
        ...     dest=dest,
        ...     mint=mint,
        ...     owner=owner,
        ...     program_id=token,
        ...     source=source,
        ... )
        >>> type(transfer_checked(params))
        <class 'solders.instruction.Instruction'>

    Returns:
        The transfer-checked instruction.
    """
    data = INSTRUCTIONS_LAYOUT.build(
        {
            "instruction_type": InstructionType.TRANSFER2,
            "args": {"amount": params.amount, "decimals": params.decimals},
        }
    )
    keys = [
        AccountMeta(pubkey=params.source, is_signer=False, is_writable=True),
        AccountMeta(pubkey=params.mint, is_signer=False, is_writable=False),
        AccountMeta(pubkey=params.dest, is_signer=False, is_writable=True),
    ]
    __add_signers(keys, params.owner, params.signers)

    return Instruction(accounts=keys, program_id=params.program_id, data=data)

ui_amount_to_amount(params)

Converts a UiAmount string to a raw u64 token amount using the given mint.

Source code in src/spl/token/instructions.py
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
def ui_amount_to_amount(params: models.UiAmountToAmountParams) -> Instruction:
    """Converts a UiAmount string to a raw u64 token amount using the given mint."""
    data = INSTRUCTIONS_LAYOUT.build(
        {
            "instruction_type": InstructionType.UI_AMOUNT_TO_AMOUNT,
            "args": {"ui_amount": params.ui_amount.encode("utf-8")},
        }
    )
    return Instruction(
        accounts=[AccountMeta(pubkey=params.mint, is_signer=False, is_writable=False)],
        program_id=params.program_id,
        data=data,
    )

withdraw_withheld_tokens_from_accounts(params)

Withdraws withheld tokens from token accounts to a fee receiver account.

Source code in src/spl/token/instructions.py
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
def withdraw_withheld_tokens_from_accounts(
    params: models.WithdrawWithheldTokensFromAccountsParams,
) -> Instruction:
    """Withdraws withheld tokens from token accounts to a fee receiver account."""
    data = INSTRUCTIONS_LAYOUT.build(
        {
            "instruction_type": InstructionType.TRANSFER_FEE_EXTENSION,
            "args": {
                "transfer_fee_instruction_type": TransferFeeInstructionType.WITHDRAW_WITHHELD_TOKENS_FROM_ACCOUNTS,
                "args": {"num_token_accounts": len(params.sources)},
            },
        }
    )
    keys = [
        AccountMeta(pubkey=params.mint, is_signer=False, is_writable=False),
        AccountMeta(pubkey=params.dest, is_signer=False, is_writable=True),
    ]
    __add_signers(keys, params.authority, params.signers)
    keys.extend(AccountMeta(pubkey=source, is_signer=False, is_writable=True) for source in params.sources)
    return Instruction(
        accounts=keys,
        program_id=params.program_id,
        data=data,
    )

withdraw_withheld_tokens_from_mint(params)

Withdraws withheld tokens from a mint to a fee receiver account.

Source code in src/spl/token/instructions.py
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
def withdraw_withheld_tokens_from_mint(
    params: models.WithdrawWithheldTokensFromMintParams,
) -> Instruction:
    """Withdraws withheld tokens from a mint to a fee receiver account."""
    data = INSTRUCTIONS_LAYOUT.build(
        {
            "instruction_type": InstructionType.TRANSFER_FEE_EXTENSION,
            "args": {
                "transfer_fee_instruction_type": TransferFeeInstructionType.WITHDRAW_WITHHELD_TOKENS_FROM_MINT,
                "args": None,
            },
        }
    )
    keys = [
        AccountMeta(pubkey=params.mint, is_signer=False, is_writable=True),
        AccountMeta(pubkey=params.dest, is_signer=False, is_writable=True),
    ]
    __add_signers(keys, params.authority, params.signers)
    return Instruction(
        accounts=keys,
        program_id=params.program_id,
        data=data,
    )