Class: Solace::Instructions::AssociatedTokenAccount::CreateAssociatedTokenAccountInstruction

Inherits:
Object
  • Object
show all
Defined in:
lib/solace/instructions/associated_token_account/create_associated_token_account_instruction.rb

Overview

A class to build the CreateAssociatedTokenAccount instruction for the Associated Token Account Program. This is a special “all-in-one” instruction that creates and initializes the account.

Constant Summary collapse

INSTRUCTION_INDEX =

!@const INSTRUCTION_INDEX

Instruction index for CreateAssociatedTokenAccount

Returns:

  • (Array<Integer>)
[0].freeze

Class Method Summary collapse

Class Method Details

.build(funder_index:, associated_token_account_index:, owner_index:, mint_index:, system_program_index:, token_program_index:, program_index:) ⇒ Solace::Instruction

Builds a CreateAssociatedTokenAccount instruction.

The on-chain program requires accounts in a specific order:

  1. writable, signer

    Funder: The account paying for the rent.

  2. writable

    ATA: The new Associated Token Account to be created.

  3. readonly

    Owner: The wallet that will own the new ATA.

  4. readonly

    Mint: The token mint for the new ATA.

  5. readonly

    System Program: Required to create the account.

  6. readonly

    SPL Token Program: Required to initialize the account.

Parameters:

  • funder_index (Integer)

    Index of the funding account (payer).

  • associated_token_account_index (Integer)

    Index of the Associated Token Account to be created.

  • owner_index (Integer)

    Index of the wallet that will own the new ATA.

  • mint_index (Integer)

    Index of the token mint.

  • system_program_index (Integer)

    Index of the System Program.

  • token_program_index (Integer)

    Index of the SPL Token Program.

  • program_index (Integer)

    Index of the Associated Token Program itself.

Returns:



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/solace/instructions/associated_token_account/create_associated_token_account_instruction.rb', line 33

def self.build(
  funder_index:,
  associated_token_account_index:,
  owner_index:,
  mint_index:,
  system_program_index:,
  token_program_index:,
  program_index:
)
  Solace::Instruction.new.tap do |ix|
    ix.program_index = program_index
    ix.accounts = [
      funder_index,
      ,
      owner_index,
      mint_index,
      system_program_index,
      token_program_index
    ]
    ix.data = data
  end
end

.dataArray

Data for a CreateAssociatedTokenAccount instruction

The BufferLayout is:

- [Instruction Index (1 byte)]

Returns:

  • (Array)

    1-byte instruction index



62
63
64
# File 'lib/solace/instructions/associated_token_account/create_associated_token_account_instruction.rb', line 62

def self.data
  INSTRUCTION_INDEX
end