Class: Solace::Instructions::SplToken::InitializeMintInstruction

Inherits:
Object
  • Object
show all
Defined in:
lib/solace/instructions/spl_token/initialize_mint_instruction.rb

Overview

Instruction for initializing a new mint.

This instruction is used to initialize a new mint for a given token. It is used in conjunction with the SystemProgram::CreateAccount instruction to create and initialize a new mint account.

Examples:

Build an InitializeMint instruction

instruction = Solace::Instructions::SplToken::InitializeMintInstruction.build(
  decimals: 6,
  mint_authority: mint_authority.address,
  freeze_authority: freeze_authority.address,
  rent_sysvar_index: 2,
  mint_account_index: 1,
  program_index: 3
)

See Also:

Since:

  • 0.0.2

Constant Summary collapse

INSTRUCTION_INDEX =

Instruction index for Initialize Mint

Since:

  • 0.0.2

[0].freeze

Class Method Summary collapse

Class Method Details

.build(decimals:, mint_authority:, rent_sysvar_index:, mint_account_index:, freeze_authority: nil, program_index: 2) ⇒ Solace::Instruction

Builds a Solace::Instruction for initializing an SPL Token Program mint

The BufferLayout is:

- [Instruction Index (1 byte)]
- [Decimals (1 byte)]
- [Mint authority (32 bytes)]
- [Freeze authority option (1 byte)]
- [Freeze authority (32 bytes)]

Parameters:

  • decimals (Integer)

    Number of decimals for the token

  • mint_authority (String)

    Public key of the mint authority

  • freeze_authority (String, nil) (defaults to: nil)

    Public key of the freeze authority

  • rent_sysvar_index (Integer)

    Index of the rent sysvar in the transaction’s accounts

  • mint_account_index (Integer)

    Index of the mint account in the transaction’s accounts

  • program_index (Integer) (defaults to: 2)

    Index of the SPL Token Program in the transaction’s accounts (default: 3)

Returns:

Since:

  • 0.0.2



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/solace/instructions/spl_token/initialize_mint_instruction.rb', line 43

def self.build(
  decimals:,
  mint_authority:,
  rent_sysvar_index:,
  mint_account_index:,
  freeze_authority: nil,
  program_index: 2
)
  Solace::Instruction.new.tap do |ix|
    ix.program_index = program_index
    ix.accounts = [, rent_sysvar_index]
    ix.data = data(decimals, mint_authority, freeze_authority)
  end
end

.data(decimals, mint_authority, freeze_authority) ⇒ Array<u8>

Instruction data for an initialize mint instruction

The BufferLayout is:

- [Instruction Index (1 byte)]
- [Decimals (1 byte)]
- [Mint authority (32 bytes)]
- [Freeze authority option (33 byte)]

Parameters:

  • decimals (Integer)

    Number of decimals for the token

  • mint_authority (String)

    Public key of the mint authority

  • freeze_authority (String, nil)

    Public key of the freeze authority

Returns:

  • (Array<u8>)

    The instruction data

Since:

  • 0.0.2



70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/solace/instructions/spl_token/initialize_mint_instruction.rb', line 70

def self.data(decimals, mint_authority, freeze_authority)
  INSTRUCTION_INDEX +
    [decimals] +
    Solace::Utils::Codecs.base58_to_bytes(mint_authority) +
    (
      if freeze_authority
        [1] + Solace::Utils::Codecs.base58_to_bytes(freeze_authority)
      else
        [0]
      end
    )
end