Skip to content

Client

spl.token.client

SPL Token program client.

Token

An ERC20-like Token.

Source code in src/spl/token/client.py
 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
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
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
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
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
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
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
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
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
851
852
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
@deprecated("Token is deprecated; use solana.rpc.async_api.AsyncClient and token instructions instead.")
class Token(_TokenCore):  # pylint: disable=too-many-public-methods
    """An ERC20-like Token."""

    def __init__(self, conn: Client, pubkey: Pubkey, program_id: Pubkey, payer: Keypair) -> None:
        """Initialize a client to a SPL-Token program."""
        warnings.warn(
            "Token is deprecated; use solana.rpc.async_api.AsyncClient and token instructions instead.",
            FutureWarning,
            stacklevel=2,
        )
        super().__init__(pubkey, program_id, payer)
        self._conn = conn

    @staticmethod
    def get_min_balance_rent_for_exempt_for_account(conn: Client) -> int:
        """Get the minimum balance for the account to be rent exempt.

        Args:
            conn: RPC connection to a solana cluster.

        Returns:
            Number of lamports required.
        """
        resp = conn.get_minimum_balance_for_rent_exemption(ACCOUNT_LAYOUT.sizeof())
        return resp.value

    @staticmethod
    def get_min_balance_rent_for_exempt_for_mint(conn: Client) -> int:
        """Get the minimum balance for the mint to be rent exempt.

        Args:
            conn: RPC connection to a solana cluster.

        Returns:
            Number of lamports required.
        """
        resp = conn.get_minimum_balance_for_rent_exemption(MINT_LAYOUT.sizeof())
        return resp.value

    @staticmethod
    def get_min_balance_rent_for_exempt_for_multisig(conn: Client) -> int:
        """Get the minimum balance for the multisig to be rent exempt.

        Args:
            conn: RPC connection to a solana cluster.

        Return: Number of lamports required.
        """
        resp = conn.get_minimum_balance_for_rent_exemption(MULTISIG_LAYOUT.sizeof())
        return resp.value

    def get_accounts_by_owner(
        self,
        owner: Pubkey,
        commitment: Optional[Commitment] = None,
        encoding: str = "base64",
    ) -> GetTokenAccountsByOwnerResp:
        """Get token accounts of the provided owner.

        Args:
            owner: Public Key of the token account owner.
            commitment: (optional) Bank state to query.
            encoding: (optional) Encoding for Account data, either "base58" (slow) or "base64".
        """
        args = self._get_accounts_args(
            owner,
            commitment,
            encoding,
            self._conn.commitment,  # pylint: disable=protected-access
        )
        return self._conn.get_token_accounts_by_owner(*args)

    def get_accounts_by_owner_json_parsed(
        self,
        owner: Pubkey,
        commitment: Optional[Commitment] = None,
    ) -> GetTokenAccountsByOwnerJsonParsedResp:
        """Get token accounts of the provided owner by the token's mint, in JSON format.

        Args:
            owner: Public Key of the token account owner.
            commitment: (optional) Bank state to query.


        Parsed-JSON encoding attempts to use program-specific state parsers to return more
        human-readable and explicit account state data. If parsed-JSON is requested but a
        valid mint cannot be found for a particular account, that account will be filtered out
        from results. jsonParsed encoding is UNSTABLE.
        """
        args = self._get_accounts_args(
            owner,
            commitment,
            "jsonParsed",
            self._conn.commitment,  # pylint: disable=protected-access
        )
        return self._conn.get_token_accounts_by_owner_json_parsed(*args)

    def get_accounts_by_delegate(
        self,
        owner: Pubkey,
        commitment: Optional[Commitment] = None,
        encoding: str = "base64",
    ) -> GetTokenAccountsByDelegateResp:
        """Get token accounts of the provided delegate.

        Args:
            owner: Public Key of the delegate account.
            commitment: (optional) Bank state to query.
            encoding: (optional) Encoding for Account data, either "base58" (slow) or "base64".
        """
        args = self._get_accounts_args(
            owner,
            commitment,
            encoding,
            self._conn.commitment,  # pylint: disable=protected-access
        )
        return self._conn.get_token_accounts_by_delegate(*args)

    def get_accounts_by_delegate_json_parsed(
        self,
        owner: Pubkey,
        commitment: Optional[Commitment] = None,
        encoding: str = "base64",
    ) -> GetTokenAccountsByDelegateJsonParsedResp:
        """Get token accounts of the provided delegate, in JSON format.

        Args:
            owner: Public Key of the delegate account.
            commitment: (optional) Bank state to query.
            encoding: (optional) Encoding for Account data, either "base58" (slow) or "base64".

        Parsed-JSON encoding attempts to use program-specific state parsers to return more
        human-readable and explicit account state data. If parsed-JSON is requested but a
        valid mint cannot be found for a particular account, that account will be filtered out
        from results. jsonParsed encoding is UNSTABLE.
        """
        args = self._get_accounts_args(
            owner,
            commitment,
            encoding,
            self._conn.commitment,  # pylint: disable=protected-access
        )
        return self._conn.get_token_accounts_by_delegate_json_parsed(*args)

    def get_balance(self, pubkey: Pubkey, commitment: Optional[Commitment] = None) -> GetTokenAccountBalanceResp:
        """Get the balance of the provided token account.

        Args:
            pubkey: Public Key of the token account.
            commitment: (optional) Bank state to query.
        """
        return self._conn.get_token_account_balance(pubkey, commitment)

    @classmethod
    def create_mint(
        cls,
        conn: Client,
        payer: Keypair,
        mint_authority: Pubkey,
        decimals: int,
        program_id: Pubkey,
        freeze_authority: Optional[Pubkey] = None,
        skip_confirmation: bool = False,
        recent_blockhash: Optional[Blockhash] = None,
    ) -> Token:
        """Create and initialize a token.

        Args:
            conn: RPC connection to a solana cluster.
            payer: Fee payer for transaction.
            mint_authority: Account or multisig that will control minting.
            decimals: Location of the decimal place.
            program_id: SPL Token program account.
            freeze_authority: (optional) Account or multisig that can freeze token accounts.
            skip_confirmation: (optional) Option to skip transaction confirmation.
            recent_blockhash: (optional) a prefetched Blockhash for the transaction.

        Returns:
            Token object for the newly minted token.

        If skip confirmation is set to `False`, this method will block for at most 30 seconds
        or until the transaction is confirmed.
        """
        # Allocate memory for the account
        balance_needed = Token.get_min_balance_rent_for_exempt_for_mint(conn)
        # Construct transaction
        recent_blockhash_to_use = (
            conn.get_latest_blockhash().value.blockhash if recent_blockhash is None else recent_blockhash
        )
        token, txn, opts = _TokenCore._create_mint_args(
            conn,
            payer,
            mint_authority,
            decimals,
            program_id,
            freeze_authority,
            skip_confirmation,
            balance_needed,
            cls,
            conn.commitment,
            recent_blockhash_to_use,
        )
        # Send the two instructions
        conn.send_transaction(txn, opts=opts)
        return cast(Token, token)

    def create_account(
        self,
        owner: Pubkey,
        skip_confirmation: bool = False,
        recent_blockhash: Optional[Blockhash] = None,
    ) -> Pubkey:
        """Create and initialize a new account.

        This account may then be used as a `transfer()` or `approve()` destination.

        Args:
            owner: User account that will own the new account.
            skip_confirmation: (optional) Option to skip transaction confirmation.
            recent_blockhash: (optional) a prefetched Blockhash for the transaction.

        Returns:
            Public key of the new empty account.

        If skip confirmation is set to `False`, this method will block for at most 30 seconds
        or until the transaction is confirmed.
        """
        balance_needed = Token.get_min_balance_rent_for_exempt_for_account(self._conn)
        recent_blockhash_to_use = (
            self._conn.get_latest_blockhash().value.blockhash if recent_blockhash is None else recent_blockhash
        )
        new_account_pk, txn, opts = self._create_account_args(
            owner,
            skip_confirmation,
            balance_needed,
            self._conn.commitment,
            recent_blockhash_to_use,
        )
        # Send the two instructions
        self._conn.send_transaction(txn, opts=opts)
        return new_account_pk

    def create_associated_token_account(
        self,
        owner: Pubkey,
        skip_confirmation: bool = False,
        recent_blockhash: Optional[Blockhash] = None,
    ) -> Pubkey:
        """Create an associated token account.

        Args:
            owner: User account that will own the associated token account.
            skip_confirmation: (optional) Option to skip transaction confirmation.
            recent_blockhash: (optional) a prefetched Blockhash for the transaction.

        Returns:
            Public key of the new associated account.

        If skip confirmation is set to `False`, this method will block for at most 30 seconds
        or until the transaction is confirmed.
        """
        # Construct transaction
        recent_blockhash_to_use = (
            self._conn.get_latest_blockhash().value.blockhash if recent_blockhash is None else recent_blockhash
        )
        public_key, txn, _payer, opts = self._create_associated_token_account_args(
            owner,
            skip_confirmation,
            self._conn.commitment,
            recent_blockhash_to_use,
            token_program_id=self.program_id,
        )
        self._conn.send_transaction(txn, opts=opts)
        return public_key

    @staticmethod
    def create_wrapped_native_account(
        conn: Client,
        program_id: Pubkey,
        owner: Pubkey,
        payer: Keypair,
        amount: int,
        skip_confirmation: bool = False,
        recent_blockhash: Optional[Blockhash] = None,
    ) -> Pubkey:
        """Create and initialize a new account on the special native token mint.

        Args:
            conn: RPC connection to a solana cluster.
            program_id: SPL Token program account.
            owner: The owner of the new token account.
            payer: The source of the lamports to initialize, and payer of the initialization fees.
            amount: The amount of lamports to wrap.
            skip_confirmation: (optional) Option to skip transaction confirmation.
            recent_blockhash: (optional) a prefetched Blockhash for the transaction.

        Returns:
            The new token account.

        If skip confirmation is set to `False`, this method will block for at most 30 seconds
        or until the transaction is confirmed.
        """
        # Allocate memory for the account
        balance_needed = Token.get_min_balance_rent_for_exempt_for_account(conn)
        recent_blockhash_to_use = (
            conn.get_latest_blockhash().value.blockhash if recent_blockhash is None else recent_blockhash
        )
        (
            new_account_public_key,
            txn,
            payer,
            _new_account,
            opts,
        ) = _TokenCore._create_wrapped_native_account_args(
            program_id,
            owner,
            payer,
            amount,
            skip_confirmation,
            balance_needed,
            conn.commitment,
            recent_blockhash_to_use,
        )
        conn.send_transaction(txn, opts=opts)
        return new_account_public_key

    def create_multisig(
        self,
        m: int,
        multi_signers: List[Pubkey],
        opts: Optional[Union[types.TxOpts, TxOptsModel]] = None,
        recent_blockhash: Optional[Blockhash] = None,
    ) -> Pubkey:  # pylint: disable=invalid-name
        """Create and initialize a new multisig.

        Args:
            m: Number of required signatures.
            multi_signers: Full set of signers.
            opts: (optional) Transaction options.
            recent_blockhash: (optional) a prefetched Blockhash for the transaction.

        Returns:
            Public key of the new multisig account.
        """
        balance_needed = Token.get_min_balance_rent_for_exempt_for_multisig(self._conn)
        recent_blockhash_to_use = (
            self._conn.get_latest_blockhash().value.blockhash if recent_blockhash is None else recent_blockhash
        )
        txn, multisig = self._create_multisig_args(m, multi_signers, balance_needed, recent_blockhash_to_use)
        opts_to_use = (
            TxOptsModel(preflight_commitment=self._conn.commitment)
            if opts is None
            else TxOptsModel.from_namedtuple(opts)
        )
        self._conn.send_transaction(txn, opts=opts_to_use)
        return multisig.pubkey()

    def get_mint_info(self) -> MintInfo:
        """Retrieve mint information."""
        info = self._conn.get_account_info(self.pubkey)
        return self._create_mint_info(info)

    def get_account_info(self, account: Pubkey, commitment: Optional[Commitment] = None) -> AccountInfo:
        """Retrieve account information."""
        info = self._conn.get_account_info(account, commitment)
        return self._create_account_info(info)

    def transfer(
        self,
        source: Pubkey,
        dest: Pubkey,
        owner: Union[Keypair, Pubkey],
        amount: int,
        multi_signers: Optional[List[Keypair]] = None,
        opts: Optional[Union[types.TxOpts, TxOptsModel]] = None,
        recent_blockhash: Optional[Blockhash] = None,
    ) -> SendTransactionResp:
        """Transfer tokens to another account.

        Args:
            source: Public key of account to transfer tokens from.
            dest: Public key of account to transfer tokens to.
            owner: Owner of the source account.
            amount: Number of tokens to transfer.
            multi_signers: (optional) Signing accounts if `owner` is a multiSig.
            opts: (optional) Transaction options.
            recent_blockhash: (optional) a prefetched Blockhash for the transaction.
        """
        opts_to_use = (
            TxOptsModel(preflight_commitment=self._conn.commitment)
            if opts is None
            else TxOptsModel.from_namedtuple(opts)
        )
        recent_blockhash_to_use = (
            self._conn.get_latest_blockhash().value.blockhash if recent_blockhash is None else recent_blockhash
        )
        txn, opts = self._transfer_args(
            source,
            dest,
            owner,
            amount,
            multi_signers,
            opts_to_use,
            recent_blockhash_to_use,
        )
        return self._conn.send_transaction(txn, opts=opts)

    def approve(
        self,
        source: Pubkey,
        delegate: Pubkey,
        owner: Pubkey,
        amount: int,
        multi_signers: Optional[List[Keypair]] = None,
        opts: Optional[Union[types.TxOpts, TxOptsModel]] = None,
        recent_blockhash: Optional[Blockhash] = None,
    ) -> SendTransactionResp:
        """Grant a third-party permission to transfer up the specified number of tokens from an account.

        Args:
            source: Public key of the source account.
            delegate: Account authorized to perform a transfer tokens from the source account.
            owner: Owner of the source account.
            amount: Maximum number of tokens the delegate may transfer.
            multi_signers: (optional) Signing accounts if `owner` is a multiSig.
            opts: (optional) Transaction options.
            recent_blockhash: (optional) a prefetched Blockhash for the transaction.
        """
        opts_to_use = (
            TxOptsModel(preflight_commitment=self._conn.commitment)
            if opts is None
            else TxOptsModel.from_namedtuple(opts)
        )
        recent_blockhash_to_use = (
            self._conn.get_latest_blockhash().value.blockhash if recent_blockhash is None else recent_blockhash
        )
        txn, _payer, _signers, opts = self._approve_args(
            source,
            delegate,
            owner,
            amount,
            multi_signers,
            opts_to_use,
            recent_blockhash_to_use,
        )
        return self._conn.send_transaction(txn, opts=opts)

    def revoke(
        self,
        account: Pubkey,
        owner: Pubkey,
        multi_signers: Optional[List[Keypair]] = None,
        opts: Optional[Union[types.TxOpts, TxOptsModel]] = None,
        recent_blockhash: Optional[Blockhash] = None,
    ) -> SendTransactionResp:
        """Revoke transfer authority for a given account.

        Args:
            account: Source account for which transfer authority is being revoked.
            owner: Owner of the source account.
            multi_signers: (optional) Signing accounts if `owner` is a multiSig.
            opts: (optional) Transaction options.
            recent_blockhash: (optional) a prefetched Blockhash for the transaction.
        """
        opts_to_use = (
            TxOptsModel(preflight_commitment=self._conn.commitment)
            if opts is None
            else TxOptsModel.from_namedtuple(opts)
        )
        recent_blockhash_to_use = (
            self._conn.get_latest_blockhash().value.blockhash if recent_blockhash is None else recent_blockhash
        )
        txn, _payer, _signers, opts = self._revoke_args(
            account, owner, multi_signers, opts_to_use, recent_blockhash_to_use
        )
        return self._conn.send_transaction(txn, opts=opts)

    def set_authority(
        self,
        account: Pubkey,
        current_authority: Union[Keypair, Pubkey],
        authority_type: spl_token.AuthorityType,
        new_authority: Optional[Pubkey] = None,
        multi_signers: Optional[List[Keypair]] = None,
        opts: Optional[Union[types.TxOpts, TxOptsModel]] = None,
        recent_blockhash: Optional[Blockhash] = None,
    ) -> SendTransactionResp:
        """Assign a new authority to the account.

        Args:
            account: Public key of the token account.
            current_authority: Current authority of the account.
            authority_type: Type of authority to set.
            new_authority: (optional) New authority of the account.
            multi_signers: (optional) Signing accounts if `owner` is a multiSig.
            opts: (optional) Transaction options.
            recent_blockhash: (optional) a prefetched Blockhash for the transaction.
        """
        opts_to_use = (
            TxOptsModel(preflight_commitment=self._conn.commitment)
            if opts is None
            else TxOptsModel.from_namedtuple(opts)
        )
        recent_blockhash_to_use = (
            self._conn.get_latest_blockhash().value.blockhash if recent_blockhash is None else recent_blockhash
        )
        txn, _payer, _signers, opts = self._set_authority_args(
            account,
            current_authority,
            authority_type,
            new_authority,
            multi_signers,
            opts_to_use,
            recent_blockhash_to_use,
        )
        return self._conn.send_transaction(txn, opts=opts)

    def mint_to(
        self,
        dest: Pubkey,
        mint_authority: Union[Keypair, Pubkey],
        amount: int,
        multi_signers: Optional[List[Keypair]] = None,
        opts: Optional[Union[types.TxOpts, TxOptsModel]] = None,
        recent_blockhash: Optional[Blockhash] = None,
    ) -> SendTransactionResp:
        """Mint new tokens.

        Args:
            dest: Public key of the account to mint to.
            mint_authority: Public key of the minting authority.
            amount: Amount to mint.
            multi_signers: (optional) Signing accounts if `owner` is a multiSig.
            opts: (optional) Transaction options.
            recent_blockhash: (optional) a prefetched Blockhash for the transaction.

        If skip confirmation is set to `False`, this method will block for at most 30 seconds
        or until the transaction is confirmed.
        """
        opts_to_use = (
            TxOptsModel(preflight_commitment=self._conn.commitment)
            if opts is None
            else TxOptsModel.from_namedtuple(opts)
        )
        recent_blockhash_to_use = (
            self._conn.get_latest_blockhash().value.blockhash if recent_blockhash is None else recent_blockhash
        )
        txn, opts = self._mint_to_args(
            dest,
            mint_authority,
            amount,
            multi_signers,
            opts_to_use,
            recent_blockhash_to_use,
        )
        return self._conn.send_transaction(txn, opts=opts)

    def burn(
        self,
        account: Pubkey,
        owner: Pubkey,
        amount: int,
        multi_signers: Optional[List[Keypair]] = None,
        opts: Optional[Union[types.TxOpts, TxOptsModel]] = None,
        recent_blockhash: Optional[Blockhash] = None,
    ) -> SendTransactionResp:
        """Burn tokens.

        Args:
            account: Account to burn tokens from.
            owner: Owner of the account.
            amount: Amount to burn.
            multi_signers: (optional) Signing accounts if `owner` is a multiSig.
            opts: (optional) Transaction options.
            recent_blockhash: (optional) a prefetched Blockhash for the transaction.
        """
        opts_to_use = (
            TxOptsModel(preflight_commitment=self._conn.commitment)
            if opts is None
            else TxOptsModel.from_namedtuple(opts)
        )
        recent_blockhash_to_use = (
            self._conn.get_latest_blockhash().value.blockhash if recent_blockhash is None else recent_blockhash
        )
        txn, opts = self._burn_args(account, owner, amount, multi_signers, opts_to_use, recent_blockhash_to_use)
        return self._conn.send_transaction(txn, opts=opts)

    def close_account(
        self,
        account: Pubkey,
        dest: Pubkey,
        authority: Union[Keypair, Pubkey],
        multi_signers: Optional[List[Keypair]] = None,
        opts: Optional[Union[types.TxOpts, TxOptsModel]] = None,
        recent_blockhash: Optional[Blockhash] = None,
    ) -> SendTransactionResp:
        """Remove approval for the transfer of any remaining tokens.

        Args:
            account: Account to close.
            dest: Account to receive the remaining balance of the closed account.
            authority: Authority which is allowed to close the account.
            multi_signers: (optional) Signing accounts if `owner` is a multiSig.
            opts: (optional) Transaction options.
            recent_blockhash: (optional) a prefetched Blockhash for the transaction.
        """
        opts_to_use = (
            TxOptsModel(preflight_commitment=self._conn.commitment)
            if opts is None
            else TxOptsModel.from_namedtuple(opts)
        )
        recent_blockhash_to_use = (
            self._conn.get_latest_blockhash().value.blockhash if recent_blockhash is None else recent_blockhash
        )
        txn, opts = self._close_account_args(
            account,
            dest,
            authority,
            multi_signers,
            opts_to_use,
            recent_blockhash_to_use,
        )
        return self._conn.send_transaction(txn, opts=opts)

    def freeze_account(
        self,
        account: Pubkey,
        authority: Union[Pubkey, Keypair],
        multi_signers: Optional[List[Keypair]] = None,
        opts: Optional[Union[types.TxOpts, TxOptsModel]] = None,
        recent_blockhash: Optional[Blockhash] = None,
    ) -> SendTransactionResp:
        """Freeze account.

        Args:
            account: Account to freeze.
            authority: The mint freeze authority.
            multi_signers: (optional) Signing accounts if `authority` is a multiSig.
            opts: (optional) Transaction options.
            recent_blockhash: (optional) a prefetched Blockhash for the transaction.
        """
        opts_to_use = (
            TxOptsModel(preflight_commitment=self._conn.commitment)
            if opts is None
            else TxOptsModel.from_namedtuple(opts)
        )
        recent_blockhash_to_use = (
            self._conn.get_latest_blockhash().value.blockhash if recent_blockhash is None else recent_blockhash
        )
        txn, opts = self._freeze_account_args(account, authority, multi_signers, opts_to_use, recent_blockhash_to_use)
        return self._conn.send_transaction(txn, opts=opts)

    def thaw_account(
        self,
        account: Pubkey,
        authority: Pubkey,
        multi_signers: Optional[List[Keypair]] = None,
        opts: Optional[Union[types.TxOpts, TxOptsModel]] = None,
        recent_blockhash: Optional[Blockhash] = None,
    ) -> SendTransactionResp:
        """Thaw account.

        Args:
            account: Account to thaw.
            authority: The mint freeze authority.
            multi_signers: (optional) Signing accounts if `authority` is a multiSig.
            opts: (optional) Transaction options.
            recent_blockhash: (optional) a prefetched Blockhash for the transaction.
        """
        opts_to_use = (
            TxOptsModel(preflight_commitment=self._conn.commitment)
            if opts is None
            else TxOptsModel.from_namedtuple(opts)
        )
        recent_blockhash_to_use = (
            self._conn.get_latest_blockhash().value.blockhash if recent_blockhash is None else recent_blockhash
        )
        txn, opts = self._thaw_account_args(account, authority, multi_signers, opts_to_use, recent_blockhash_to_use)
        return self._conn.send_transaction(txn, opts=opts)

    def transfer_checked(
        self,
        source: Pubkey,
        dest: Pubkey,
        owner: Union[Keypair, Pubkey],
        amount: int,
        decimals: int,
        multi_signers: Optional[List[Keypair]] = None,
        opts: Optional[Union[types.TxOpts, TxOptsModel]] = None,
        recent_blockhash: Optional[Blockhash] = None,
    ) -> SendTransactionResp:
        """Transfer tokens to another account, asserting the token mint and decimals.

        Args:
            source: Public key of account to transfer tokens from.
            dest: Public key of account to transfer tokens to.
            owner: Owner of the source account.
            amount: Number of tokens to transfer.
            decimals: Number of decimals in transfer amount.
            multi_signers: (optional) Signing accounts if `owner` is a multiSig.
            opts: (optional) Transaction options.
            recent_blockhash: (optional) a prefetched Blockhash for the transaction.
        """
        opts_to_use = (
            TxOptsModel(preflight_commitment=self._conn.commitment)
            if opts is None
            else TxOptsModel.from_namedtuple(opts)
        )
        recent_blockhash_to_use = (
            self._conn.get_latest_blockhash().value.blockhash if recent_blockhash is None else recent_blockhash
        )
        txn, opts = self._transfer_checked_args(
            source,
            dest,
            owner,
            amount,
            decimals,
            multi_signers,
            opts_to_use,
            recent_blockhash_to_use,
        )
        return self._conn.send_transaction(txn, opts=opts)

    def approve_checked(
        self,
        source: Pubkey,
        delegate: Pubkey,
        owner: Pubkey,
        amount: int,
        decimals: int,
        multi_signers: Optional[List[Keypair]] = None,
        opts: Optional[Union[types.TxOpts, TxOptsModel]] = None,
        recent_blockhash: Optional[Blockhash] = None,
    ) -> SendTransactionResp:
        """Grant a third-party permission to transfer up the specified number of tokens from an account.

        This method also asserts the token mint and decimals.

        Args:
            source: Public key of the source account.
            delegate: Account authorized to perform a transfer tokens from the source account.
            owner: Owner of the source account.
            amount: Maximum number of tokens the delegate may transfer.
            decimals: Number of decimals in approve amount.
            multi_signers: (optional) Signing accounts if `owner` is a multiSig.
            opts: (optional) Transaction options.
            recent_blockhash: (optional) a prefetched Blockhash for the transaction.
        """
        opts_to_use = (
            TxOptsModel(preflight_commitment=self._conn.commitment)
            if opts is None
            else TxOptsModel.from_namedtuple(opts)
        )
        recent_blockhash_to_use = (
            self._conn.get_latest_blockhash().value.blockhash if recent_blockhash is None else recent_blockhash
        )
        txn, opts = self._approve_checked_args(
            source,
            delegate,
            owner,
            amount,
            decimals,
            multi_signers,
            opts_to_use,
            recent_blockhash_to_use,
        )
        return self._conn.send_transaction(txn, opts=opts)

    def mint_to_checked(
        self,
        dest: Pubkey,
        mint_authority: Union[Keypair, Pubkey],
        amount: int,
        decimals: int,
        multi_signers: Optional[List[Keypair]] = None,
        opts: Optional[Union[types.TxOpts, TxOptsModel]] = None,
        recent_blockhash: Optional[Blockhash] = None,
    ) -> SendTransactionResp:
        """Mint new tokens, asserting the token mint and decimals.

        Args:
            dest: Public key of the account to mint to.
            mint_authority: Public key of the minting authority.
            amount: Amount to mint.
            decimals: Number of decimals in amount to mint.
            multi_signers: (optional) Signing accounts if `owner` is a multiSig.
            opts: (optional) Transaction options.
            recent_blockhash: (optional) a prefetched Blockhash for the transaction.
        """
        opts_to_use = (
            TxOptsModel(preflight_commitment=self._conn.commitment)
            if opts is None
            else TxOptsModel.from_namedtuple(opts)
        )
        recent_blockhash_to_use = (
            self._conn.get_latest_blockhash().value.blockhash if recent_blockhash is None else recent_blockhash
        )
        txn, opts = self._mint_to_checked_args(
            dest,
            mint_authority,
            amount,
            decimals,
            multi_signers,
            opts_to_use,
            recent_blockhash_to_use,
        )
        return self._conn.send_transaction(txn, opts=opts)

    def burn_checked(
        self,
        account: Pubkey,
        owner: Union[Keypair, Pubkey],
        amount: int,
        decimals: int,
        multi_signers: Optional[List[Keypair]] = None,
        opts: Optional[Union[types.TxOpts, TxOptsModel]] = None,
        recent_blockhash: Optional[Blockhash] = None,
    ) -> SendTransactionResp:
        """Burn tokens, asserting the token mint and decimals.

        Args:
            account: Account to burn tokens from.
            owner: Owner of the account.
            amount: Amount to burn.
            decimals: Number of decimals in amount to burn.
            multi_signers: (optional) Signing accounts if `owner` is a multiSig.
            opts: (optional) Transaction options.
            recent_blockhash: (optional) a prefetched Blockhash for the transaction.
        """
        opts_to_use = (
            TxOptsModel(preflight_commitment=self._conn.commitment)
            if opts is None
            else TxOptsModel.from_namedtuple(opts)
        )
        recent_blockhash_to_use = (
            self._conn.get_latest_blockhash().value.blockhash if recent_blockhash is None else recent_blockhash
        )
        txn, opts = self._burn_checked_args(
            account,
            owner,
            amount,
            decimals,
            multi_signers,
            opts_to_use,
            recent_blockhash_to_use,
        )
        return self._conn.send_transaction(txn, opts=opts)

