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

Instruction for creating an Associated Token Account.

This is a special “all-in-one” instruction that creates and initializes the account. It is used to create an Associated Token Account (ATA) for a given mint and owner.

Examples:

Build a CreateAssociatedTokenAccount instruction

instruction = Solace::Instructions::AssociatedTokenAccount::CreateAssociatedTokenAccountInstruction.build(
  funder_index: 0,
  associated_token_account_index: 1,
  owner_index: 2,
  mint_index: 3,
  system_program_index: 4,
  token_program_index: 5,
  program_index: 6
)

Since:

  • 0.0.2

Constant Summary collapse

INSTRUCTION_INDEX =

!@const INSTRUCTION_INDEX

Instruction index for CreateAssociatedTokenAccount

Since:

  • 0.0.2

[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.

Since:

  • 0.0.2



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/solace/instructions/associated_token_account/create_associated_token_account_instruction.rb', line 48

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)]

Since:

  • 0.0.2



77
78
79
# File 'lib/solace/instructions/associated_token_account/create_associated_token_account_instruction.rb', line 77

def self.data
  INSTRUCTION_INDEX
end