Class: Solace::Instructions::SplToken::MintToInstruction

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

Overview

Instruction for minting tokens to a token account.

This instruction is used to mint tokens to a token account for a given mint and owner.

Examples:

Build a MintTo instruction

instruction = Solace::Instructions::SplToken::MintToInstruction.build(
  amount: 100,
  mint_index: 1,
  mint_authority_index: 2,
  destination_index: 3,
  program_index: 4
)

Since:

  • 0.0.2

Constant Summary collapse

INSTRUCTION_INDEX =

Since:

  • 0.0.2

[7].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#INSTRUCTION_INDEXObject (readonly)

Instruction index for SPL Token Program’s MintTo instruction.



23
# File 'lib/solace/instructions/spl_token/mint_to_instruction.rb', line 23

INSTRUCTION_INDEX = [7].freeze

Class Method Details

.build(amount:, mint_index:, mint_authority_index:, destination_index:, program_index:) ⇒ Solace::Instruction

Builds a MintTo instruction.

Parameters:

  • amount (Integer)

    The amount of tokens to mint.

  • mint_index (Integer)

    The index of the mint account.

  • destination_index (Integer)

    The index of the token account to mint to.

  • mint_authority_index (Integer)

    The index of the mint authority account.

  • program_index (Integer)

    The index of the SPL Token Program.

Returns:

Since:

  • 0.0.2



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/solace/instructions/spl_token/mint_to_instruction.rb', line 33

def self.build(
  amount:,
  mint_index:,
  mint_authority_index:,
  destination_index:,
  program_index:
)
  Solace::Instruction.new.tap do |ix|
    ix.program_index = program_index
    ix.accounts = [mint_index, destination_index, mint_authority_index]
    ix.data = data(amount)
  end
end

.data(amount) ⇒ Array

Builds the data for a MintTo instruction.

The BufferLayout is:

- [Instruction Index (1 byte)]
- [Amount (8 bytes)]

Parameters:

  • amount (Integer)

    The amount of tokens to mint.

Returns:

  • (Array)

    1-byte instruction index + 8-byte amount

Since:

  • 0.0.2



55
56
57
# File 'lib/solace/instructions/spl_token/mint_to_instruction.rb', line 55

def self.data(amount)
  INSTRUCTION_INDEX + Solace::Utils::Codecs.encode_le_u64(amount).bytes
end