__init__(conn, pubkey, program_id, payer)

Initialize a client to a SPL-Token program.

Source code in src/spl/token/client.py
36
37
38
39
40
41
42
43
44
def __init__(self, conn: Client, pubkey: Pubkey, program_id: Pubkey, payer: Keypair) -> None:
    """Initialize a client to a SPL-Token program."""
    warnings.warn(
        "Token is deprecated; use solana.rpc.async_api.AsyncClient and token instructions instead.",
        FutureWarning,
        stacklevel=2,
    )
    super().__init__(pubkey, program_id, payer)
    self._conn = conn

approve(source, delegate, owner, amount, multi_signers=None, opts=None, recent_blockhash=None)

Grant a third-party permission to transfer up the specified number of tokens from an account.

Parameters:

Name Type Description Default
source Pubkey

Public key of the source account.

required
delegate Pubkey

Account authorized to perform a transfer tokens from the source account.

required
owner Pubkey

Owner of the source account.

required
amount int

Maximum number of tokens the delegate may transfer.

required
multi_signers Optional[List[Keypair]]

(optional) Signing accounts if owner is a multiSig.

None
opts Optional[Union[TxOpts, TxOpts]]

(optional) Transaction options.

None
recent_blockhash Optional[Hash]

(optional) a prefetched Blockhash for the transaction.

