Skip to content

System Program

The System program owns the most fundamental operations: transferring SOL and creating accounts. Solace ships instruction builders and composers for both. There is no dedicated Programs::System client — these operations are simple enough that the composer layer is the natural top level.

Program ID: Solace::Constants::SYSTEM_PROGRAM_ID (11111111111111111111111111111111).

Transfer SOL

Move lamports from one account to another.

Composer — SystemProgramTransferComposer

ParameterTypeRequiredDefaultDescription
from#to_syesSource account (writable signer).
to#to_syesDestination account (writable).
lamportsIntegeryesAmount to transfer, in lamports.
ruby
tx = Solace::TransactionComposer.new(connection:)
                                .add_instruction(
                                  Solace::Composers::SystemProgramTransferComposer.new(
                                    from:     payer.address,
                                    to:       recipient.address,
                                    lamports: 1_000_000
                                  )
                                )
                                .set_fee_payer(payer.address)
                                .compose_transaction

tx.sign(payer)
connection.send_transaction(tx.serialize)

Low-level instruction (advanced)

Instructions::SystemProgram::TransferInstruction.build encodes the raw instruction from account indices.

  • Encodes (data): le_u32(2) (the System Transfer discriminator) + le_u64(lamports)
ParameterTypeRequiredDefaultDescription
lamportsIntegeryesAmount in lamports.
from_indexIntegeryesIndex of the source account.
to_indexIntegeryesIndex of the destination account.
program_indexIntegerno2Index of the System program in the account list.
ruby
ix = Solace::Instructions::SystemProgram::TransferInstruction.build(
  lamports:      1_000_000,
  from_index:    context.index_of(payer.address),
  to_index:      context.index_of(recipient.address),
  program_index: context.index_of(Solace::Constants::SYSTEM_PROGRAM_ID)
)

Create an account

Allocate a new account, fund it to rent-exemption, and assign it to an owning program — the primitive behind creating mints, token accounts, and program state.

Composer — SystemProgramCreateAccountComposer

ParameterTypeRequiredDefaultDescription
from#to_syesFunder of the new account's rent (writable signer).
new_account#to_syesThe account to create (writable signer).
lamportsIntegeryesLamports to deposit (use get_minimum_lamports_for_rent_exemption).
spaceIntegeryesBytes to allocate for the account's data.
owner#to_syesProgram that will own the new account.
ruby
rent  = connection.get_minimum_lamports_for_rent_exemption(165)
acct  = Solace::Keypair.generate

tx = Solace::TransactionComposer.new(connection:)
                                .add_instruction(
                                  Solace::Composers::SystemProgramCreateAccountComposer.new(
                                    from:        payer.address,
                                    new_account: acct.address,
                                    lamports:    rent,
                                    space:       165,
                                    owner:       Solace::Constants::TOKEN_PROGRAM_ID
                                  )
                                )
                                .set_fee_payer(payer.address)
                                .compose_transaction

tx.sign(payer, acct) # the new account must also sign
connection.send_transaction(tx.serialize)

Low-level instruction (advanced)

Instructions::SystemProgram::CreateAccountInstruction.build encodes the raw instruction.

  • Encodes (data): le_u32(0) (the System CreateAccount discriminator) + le_u64(lamports) + le_u64(space) + the 32-byte owner pubkey.
ParameterTypeRequiredDescription
lamportsIntegeryesRent to deposit.
spaceIntegeryesBytes to allocate.
owner#to_syesOwning program's pubkey.
from_indexIntegeryesIndex of the funder.
new_account_indexIntegeryesIndex of the new account.
program_indexIntegeryesIndex of the System program.

TIP

Creating a mint or token account combines a create-account instruction with an initialize instruction in one transaction. The SPL Token client does this for you in create_mint.

A Ruby SDK for Solana