Client and backend. This class is shared: the same code is compiled into your app and into your server, so everything on this page works in both.

public final class SolanaMessage

  1. Object
  2. SolanaMessage

The part of a transaction that is signed: the accounts, a recent blockhash and the compiled instructions. Both wire versions are read and written: the legacy format and v0. compile orders accounts the way the Solana SDK does: the fee payer first, then the writable signers, the read-only signers, the writable and the read-only non-signers, each group in order of first appearance, with every program after the accounts named before it.

A v0 message read from the wire may name accounts through address lookup tables; those are kept as they are so the message re-serializes unchanged, but only its static keys can be resolved here.

Fields

public static final int LEGACY = -1The version of a legacy message.

Methods

public static SolanaMessage compile(SolanaAddress payer, List<Instruction> instructions, String recentBlockhash)A legacy message.
public static SolanaMessage compileV0(SolanaAddress payer, List<Instruction> instructions, String recentBlockhash)A v0 message with no address lookup tables.
public byte[] serialize()The wire form, the bytes every signer signs.
public static SolanaMessage parse(byte[] data)Reads a message, legacy or v0.
public int getVersion()LEGACY or 0.
public List<SolanaAddress> getAccountKeys()The accounts named directly in the message; signers come first.
public SolanaAddress getFeePayer()The fee payer, the first account.
public String getRecentBlockhash()The Base58 recent blockhash.
public int getNumRequiredSignatures()How many signatures the transaction carries; the first this many accounts sign.
public boolean isSigner(int index)Whether the account at an index signs.
public boolean isWritable(int index)Whether the message marks the account at an index writable.
public boolean hasAddressLookups()Whether the message loads accounts through address lookup tables.
public List<Instruction> getInstructions()The instructions with their accounts resolved.

Inherited methods

Field details

LEGACY

public static final int LEGACY = -1
The version of a legacy message.

Method details

compile

public static SolanaMessage compile(SolanaAddress payer, List<Instruction> instructions, String recentBlockhash)
A legacy message.

Parameters

payer SolanaAddress
the fee payer, which signs
instructions List<Instruction>
the instructions, run in order
recentBlockhash String
a Base58 blockhash from getLatestBlockhash, or a durable nonce

compileV0

public static SolanaMessage compileV0(SolanaAddress payer, List<Instruction> instructions, String recentBlockhash)
A v0 message with no address lookup tables.

serialize

public byte[] serialize()
The wire form, the bytes every signer signs.

parse

public static SolanaMessage parse(byte[] data)
Reads a message, legacy or v0.

Throws

IllegalArgumentException
for malformed data or an unknown version

getVersion

public int getVersion()
LEGACY or 0.

getAccountKeys

public List<SolanaAddress> getAccountKeys()
The accounts named directly in the message; signers come first.

getFeePayer

public SolanaAddress getFeePayer()
The fee payer, the first account.

getRecentBlockhash

public String getRecentBlockhash()
The Base58 recent blockhash.

getNumRequiredSignatures

public int getNumRequiredSignatures()
How many signatures the transaction carries; the first this many accounts sign.

isSigner

public boolean isSigner(int index)
Whether the account at an index signs.

isWritable

public boolean isWritable(int index)
Whether the message marks the account at an index writable.

hasAddressLookups

public boolean hasAddressLookups()
Whether the message loads accounts through address lookup tables.

getInstructions

public List<Instruction> getInstructions()
The instructions with their accounts resolved.

Throws

IllegalStateException
when an instruction names an account from a lookup table