None
Source code in src/spl/token/client.py
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
def approve(
    self,
    source: Pubkey,
    delegate: Pubkey,
    owner: Pubkey,
    amount: int,
    multi_signers: Optional[List[Keypair]] = None,
    opts: Optional[Union[types.TxOpts, TxOptsModel]] = None,
    recent_blockhash: Optional[Blockhash] = None,
) -> SendTransactionResp:
    """Grant a third-party permission to transfer up the specified number of tokens from an account.

    Args:
        source: Public key of the source account.
        delegate: Account authorized to perform a transfer tokens from the source account.
        owner: Owner of the source account.
        amount: Maximum number of tokens the delegate may transfer.
        multi_signers: (optional) Signing accounts if `owner` is a multiSig.
        opts: (optional) Transaction options.
        recent_blockhash: (optional) a prefetched Blockhash for the transaction.
    """
    opts_to_use = (
        TxOptsModel(preflight_commitment=self._conn.commitment)
        if opts is None
        else TxOptsModel.from_namedtuple(opts)
    )
    recent_blockhash_to_use = (
        self._conn.get_latest_blockhash().value.blockhash if recent_blockhash is None else recent_blockhash
    )
    txn, _payer, _signers, opts = self._approve_args(
        source,
        delegate,
        owner,
        amount,
        multi_signers,
        opts_to_use,
        recent_blockhash_to_use,
    )
    return self._conn.send_transaction(txn, opts=opts)

