solana_kit_token_2022 0.8.0
solana_kit_token_2022: ^0.8.0 copied to clipboard
SPL Token 2022 and Associated Token Account client for the Solana Kit Dart SDK. Generated from the upstream Codama IDL with focused ergonomic helpers.
solana_kit_token_2022 #
Token-2022 extension-aware instruction builders, account decoders, codecs, and helpers for the Solana Kit Dart SDK. ATA APIs from solana_kit_associated_token_account are re-exported for convenience.
Installation #
Install the package directly:
dependencies:
"solana_kit_token_2022": ^0.8.0
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.
Usage #
Compute the on-chain byte size for a mint with extensions before creating the account:
import 'package:solana_kit_addresses/solana_kit_addresses.dart';
import 'package:solana_kit_token_2022/solana_kit_token_2022.dart';
void main() {
final size = getMintSize([
TransferFeeConfig(
transferFeeConfigAuthority: Address(
'TkQKURgZR8bWbYq7bH6KcXQ3Pnt3D3qWbh4StE5jQ2Sf',
),
withdrawWithheldAuthority: Address(
'9xqYQKFSR3m3kqgT5sYRH7gH3j7Ab8F2PWasmY3dGkDm',
),
withheldAmount: BigInt.zero,
olderTransferFee: TransferFee(
epoch: BigInt.from(0),
maximumFee: BigInt.from(50000),
transferFeeBasisPoints: 100,
),
newerTransferFee: TransferFee(
epoch: BigInt.from(0),
maximumFee: BigInt.from(50000),
transferFeeBasisPoints: 100,
),
),
]);
print(size);
final tokenSize = getTokenSize([
TransferFeeAmount(withheldAmount: BigInt.from(50000)),
]);
print(tokenSize);
}
Get the pre-initialize instructions that some extensions require before the mint itself:
import 'package:solana_kit_addresses/solana_kit_addresses.dart';
import 'package:solana_kit_token_2022/solana_kit_token_2022.dart';
void main() {
const mint = Address('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v');
const payer = Address('11111111111111111111111111111111');
const authority = Address(
'5z3Y2Y6sxR28F9FJ6YqnbLBoz2tQqNqKVBwShck8KJ5W',
);
final preIx = getPreInitializeInstructionsForMintExtensions(
mint: mint,
extensions: [
TransferFeeConfig(
transferFeeConfigAuthority: authority,
withdrawWithheldAuthority: authority,
withheldAmount: BigInt.zero,
olderTransferFee: TransferFee(
epoch: BigInt.from(0),
maximumFee: BigInt.from(50000),
transferFeeBasisPoints: 100,
),
newerTransferFee: TransferFee(
epoch: BigInt.from(0),
maximumFee: BigInt.from(50000),
transferFeeBasisPoints: 100,
),
),
],
);
print(preIx.length);
print(payer);
}
Use the generated instruction builders directly. The programAddress parameter targets Token-2022 instead of classic Token:
import 'package:solana_kit_addresses/solana_kit_addresses.dart';
import 'package:solana_kit_token_2022/solana_kit_token_2022.dart';
void main() {
const mint = Address('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v');
const token = Address('11111111111111111111111111111112');
const mintAuthority = Address(
'5z3Y2Y6sxR28F9FJ6YqnbLBoz2tQqNqKVBwShck8KJ5W',
);
final ix = getMintToInstruction(
programAddress: token2022ProgramAddress,
mint: mint,
token: token,
mintAuthority: mintAuthority,
amount: BigInt.from(1000000000),
);
print(ix.programAddress);
}
Key APIs #
getMintSize,getTokenSizefor account sizing withExtensioninstancesgetPreInitializeInstructionsForMintExtensionsfor pre-mint setupgetMintToInstruction,getTransferInstruction, and other generated builders (passtoken2022ProgramAddress)token2022ProgramAddressandtoken2022ProgramAddressObjectconstants
Re-exports #
The full solana_kit_associated_token_account API surface is re-exported so callers can access ATA PDA helpers and instruction builders without adding a separate dependency.
Upstream reference #
Generated layer mirrors solana-program/token-2022 at js@v0.16.0.