Module: Solana::Ruby::Kit::Programs::SystemProgram

Extended by:
T::Sig
Defined in:
lib/solana/ruby/kit/programs/system_program.rb

Overview

Ruby interface for the Solana System Program (11111111111111111111111111111111).

The System Program is responsible for creating accounts, transferring SOL, and other low-level operations. Instruction data uses little-endian encoding: a u32 discriminator identifying the instruction variant, followed by any instruction-specific fields.

Reference: github.com/solana-program/system

Constant Summary collapse

PROGRAM_ID =

The System Program address (all zeros, encoded in base58).

T.let(
  Addresses::Address.new('11111111111111111111111111111111'),
  Addresses::Address
)
DISCRIMINATOR_TRANSFER =

Instruction discriminators (u32 little-endian).

T.let(2, Integer)

Class Method Summary collapse

Class Method Details

.transfer_instruction(sender:, recipient:, lamports:) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/solana/ruby/kit/programs/system_program.rb', line 54

def transfer_instruction(sender:, recipient:, lamports:)
  # Pack as: u32 LE discriminator || u64 LE lamports
  data = [DISCRIMINATOR_TRANSFER, lamports].pack('VQ<').b

  Instructions::Instruction.new(
    program_address: PROGRAM_ID,
    accounts: [
      Instructions.(sender),    # 0 sender
      Instructions.(recipient),         # 1 recipient
    ],
    data: data
  )
end