approve_checked(source, delegate, owner, amount, decimals, multi_signers=None, opts=None, recent_blockhash=None)

Grant a third-party permission to transfer up the specified number of tokens from an account.

This method also asserts the token mint and decimals.

Parameters:

Name Type Description Default
source Pubkey

Public key of the source account.

required
delegate Pubkey

Account authorized to perform a transfer tokens from the source account.

required
owner Pubkey

Owner of the source account.

required
amount int

Maximum number of tokens the delegate may transfer.

required
decimals int

Number of decimals in approve amount.

required
multi_signers Optional[List[Keypair]]

(optional) Signing accounts if owner is a multiSig.

None
opts Optional[Union[TxOpts, TxOpts]]

(optional) Transaction options.

None
recent_blockhash Optional[Hash]

(optional) a prefetched Blockhash for the transaction.

None
Source code in src/spl/token/client.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
795
796
797
798
799
def approve_checked(
    self,
    source: Pubkey,
    delegate: Pubkey,
    owner: Pubkey,
    amount: int,
    decimals: int,
    multi_signers: Optional[List[Keypair]] = None,
    opts: Optional[Union[types.TxOpts, TxOptsModel]] = None,
    recent_blockhash: Optional[Blockhash] = None,
) -> SendTransactionResp:
    """Grant a third-party permission to transfer up the specified number of tokens from an account.

    This method also asserts the token mint and decimals.

    Args:
        source: Public key of the source account.
        delegate: Account authorized to perform a transfer tokens from the source account.
        owner: Owner of the source account.
        amount: Maximum number of tokens the delegate may transfer.
        decimals: Number of decimals in approve amount.
        multi_signers: (optional) Signing accounts if `owner` is a multiSig.
        opts: (optional) Transaction options.
        recent_blockhash: (optional) a prefetched Blockhash for the transaction.
    """
    opts_to_use = (
        TxOptsModel(preflight_commitment=self._conn.commitment)
        if opts is None
        else TxOptsModel.from_namedtuple(opts)
    )
    recent_blockhash_to_use = (
        self._conn.get_latest_blockhash().value.blockhash if recent_blockhash is None else recent_blockhash
    )
    txn, opts = self._approve_checked_args(
        source,
        delegate,
        owner,
        amount,
        decimals,
        multi_signers,
        opts_to_use,
        recent_blockhash_to_use,
    )
    return self._conn.send_transaction(txn, opts=opts)

burn(account, owner, amount, multi_signers=None, opts=None, recent_blockhash=None)

Burn tokens.

Parameters:

Name Type Description Default
account Pubkey

Account to burn tokens from.

required
owner Pubkey

Owner of the account.

required
amount int

Amount to burn.

required
multi_signers Optional[List[Keypair]]

(optional) Signing accounts if owner is a multiSig.

None
opts Optional[Union[TxOpts, TxOpts]]

(optional) Transaction options.

None
recent_blockhash Optional[Hash]

(optional) a prefetched Blockhash for the transaction.

None
Source code in src/spl/token/client.py
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
def burn(
    self,
    account: Pubkey,
    owner: Pubkey,
    amount: int,
    multi_signers: Optional[List[Keypair]] = None,
    opts: Optional[Union[types.TxOpts, TxOptsModel]] = None,
    recent_blockhash: Optional[Blockhash] = None,
) -> SendTransactionResp:
    """Burn tokens.

    Args:
        account: Account to burn tokens from.
        owner: Owner of the account.
        amount: Amount to burn.
        multi_signers: (optional) Signing accounts if `owner` is a multiSig.
        opts: (optional) Transaction options.
        recent_blockhash: (optional) a prefetched Blockhash for the transaction.
    """
    opts_to_use = (
        TxOptsModel(preflight_commitment=self._conn.commitment)
        if opts is None
        else TxOptsModel.from_namedtuple(opts)
    )
    recent_blockhash_to_use = (
        self._conn.get_latest_blockhash().value.blockhash if recent_blockhash is None else recent_blockhash
    )
    txn, opts = self._burn_args(account, owner, amount, multi_signers, opts_to_use, recent_blockhash_to_use)
    return self._conn.send_transaction(txn, opts=opts)

burn_checked(account, owner, amount, decimals, multi_signers=None, opts=None, recent_blockhash=None)

Burn tokens, asserting the token mint and decimals.

Parameters:

Name Type Description Default
account Pubkey

Account to burn tokens from.

required
owner Union[Keypair, Pubkey]

Owner of the account.

required
amount int

Amount to burn.

required
decimals int

Number of decimals in amount to burn.

required
multi_signers Optional[List[Keypair]]

(optional) Signing accounts if owner is a multiSig.

None
opts Optional[Union[TxOpts, TxOpts]]

(optional) Transaction options.

None
recent_blockhash Optional[Hash]

(optional) a prefetched Blockhash for the transaction.

