solana_kit_transactions 0.9.1
solana_kit_transactions: ^0.9.1 copied to clipboard
Transaction compilation and signing for the Solana Kit Dart SDK.
solana_kit_transactions #
Compile, sign, encode, and decode Solana transactions. Wrap a compiled message with signatures, verify completeness, and produce the base64 wire format that the RPC sendTransaction endpoint accepts.
Installation #
Install the package directly:
dependencies:
"solana_kit_transactions": ^0.9.1
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_transactions
- API reference: https://pub.dev/documentation/solana_kit_transactions/latest/
- Workspace docs: https://openbudgetfun.github.io/solana_kit/
- Package catalog entry: https://openbudgetfun.github.io/solana_kit/reference/package-catalog#solana_kit_transactions
- Source code: https://github.com/openbudgetfun/solana_kit/tree/main/packages/solana_kit_transactions
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.
Compile a transaction for signing #
Once a transaction message has a fee payer, lifetime, and instructions, compile it into the wire-ready transaction shape that signers and senders consume.
import 'dart:typed_data';
import 'package:solana_kit_addresses/solana_kit_addresses.dart';
import 'package:solana_kit_instructions/solana_kit_instructions.dart';
import 'package:solana_kit_transaction_messages/solana_kit_transaction_messages.dart';
import 'package:solana_kit_transactions/solana_kit_transactions.dart';
void main() {
final message = createTransactionMessage(version: TransactionVersion.v0)
.withFeePayer(const Address('11111111111111111111111111111111'))
.withBlockhashLifetime(
BlockhashLifetimeConstraint(
blockhash: '11111111111111111111111111111111',
lastValidBlockHeight: BigInt.zero,
),
)
.appendInstruction(
Instruction(
programAddress: const Address('11111111111111111111111111111111'),
accounts: const [
AccountMeta(
address: Address('11111111111111111111111111111111'),
role: AccountRole.readonly,
),
],
data: Uint8List(0),
),
);
final transaction = compileTransaction(message);
print(transaction.signatures.length);
}
Compilation is the boundary where account ordering, signer sets, and lifetime constraints are frozen into the bytes that will actually be signed.
Usage #
Sign a transaction #
signTransaction adds a signature for a given signer address to the transaction's signature map. Call it once per signer.
Future<void> main() async {
// After compiling a message and creating a key pair signer:
// final message = createTransactionMessage(version: TransactionVersion.v0)
// .withFeePayer(signer.address)
// .withBlockhashLifetime(...)
// .appendInstruction(...);
// final transactionWithLifetime = compileTransaction(message);
// final signed = await signTransaction(transactionWithLifetime, signer);
}
Get the signature #
getSignatureFromTransaction extracts the fee payer's signature as a Signature object. The transaction must be fully signed by the fee payer.
void main() {
// After signing, extract the fee payer's signature.
// final sig = getSignatureFromTransaction(signedTransaction);
// print(sig.value);
}
Verify signatures #
isFullySignedTransaction checks whether every required signer has a non-null signature in the map. partiallySignTransaction adds a signature without requiring all signers to be present.
Encode and decode #
getTransactionEncoder and getTransactionDecoder return codec objects from solana_kit_codecs_core. getTransactionCodec returns a combined encoder/decoder. getBase64EncodedWireTransaction produces the base64 string accepted by sendTransaction.
void main() {
// After signing, encode the transaction for the RPC.
// final base64 = getBase64EncodedWireTransaction(signedTransaction);
// Pass `base64` to rpc.sendTransaction.
}
Lifetime constraints #
TransactionBlockhashLifetime and TransactionDurableNonceLifetime are the two sealed subtypes of TransactionLifetimeConstraint. Guard functions check which kind a transaction carries:
isTransactionWithBlockhashLifetime(transaction)returnstrueif the lifetime is blockhash-based.isTransactionWithDurableNonceLifetime(transaction)returnstrueif the lifetime is nonce-based.
Transaction size helpers #
getTransactionSize estimates the serialized size of a compiled transaction message. assertTransactionIsWithinSizeLimit throws if the message exceeds the network limit.
Example #
Use example/main.dart as a runnable starting point for solana_kit_transactions.
- Import path:
package:solana_kit_transactions/solana_kit_transactions.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.