solana_kit_transaction_messages 0.9.3
solana_kit_transaction_messages: ^0.9.3 copied to clipboard
Building transaction messages for the Solana Kit Dart SDK.
solana_kit_transaction_messages #
Build, compile, and decompile Solana transaction messages. Create an empty message, set a fee payer and lifetime, append instructions, then compile it for signing.
Installation #
Install the package directly:
dependencies:
"solana_kit_transaction_messages": ^0.9.3
If your app uses several Solana Kit packages together, you can also depend on the umbrella package instead:
dart pub add solana_kit
Inside this monorepo, Dart workspace resolution uses the local package automatically.
Documentation #
- Package page: https://pub.dev/packages/solana_kit_transaction_messages
- API reference: https://pub.dev/documentation/solana_kit_transaction_messages/latest/
- Workspace docs: https://openbudgetfun.github.io/solana_kit/
- Package catalog entry: https://openbudgetfun.github.io/solana_kit/reference/package-catalog#solana_kit_transaction_messages
- Source code: https://github.com/openbudgetfun/solana_kit/tree/main/packages/solana_kit_transaction_messages
For architecture notes, getting-started guides, and cross-package examples, start with the workspace docs site and then drill down into the package README and API reference.
Usage #
Transaction messages are assembled incrementally. Create an empty message, set the fee payer, set a lifetime constraint using a recent blockhash, and append one or more instructions.
import 'package:solana_kit_addresses/solana_kit_addresses.dart';
import 'package:solana_kit_transaction_messages/solana_kit_transaction_messages.dart';
void main() {
final message = createTransactionMessage(version: TransactionVersion.v0)
.withFeePayer(const Address('11111111111111111111111111111111'))
.withBlockhashLifetime(
BlockhashLifetimeConstraint(
blockhash: '11111111111111111111111111111111',
lastValidBlockHeight: BigInt.zero,
),
);
print(message.feePayer);
}
This separation keeps transaction construction explicit and makes it easier to reason about fee payment, expiry, and instruction ordering. The .withFeePayer(), .withBlockhashLifetime(), and .appendInstruction() extension methods build on the same underlying model as the standalone functions setTransactionMessageFeePayer, setTransactionMessageLifetimeUsingBlockhash, and appendTransactionMessageInstruction.
Compile for signing #
Once a message has a fee payer, lifetime, and instructions, compile it into the wire-ready format that signers and senders consume.
import 'package:solana_kit_addresses/solana_kit_addresses.dart';
import 'package:solana_kit_transaction_messages/solana_kit_transaction_messages.dart';
void main() {
final message = createTransactionMessage(version: TransactionVersion.v0)
.withFeePayer(const Address('11111111111111111111111111111111'))
.withBlockhashLifetime(
BlockhashLifetimeConstraint(
blockhash: '11111111111111111111111111111111',
lastValidBlockHeight: BigInt.zero,
),
);
final compiled = compileTransactionMessage(message);
print(compiled.header.numSignerAccounts);
}
Compilation is lossy: you cannot fully reconstruct a source message from a compiled message without extra information. Decompilation preserves the transaction version, all instructions, account roles, and v1 resource and priority fee configuration. Supply lookup table contents and the last valid block height when needed.
Signer accounts always remain static, even if an instruction supplies lookup metadata for them. Only v0 messages use address lookup tables; legacy and v1 messages materialize those accounts as static accounts while preserving their roles.
Pipe extension #
The Pipe<T> extension adds a .pipe() method to every Dart value, enabling fluent left-to-right pipeline composition. This is the same extension previously exported from solana_kit_functional (now deprecated).
import 'package:solana_kit_transaction_messages/solana_kit_transaction_messages.dart';
void main() {
final result = 'hello'
.pipe((v) => v.toUpperCase())
.pipe((v) => '$v!');
print(result); // HELLO!
}
API reference #
Message construction #
createTransactionMessage({required TransactionVersion version})creates an empty message.setTransactionMessageFeePayer(Address, TransactionMessage)returns a copy with the fee payer set.setTransactionMessageLifetimeUsingBlockhash(String, TransactionMessage)returns a copy with a blockhash lifetime.appendTransactionMessageInstruction(Instruction, TransactionMessage)returns a copy with the instruction appended.appendTransactionMessageInstructions(List<Instruction>, TransactionMessage)returns a copy with multiple instructions appended.
Fluent extension methods #
These wrap the standalone functions above for method-chaining style:
.withFeePayer(Address).withBlockhashLifetime(BlockhashLifetimeConstraint).appendInstruction(Instruction).appendInstructions(List<Instruction>)
Compilation and decompilation #
compileTransactionMessage(TransactionMessage)compiles a message for signing.decompileTransactionMessage(CompiledTransactionMessage)reverses compilation back to aTransactionMessage.
Pipe #
Pipe<T>onTaddsR pipe<R>(R Function(T) transform).
Example #
Use example/main.dart as a runnable starting point for solana_kit_transaction_messages.
- Import path:
package:solana_kit_transaction_messages/solana_kit_transaction_messages.dart - This section is centrally maintained with
mdtto keep package guidance aligned. - After updating shared docs templates, run
docs:updatefrom the repo root.
Maintenance #
- Validate docs in CI and locally with
docs:check. - Keep examples focused on one workflow and reference package README sections for deeper API details.