None
Source code in src/spl/token/client.py
841
842
843
844
845
846
847
848
849
850
851
852
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
def burn_checked(
    self,
    account: Pubkey,
    owner: Union[Keypair, Pubkey],
    amount: int,
    decimals: int,
    multi_signers: Optional[List[Keypair]] = None,
    opts: Optional[Union[types.TxOpts, TxOptsModel]] = None,
    recent_blockhash: Optional[Blockhash] = None,
) -> SendTransactionResp:
    """Burn tokens, asserting the token mint and decimals.

    Args:
        account: Account to burn tokens from.
        owner: Owner of the account.
        amount: Amount to burn.
        decimals: Number of decimals in amount to burn.
        multi_signers: (optional) Signing accounts if `owner` is a multiSig.
        opts: (optional) Transaction options.
        recent_blockhash: (optional) a prefetched Blockhash for the transaction.
    """
    opts_to_use = (
        TxOptsModel(preflight_commitment=self._conn.commitment)
        if opts is None
        else TxOptsModel.from_namedtuple(opts)
    )
    recent_blockhash_to_use = (
        self._conn.get_latest_blockhash().value.blockhash if recent_blockhash is None else recent_blockhash
    )
    txn, opts = self._burn_checked_args(
        account,
        owner,
        amount,
        decimals,
        multi_signers,
        opts_to_use,
        recent_blockhash_to_use,
    )
    return self._conn.send_transaction(txn, opts=opts)

close_account(account, dest, authority, multi_signers=None, opts=None, recent_blockhash=None)

Remove approval for the transfer of any remaining tokens.

Parameters:

Name Type Description Default
account Pubkey

Account to close.

required
dest Pubkey

Account to receive the remaining balance of the closed account.

required
authority Union[Keypair, Pubkey]

Authority which is allowed to close the account.

required
multi_signers Optional[List[Keypair]]

(optional) Signing accounts if owner is a multiSig.

None
opts Optional[Union[TxOpts, TxOpts]]

(optional) Transaction options.

None
recent_blockhash Optional[Hash]

(optional) a prefetched Blockhash for the transaction.

None
Source code in src/spl/token/client.py
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
def close_account(
    self,
    account: Pubkey,
    dest: Pubkey,
    authority: Union[Keypair, Pubkey],
    multi_signers: Optional[List[Keypair]] = None,
    opts: Optional[Union[types.TxOpts, TxOptsModel]] = None,
    recent_blockhash: Optional[Blockhash] = None,
) -> SendTransactionResp:
    """Remove approval for the transfer of any remaining tokens.

    Args:
        account: Account to close.
        dest: Account to receive the remaining balance of the closed account.
        authority: Authority which is allowed to close the account.
        multi_signers: (optional) Signing accounts if `owner` is a multiSig.
        opts: (optional) Transaction options.
        recent_blockhash: (optional) a prefetched Blockhash for the transaction.
    """
    opts_to_use = (
        TxOptsModel(preflight_commitment=self._conn.commitment)
        if opts is None
        else TxOptsModel.from_namedtuple(opts)
    )
    recent_blockhash_to_use = (
        self._conn.get_latest_blockhash().value.blockhash if recent_blockhash is None else recent_blockhash
    )
    txn, opts = self._close_account_args(
        account,
        dest,
        authority,
        multi_signers,
        opts_to_use,
        recent_blockhash_to_use,
    )
    return self._conn.send_transaction(txn, opts=opts)

create_account(owner, skip_confirmation=False, recent_blockhash=None)

Create and initialize a new account.

This account may then be used as a transfer() or approve() destination.

Parameters:

Name Type Description Default
owner Pubkey

User account that will own the new account.

required
skip_confirmation bool

(optional) Option to skip transaction confirmation.

False
recent_blockhash Optional[Hash]

(optional) a prefetched Blockhash for the transaction.

None

Returns:

Type Description
Pubkey

Public key of the new empty account.

If skip confirmation is set to False, this method will block for at most 30 seconds or until the transaction is confirmed.

Source code in src/spl/token/client.py
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
def create_account(
    self,
    owner: Pubkey,
    skip_confirmation: bool = False,
    recent_blockhash: Optional[Blockhash] = None,
) -> Pubkey:
    """Create and initialize a new account.

    This account may then be used as a `transfer()` or `approve()` destination.

    Args:
        owner: User account that will own the new account.
        skip_confirmation: (optional) Option to skip transaction confirmation.
        recent_blockhash: (optional) a prefetched Blockhash for the transaction.

    Returns:
        Public key of the new empty account.

    If skip confirmation is set to `False`, this method will block for at most 30 seconds
    or until the transaction is confirmed.
    """
    balance_needed = Token.get_min_balance_rent_for_exempt_for_account(self._conn)
    recent_blockhash_to_use = (
        self._conn.get_latest_blockhash().value.blockhash if recent_blockhash is None else recent_blockhash
    )
    new_account_pk, txn, opts = self._create_account_args(
        owner,
        skip_confirmation,
        balance_needed,
        self._conn.commitment,
        recent_blockhash_to_use,
    )
    # Send the two instructions
    self._conn.send_transaction(txn, opts=opts)
    return new_account_pk

create_associated_token_account(owner, skip_confirmation=False, recent_blockhash=None)

Create an associated token account.

Parameters:

Name Type Description Default
owner Pubkey

User account that will own the associated token account.

required
skip_confirmation bool

(optional) Option to skip transaction confirmation.

False
recent_blockhash Optional[Hash]

(optional) a prefetched Blockhash for the transaction.

None

Returns:

Type Description
Pubkey

Public key of the new associated account.

If skip confirmation is set to False, this method will block for at most 30 seconds or until the transaction is confirmed.

Source code in src/spl/token/client.py
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
def create_associated_token_account(
    self,
    owner: Pubkey,
    skip_confirmation: bool = False,
    recent_blockhash: Optional[Blockhash] = None,
) -> Pubkey:
    """Create an associated token account.

    Args:
        owner: User account that will own the associated token account.
        skip_confirmation: (optional) Option to skip transaction confirmation.
        recent_blockhash: (optional) a prefetched Blockhash for the transaction.

    Returns:
        Public key of the new associated account.

    If skip confirmation is set to `False`, this method will block for at most 30 seconds
    or until the transaction is confirmed.
    """
    # Construct transaction
    recent_blockhash_to_use = (
        self._conn.get_latest_blockhash().value.blockhash if recent_blockhash is None else recent_blockhash
    )
    public_key, txn, _payer, opts = self._create_associated_token_account_args(
        owner,
        skip_confirmation,
        self._conn.commitment,
        recent_blockhash_to_use,
        token_program_id=self.program_id,
    )
    self._conn.send_transaction(txn, opts=opts)
    return public_key

create_mint(conn, payer, mint_authority, decimals, program_id, freeze_authority=None, skip_confirmation=False, recent_blockhash=None) classmethod

Create and initialize a token.

Parameters:

Name Type Description Default
conn Client

RPC connection to a solana cluster.

required
payer Keypair

Fee payer for transaction.

required
mint_authority Pubkey

Account or multisig that will control minting.

required
decimals int

Location of the decimal place.

required
program_id Pubkey

SPL Token program account.

required
freeze_authority Optional[Pubkey]

(optional) Account or multisig that can freeze token accounts.

None
skip_confirmation bool

(optional) Option to skip transaction confirmation.

False
recent_blockhash Optional[Hash]

(optional) a prefetched Blockhash for the transaction.

None

Returns:

Type Description
Token

Token object for the newly minted token.

If skip confirmation is set to False, this method will block for at most 30 seconds or until the transaction is confirmed.

Source code in src/spl/token/client.py
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
@classmethod
def create_mint(
    cls,
    conn: Client,
    payer: Keypair,
    mint_authority: Pubkey,
    decimals: int,
    program_id: Pubkey,
    freeze_authority: Optional[Pubkey] = None,
    skip_confirmation: bool = False,
    recent_blockhash: Optional[Blockhash] = None,
) -> Token:
    """Create and initialize a token.

    Args:
        conn: RPC connection to a solana cluster.
        payer: Fee payer for transaction.
        mint_authority: Account or multisig that will control minting.
        decimals: Location of the decimal place.
        program_id: SPL Token program account.
        freeze_authority: (optional) Account or multisig that can freeze token accounts.
        skip_confirmation: (optional) Option to skip transaction confirmation.
        recent_blockhash: (optional) a prefetched Blockhash for the transaction.

    Returns:
        Token object for the newly minted token.

    If skip confirmation is set to `False`, this method will block for at most 30 seconds
    or until the transaction is confirmed.
    """
    # Allocate memory for the account
    balance_needed = Token.get_min_balance_rent_for_exempt_for_mint(conn)
    # Construct transaction
    recent_blockhash_to_use = (
        conn.get_latest_blockhash().value.blockhash if recent_blockhash is None else recent_blockhash
    )
    token, txn, opts = _TokenCore._create_mint_args(
        conn,
        payer,
        mint_authority,
        decimals,
        program_id,
        freeze_authority,
        skip_confirmation,
        balance_needed,
        cls,
        conn.commitment,
        recent_blockhash_to_use,
    )
    # Send the two instructions
    conn.send_transaction(txn, opts=opts)
    return cast(Token, token)

create_multisig(m, multi_signers, opts=None, recent_blockhash=None)

Create and initialize a new multisig.

Parameters:

Name Type Description Default
m int

Number of required signatures.

required
multi_signers List[Pubkey]

Full set of signers.

required
opts Optional[Union[TxOpts, TxOpts]]

(optional) Transaction options.

None
recent_blockhash Optional[Hash]

(optional) a prefetched Blockhash for the transaction.

None

Returns:

Type Description
Pubkey

Public key of the new multisig account.

Source code in src/spl/token/client.py
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
def create_multisig(
    self,
    m: int,
    multi_signers: List[Pubkey],
    opts: Optional[Union[types.TxOpts, TxOptsModel]] = None,
    recent_blockhash: Optional[Blockhash] = None,
) -> Pubkey:  # pylint: disable=invalid-name
    """Create and initialize a new multisig.

    Args:
        m: Number of required signatures.
        multi_signers: Full set of signers.
        opts: (optional) Transaction options.
        recent_blockhash: (optional) a prefetched Blockhash for the transaction.

    Returns:
        Public key of the new multisig account.
    """
    balance_needed = Token.get_min_balance_rent_for_exempt_for_multisig(self._conn)
    recent_blockhash_to_use = (
        self._conn.get_latest_blockhash().value.blockhash if recent_blockhash is None else recent_blockhash
    )
    txn, multisig = self._create_multisig_args(m, multi_signers, balance_needed, recent_blockhash_to_use)
    opts_to_use = (
        TxOptsModel(preflight_commitment=self._conn.commitment)
        if opts is None
        else TxOptsModel.from_namedtuple(opts)
    )
    self._conn.send_transaction(txn, opts=opts_to_use)
    return multisig.pubkey()

create_wrapped_native_account(conn, program_id, owner, payer, amount, skip_confirmation=False, recent_blockhash=None) staticmethod

Create and initialize a new account on the special native token mint.

Parameters:

Name Type Description Default
conn Client

RPC connection to a solana cluster.

required
program_id Pubkey

SPL Token program account.

required
owner Pubkey

The owner of the new token account.

required
payer Keypair

The source of the lamports to initialize, and payer of the initialization fees.

required
amount int

The amount of lamports to wrap.

required
skip_confirmation bool

(optional) Option to skip transaction confirmation.

False
recent_blockhash Optional[Hash]

(optional) a prefetched Blockhash for the transaction.

None

Returns:

Type Description
Pubkey

The new token account.

If skip confirmation is set to False, this method will block for at most 30 seconds or until the transaction is confirmed.

Source code in src/spl/token/client.py
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
@staticmethod
def create_wrapped_native_account(
    conn: Client,
    program_id: Pubkey,
    owner: Pubkey,
    payer: Keypair,
    amount: int,
    skip_confirmation: bool = False,
    recent_blockhash: Optional[Blockhash] = None,
) -> Pubkey:
    """Create and initialize a new account on the special native token mint.

    Args:
        conn: RPC connection to a solana cluster.
        program_id: SPL Token program account.
        owner: The owner of the new token account.
        payer: The source of the lamports to initialize, and payer of the initialization fees.
        amount: The amount of lamports to wrap.
        skip_confirmation: (optional) Option to skip transaction confirmation.
        recent_blockhash: (optional) a prefetched Blockhash for the transaction.

    Returns:
        The new token account.

    If skip confirmation is set to `False`, this method will block for at most 30 seconds
    or until the transaction is confirmed.
    """
    # Allocate memory for the account
    balance_needed = Token.get_min_balance_rent_for_exempt_for_account(conn)
    recent_blockhash_to_use = (
        conn.get_latest_blockhash().value.blockhash if recent_blockhash is None else recent_blockhash
    )
    (
        new_account_public_key,
        txn,
        payer,
        _new_account,
        opts,
    ) = _TokenCore._create_wrapped_native_account_args(
        program_id,
        owner,
        payer,
        amount,
        skip_confirmation,
        balance_needed,
        conn.commitment,
        recent_blockhash_to_use,
    )
    conn.send_transaction(txn, opts=opts)
    return new_account_public_key

freeze_account(account, authority, multi_signers=None, opts=None, recent_blockhash=None)

Freeze account.

Parameters:

Name Type Description Default
account Pubkey

Account to freeze.

required
authority Union[Pubkey, Keypair]

The mint freeze authority.

required
multi_signers Optional[List[Keypair]]

(optional) Signing accounts if authority is a multiSig.

None
opts Optional[Union[TxOpts, TxOpts]]

(optional) Transaction options.

None
recent_blockhash Optional[Hash]

(optional) a prefetched Blockhash for the transaction.

None
Source code in src/spl/token/client.py
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
def freeze_account(
    self,
    account: Pubkey,
    authority: Union[Pubkey, Keypair],
    multi_signers: Optional[List[Keypair]] = None,
    opts: Optional[Union[types.TxOpts, TxOptsModel]] = None,
    recent_blockhash: Optional[Blockhash] = None,
) -> SendTransactionResp:
    """Freeze account.

    Args:
        account: Account to freeze.
        authority: The mint freeze authority.
        multi_signers: (optional) Signing accounts if `authority` is a multiSig.
        opts: (optional) Transaction options.
        recent_blockhash: (optional) a prefetched Blockhash for the transaction.
    """
    opts_to_use = (
        TxOptsModel(preflight_commitment=self._conn.commitment)
        if opts is None
        else TxOptsModel.from_namedtuple(opts)
    )
    recent_blockhash_to_use = (
        self._conn.get_latest_blockhash().value.blockhash if recent_blockhash is None else recent_blockhash
    )
    txn, opts = self._freeze_account_args(account, authority, multi_signers, opts_to_use, recent_blockhash_to_use)
    return self._conn.send_transaction(txn, opts=opts)

get_account_info(account, commitment=None)

Retrieve account information.

Source code in src/spl/token/client.py
395
396
397
398
def get_account_info(self, account: Pubkey, commitment: Optional[Commitment] = None) -> AccountInfo:
    """Retrieve account information."""
    info = self._conn.get_account_info(account, commitment)
    return self._create_account_info(info)

get_accounts_by_delegate(owner, commitment=None, encoding='base64')

Get token accounts of the provided delegate.

Parameters:

Name Type Description Default
owner Pubkey

Public Key of the delegate account.

required
commitment Optional[Commitment]

(optional) Bank state to query.

None
encoding str

(optional) Encoding for Account data, either "base58" (slow) or "base64".

'base64'
Source code in src/spl/token/client.py
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
def get_accounts_by_delegate(
    self,
    owner: Pubkey,
    commitment: Optional[Commitment] = None,
    encoding: str = "base64",
) -> GetTokenAccountsByDelegateResp:
    """Get token accounts of the provided delegate.

    Args:
        owner: Public Key of the delegate account.
        commitment: (optional) Bank state to query.
        encoding: (optional) Encoding for Account data, either "base58" (slow) or "base64".
    """
    args = self._get_accounts_args(
        owner,
        commitment,
        encoding,
        self._conn.commitment,  # pylint: disable=protected-access
    )
    return self._conn.get_token_accounts_by_delegate(*args)

get_accounts_by_delegate_json_parsed(owner, commitment=None, encoding='base64')

Get token accounts of the provided delegate, in JSON format.

Parameters:

Name Type Description Default
owner Pubkey

Public Key of the delegate account.

required
commitment Optional[Commitment]

(optional) Bank state to query.

None
encoding str

(optional) Encoding for Account data, either "base58" (slow) or "base64".

'base64'

Parsed-JSON encoding attempts to use program-specific state parsers to return more human-readable and explicit account state data. If parsed-JSON is requested but a valid mint cannot be found for a particular account, that account will be filtered out from results. jsonParsed encoding is UNSTABLE.

Source code in src/spl/token/client.py
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
def get_accounts_by_delegate_json_parsed(
    self,
    owner: Pubkey,
    commitment: Optional[Commitment] = None,
    encoding: str = "base64",
) -> GetTokenAccountsByDelegateJsonParsedResp:
    """Get token accounts of the provided delegate, in JSON format.

    Args:
        owner: Public Key of the delegate account.
        commitment: (optional) Bank state to query.
        encoding: (optional) Encoding for Account data, either "base58" (slow) or "base64".

    Parsed-JSON encoding attempts to use program-specific state parsers to return more
    human-readable and explicit account state data. If parsed-JSON is requested but a
    valid mint cannot be found for a particular account, that account will be filtered out
    from results. jsonParsed encoding is UNSTABLE.
    """
    args = self._get_accounts_args(
        owner,
        commitment,
        encoding,
        self._conn.commitment,  # pylint: disable=protected-access
    )
    return self._conn.get_token_accounts_by_delegate_json_parsed(*args)

get_accounts_by_owner(owner, commitment=None, encoding='base64')

Get token accounts of the provided owner.

Parameters:

Name Type Description Default
owner Pubkey

Public Key of the token account owner.

required
commitment Optional[Commitment]

(optional) Bank state to query.

None
encoding str

(optional) Encoding for Account data, either "base58" (slow) or "base64".

'base64'
Source code in src/spl/token/client.py
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
def get_accounts_by_owner(
    self,
    owner: Pubkey,
    commitment: Optional[Commitment] = None,
    encoding: str = "base64",
) -> GetTokenAccountsByOwnerResp:
    """Get token accounts of the provided owner.

    Args:
        owner: Public Key of the token account owner.
        commitment: (optional) Bank state to query.
        encoding: (optional) Encoding for Account data, either "base58" (slow) or "base64".
    """
    args = self._get_accounts_args(
        owner,
        commitment,
        encoding,
        self._conn.commitment,  # pylint: disable=protected-access
    )
    return self._conn.get_token_accounts_by_owner(*args)

get_accounts_by_owner_json_parsed(owner, commitment=None)

Get token accounts of the provided owner by the token's mint, in JSON format.

Parameters:

Name Type Description Default
owner Pubkey

Public Key of the token account owner.

required
commitment Optional[Commitment]

(optional) Bank state to query.

None

Parsed-JSON encoding attempts to use program-specific state parsers to return more human-readable and explicit account state data. If parsed-JSON is requested but a valid mint cannot be found for a particular account, that account will be filtered out from results. jsonParsed encoding is UNSTABLE.

Source code in src/spl/token/client.py
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
def get_accounts_by_owner_json_parsed(
    self,
    owner: Pubkey,
    commitment: Optional[Commitment] = None,
) -> GetTokenAccountsByOwnerJsonParsedResp:
    """Get token accounts of the provided owner by the token's mint, in JSON format.

    Args:
        owner: Public Key of the token account owner.
        commitment: (optional) Bank state to query.


    Parsed-JSON encoding attempts to use program-specific state parsers to return more
    human-readable and explicit account state data. If parsed-JSON is requested but a
    valid mint cannot be found for a particular account, that account will be filtered out
    from results. jsonParsed encoding is UNSTABLE.
    """
    args = self._get_accounts_args(
        owner,
        commitment,
        "jsonParsed",
        self._conn.commitment,  # pylint: disable=protected-access
    )
    return self._conn.get_token_accounts_by_owner_json_parsed(*args)

get_balance(pubkey, commitment=None)

Get the balance of the provided token account.

Parameters:

Name Type Description Default
pubkey Pubkey

Public Key of the token account.

required
commitment Optional[Commitment]

(optional) Bank state to query.

None
Source code in src/spl/token/client.py
177
178
179
180
181
182
183
184
def get_balance(self, pubkey: Pubkey, commitment: Optional[Commitment] = None) -> GetTokenAccountBalanceResp:
    """Get the balance of the provided token account.

    Args:
        pubkey: Public Key of the token account.
        commitment: (optional) Bank state to query.
    """
    return self._conn.get_token_account_balance(pubkey, commitment)

get_min_balance_rent_for_exempt_for_account(conn) staticmethod

Get the minimum balance for the account to be rent exempt.

Parameters:

Name Type Description Default
conn Client

RPC connection to a solana cluster.

required

Returns:

Type Description
int

Number of lamports required.

Source code in src/spl/token/client.py
46
47
48
49
50
51
52
53
54
55
56
57
@staticmethod
def get_min_balance_rent_for_exempt_for_account(conn: Client) -> int:
    """Get the minimum balance for the account to be rent exempt.

    Args:
        conn: RPC connection to a solana cluster.

    Returns:
        Number of lamports required.
    """
    resp = conn.get_minimum_balance_for_rent_exemption(ACCOUNT_LAYOUT.sizeof())
    return resp.value

get_min_balance_rent_for_exempt_for_mint(conn) staticmethod

Get the minimum balance for the mint to be rent exempt.

Parameters:

Name Type Description Default
conn Client

RPC connection to a solana cluster.

required

Returns:

Type Description
int

Number of lamports required.

Source code in src/spl/token/client.py
59
60
61
62
63
64
65
66
67
68
69
70
@staticmethod
def get_min_balance_rent_for_exempt_for_mint(conn: Client) -> int:
    """Get the minimum balance for the mint to be rent exempt.

    Args:
        conn: RPC connection to a solana cluster.

    Returns:
        Number of lamports required.
    """
    resp = conn.get_minimum_balance_for_rent_exemption(MINT_LAYOUT.sizeof())
    return resp.value

get_min_balance_rent_for_exempt_for_multisig(conn) staticmethod

Get the minimum balance for the multisig to be rent exempt.

Parameters:

Name Type Description Default
conn Client

RPC connection to a solana cluster.

required
Source code in src/spl/token/client.py
72
73
74
75
76
77
78
79
80
81
82
@staticmethod
def get_min_balance_rent_for_exempt_for_multisig(conn: Client) -> int:
    """Get the minimum balance for the multisig to be rent exempt.

    Args:
        conn: RPC connection to a solana cluster.

    Return: Number of lamports required.
    """
    resp = conn.get_minimum_balance_for_rent_exemption(MULTISIG_LAYOUT.sizeof())
    return resp.value

get_mint_info()

Retrieve mint information.

Source code in src/spl/token/client.py
390
391
392
393
def get_mint_info(self) -> MintInfo:
    """Retrieve mint information."""
    info = self._conn.get_account_info(self.pubkey)
    return self._create_mint_info(info)

mint_to(dest, mint_authority, amount, multi_signers=None, opts=None, recent_blockhash=None)

Mint new tokens.

Parameters:

Name Type Description Default
dest Pubkey

Public key of the account to mint to.

required
mint_authority Union[Keypair, Pubkey]

Public key of the minting authority.

required
amount int

Amount to mint.

required
multi_signers Optional[List[Keypair]]

(optional) Signing accounts if owner is a multiSig.

None
opts Optional[Union[TxOpts, TxOpts]]

(optional) Transaction options.

None
recent_blockhash Optional[Hash]

(optional) a prefetched Blockhash for the transaction.

None

If skip confirmation is set to False, this method will block for at most 30 seconds or until the transaction is confirmed.

Source code in src/spl/token/client.py
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
def mint_to(
    self,
    dest: Pubkey,
    mint_authority: Union[Keypair, Pubkey],
    amount: int,
    multi_signers: Optional[List[Keypair]] = None,
    opts: Optional[Union[types.TxOpts, TxOptsModel]] = None,
    recent_blockhash: Optional[Blockhash] = None,
) -> SendTransactionResp:
    """Mint new tokens.

    Args:
        dest: Public key of the account to mint to.
        mint_authority: Public key of the minting authority.
        amount: Amount to mint.
        multi_signers: (optional) Signing accounts if `owner` is a multiSig.
        opts: (optional) Transaction options.
        recent_blockhash: (optional) a prefetched Blockhash for the transaction.

    If skip confirmation is set to `False`, this method will block for at most 30 seconds
    or until the transaction is confirmed.
    """
    opts_to_use = (
        TxOptsModel(preflight_commitment=self._conn.commitment)
        if opts is None
        else TxOptsModel.from_namedtuple(opts)
    )
    recent_blockhash_to_use = (
        self._conn.get_latest_blockhash().value.blockhash if recent_blockhash is None else recent_blockhash
    )
    txn, opts = self._mint_to_args(
        dest,
        mint_authority,
        amount,
        multi_signers,
        opts_to_use,
        recent_blockhash_to_use,
    )
    return self._conn.send_transaction(txn, opts=opts)

mint_to_checked(dest, mint_authority, amount, decimals, multi_signers=None, opts=None, recent_blockhash=None)

Mint new tokens, asserting the token mint and decimals.

Parameters:

Name Type Description Default
dest Pubkey

Public key of the account to mint to.

required
mint_authority Union[Keypair, Pubkey]

Public key of the minting authority.

required
amount int

Amount to mint.

required
decimals int

Number of decimals in amount to mint.

required
multi_signers Optional[List[Keypair]]

(optional) Signing accounts if owner is a multiSig.

None
opts Optional[Union[TxOpts, TxOpts]]

(optional) Transaction options.

None
recent_blockhash Optional[Hash]

(optional) a prefetched Blockhash for the transaction.

None
Source code in src/spl/token/client.py
801
802
803
804
805
806
807
808
809
810
811
812
813
814
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
def mint_to_checked(
    self,
    dest: Pubkey,
    mint_authority: Union[Keypair, Pubkey],
    amount: int,
    decimals: int,
    multi_signers: Optional[List[Keypair]] = None,
    opts: Optional[Union[types.TxOpts, TxOptsModel]] = None,
    recent_blockhash: Optional[Blockhash] = None,
) -> SendTransactionResp:
    """Mint new tokens, asserting the token mint and decimals.

    Args:
        dest: Public key of the account to mint to.
        mint_authority: Public key of the minting authority.
        amount: Amount to mint.
        decimals: Number of decimals in amount to mint.
        multi_signers: (optional) Signing accounts if `owner` is a multiSig.
        opts: (optional) Transaction options.
        recent_blockhash: (optional) a prefetched Blockhash for the transaction.
    """
    opts_to_use = (
        TxOptsModel(preflight_commitment=self._conn.commitment)
        if opts is None
        else TxOptsModel.from_namedtuple(opts)
    )
    recent_blockhash_to_use = (
        self._conn.get_latest_blockhash().value.blockhash if recent_blockhash is None else recent_blockhash
    )
    txn, opts = self._mint_to_checked_args(
        dest,
        mint_authority,
        amount,
        decimals,
        multi_signers,
        opts_to_use,
        recent_blockhash_to_use,
    )
    return self._conn.send_transaction(txn, opts=opts)

revoke(account, owner, multi_signers=None, opts=None, recent_blockhash=None)

Revoke transfer authority for a given account.

Parameters:

Name Type Description Default
account Pubkey

Source account for which transfer authority is being revoked.

required
owner Pubkey

Owner of the source account.

required
multi_signers Optional[List[Keypair]]

(optional) Signing accounts if owner is a multiSig.

None
opts Optional[Union[TxOpts, TxOpts]]

(optional) Transaction options.

None
recent_blockhash Optional[Hash]

(optional) a prefetched Blockhash for the transaction.

None
Source code in src/spl/token/client.py
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
def revoke(
    self,
    account: Pubkey,
    owner: Pubkey,
    multi_signers: Optional[List[Keypair]] = None,
    opts: Optional[Union[types.TxOpts, TxOptsModel]] = None,
    recent_blockhash: Optional[Blockhash] = None,
) -> SendTransactionResp:
    """Revoke transfer authority for a given account.

    Args:
        account: Source account for which transfer authority is being revoked.
        owner: Owner of the source account.
        multi_signers: (optional) Signing accounts if `owner` is a multiSig.
        opts: (optional) Transaction options.
        recent_blockhash: (optional) a prefetched Blockhash for the transaction.
    """
    opts_to_use = (
        TxOptsModel(preflight_commitment=self._conn.commitment)
        if opts is None
        else TxOptsModel.from_namedtuple(opts)
    )
    recent_blockhash_to_use = (
        self._conn.get_latest_blockhash().value.blockhash if recent_blockhash is None else recent_blockhash
    )
    txn, _payer, _signers, opts = self._revoke_args(
        account, owner, multi_signers, opts_to_use, recent_blockhash_to_use
    )
    return self._conn.send_transaction(txn, opts=opts)

set_authority(account, current_authority, authority_type, new_authority=None, multi_signers=None, opts=None, recent_blockhash=None)

Assign a new authority to the account.

Parameters:

Name Type Description Default
account Pubkey

Public key of the token account.

required
current_authority Union[Keypair, Pubkey]

Current authority of the account.

required
authority_type AuthorityType

Type of authority to set.

required
new_authority Optional[Pubkey]

(optional) New authority of the account.

None
multi_signers Optional[List[Keypair]]

(optional) Signing accounts if owner is a multiSig.

None
opts Optional[Union[TxOpts, TxOpts]]

(optional) Transaction options.

None
recent_blockhash Optional[Hash]

(optional) a prefetched Blockhash for the transaction.

None
Source code in src/spl/token/client.py
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
def set_authority(
    self,
    account: Pubkey,
    current_authority: Union[Keypair, Pubkey],
    authority_type: spl_token.AuthorityType,
    new_authority: Optional[Pubkey] = None,
    multi_signers: Optional[List[Keypair]] = None,
    opts: Optional[Union[types.TxOpts, TxOptsModel]] = None,
    recent_blockhash: Optional[Blockhash] = None,
) -> SendTransactionResp:
    """Assign a new authority to the account.

    Args:
        account: Public key of the token account.
        current_authority: Current authority of the account.
        authority_type: Type of authority to set.
        new_authority: (optional) New authority of the account.
        multi_signers: (optional) Signing accounts if `owner` is a multiSig.
        opts: (optional) Transaction options.
        recent_blockhash: (optional) a prefetched Blockhash for the transaction.
    """
    opts_to_use = (
        TxOptsModel(preflight_commitment=self._conn.commitment)
        if opts is None
        else TxOptsModel.from_namedtuple(opts)
    )
    recent_blockhash_to_use = (
        self._conn.get_latest_blockhash().value.blockhash if recent_blockhash is None else recent_blockhash
    )
    txn, _payer, _signers, opts = self._set_authority_args(
        account,
        current_authority,
        authority_type,
        new_authority,
        multi_signers,
        opts_to_use,
        recent_blockhash_to_use,
    )
    return self._conn.send_transaction(txn, opts=opts)

thaw_account(account, authority, multi_signers=None, opts=None, recent_blockhash=None)

Thaw account.

Parameters:

Name Type Description Default
account Pubkey

Account to thaw.

required
authority Pubkey

The mint freeze authority.

required
multi_signers Optional[List[Keypair]]

(optional) Signing accounts if authority is a multiSig.

None
opts Optional[Union[TxOpts, TxOpts]]

(optional) Transaction options.

None
recent_blockhash Optional[Hash]

(optional) a prefetched Blockhash for the transaction.

None
Source code in src/spl/token/client.py
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
def thaw_account(
    self,
    account: Pubkey,
    authority: Pubkey,
    multi_signers: Optional[List[Keypair]] = None,
    opts: Optional[Union[types.TxOpts, TxOptsModel]] = None,
    recent_blockhash: Optional[Blockhash] = None,
) -> SendTransactionResp:
    """Thaw account.

    Args:
        account: Account to thaw.
        authority: The mint freeze authority.
        multi_signers: (optional) Signing accounts if `authority` is a multiSig.
        opts: (optional) Transaction options.
        recent_blockhash: (optional) a prefetched Blockhash for the transaction.
    """
    opts_to_use = (
        TxOptsModel(preflight_commitment=self._conn.commitment)
        if opts is None
        else TxOptsModel.from_namedtuple(opts)
    )
    recent_blockhash_to_use = (
        self._conn.get_latest_blockhash().value.blockhash if recent_blockhash is None else recent_blockhash
    )
    txn, opts = self._thaw_account_args(account, authority, multi_signers, opts_to_use, recent_blockhash_to_use)
    return self._conn.send_transaction(txn, opts=opts)

transfer(source, dest, owner, amount, multi_signers=None, opts=None, recent_blockhash=None)

Transfer tokens to another account.

Parameters:

Name Type Description Default
source Pubkey

Public key of account to transfer tokens from.

required
dest Pubkey

Public key of account to transfer tokens to.

required
owner Union[Keypair, Pubkey]

Owner of the source account.

required
amount int

Number of tokens to transfer.

required
multi_signers Optional[List[Keypair]]

(optional) Signing accounts if owner is a multiSig.

None
opts Optional[Union[TxOpts, TxOpts]]

(optional) Transaction options.

None
recent_blockhash Optional[Hash]

(optional) a prefetched Blockhash for the transaction.

None
Source code in src/spl/token/client.py
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
def transfer(
    self,
    source: Pubkey,
    dest: Pubkey,
    owner: Union[Keypair, Pubkey],
    amount: int,
    multi_signers: Optional[List[Keypair]] = None,
    opts: Optional[Union[types.TxOpts, TxOptsModel]] = None,
    recent_blockhash: Optional[Blockhash] = None,
) -> SendTransactionResp:
    """Transfer tokens to another account.

    Args:
        source: Public key of account to transfer tokens from.
        dest: Public key of account to transfer tokens to.
        owner: Owner of the source account.
        amount: Number of tokens to transfer.
        multi_signers: (optional) Signing accounts if `owner` is a multiSig.
        opts: (optional) Transaction options.
        recent_blockhash: (optional) a prefetched Blockhash for the transaction.
    """
    opts_to_use = (
        TxOptsModel(preflight_commitment=self._conn.commitment)
        if opts is None
        else TxOptsModel.from_namedtuple(opts)
    )
    recent_blockhash_to_use = (
        self._conn.get_latest_blockhash().value.blockhash if recent_blockhash is None else recent_blockhash
    )
    txn, opts = self._transfer_args(
        source,
        dest,
        owner,
        amount,
        multi_signers,
        opts_to_use,
        recent_blockhash_to_use,
    )
    return self._conn.send_transaction(txn, opts=opts)

transfer_checked(source, dest, owner, amount, decimals, multi_signers=None, opts=None, recent_blockhash=None)

Transfer tokens to another account, asserting the token mint and decimals.

Parameters:

Name Type Description Default
source Pubkey

Public key of account to transfer tokens from.

required
dest Pubkey

Public key of account to transfer tokens to.

required
owner Union[Keypair, Pubkey]

Owner of the source account.

required
amount int

Number of tokens to transfer.

required
decimals int

Number of decimals in transfer amount.

required
multi_signers Optional[List[Keypair]]

(optional) Signing accounts if owner is a multiSig.

None
opts Optional[Union[TxOpts, TxOpts]]

(optional) Transaction options.

None
recent_blockhash Optional[Hash]

(optional) a prefetched Blockhash for the transaction.

None
Source code in src/spl/token/client.py
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
def transfer_checked(
    self,
    source: Pubkey,
    dest: Pubkey,
    owner: Union[Keypair, Pubkey],
    amount: int,
    decimals: int,
    multi_signers: Optional[List[Keypair]] = None,
    opts: Optional[Union[types.TxOpts, TxOptsModel]] = None,
    recent_blockhash: Optional[Blockhash] = None,
) -> SendTransactionResp:
    """Transfer tokens to another account, asserting the token mint and decimals.

    Args:
        source: Public key of account to transfer tokens from.
        dest: Public key of account to transfer tokens to.
        owner: Owner of the source account.
        amount: Number of tokens to transfer.
        decimals: Number of decimals in transfer amount.
        multi_signers: (optional) Signing accounts if `owner` is a multiSig.
        opts: (optional) Transaction options.
        recent_blockhash: (optional) a prefetched Blockhash for the transaction.
    """
    opts_to_use = (
        TxOptsModel(preflight_commitment=self._conn.commitment)
        if opts is None
        else TxOptsModel.from_namedtuple(opts)
    )
    recent_blockhash_to_use = (
        self._conn.get_latest_blockhash().value.blockhash if recent_blockhash is None else recent_blockhash
    )
    txn, opts = self._transfer_checked_args(
        source,
        dest,
        owner,
        amount,
        decimals,
        multi_signers,
        opts_to_use,
        recent_blockhash_to_use,
    )
    return self._conn.send_transaction(txn, opts=opts)