Solana blockchain SDK for Object Pascal
SolLib4Pascal is a Solana blockchain SDK for Object Pascal, providing JSON RPC clients, wallet management, transaction building, and program interfaces for seamless Solana integration in Object Pascal applications, released under the permissive MIT License.
- Features
- Available Programs
- Getting Started
- Quick Examples
- Running Tests
- Contributing
- Sponsors
- Tip Jar
- License
- Branding
- JSON RPC API -- full coverage of Solana JSON RPC methods
- Streaming JSON RPC API -- WebSocket-based subscription support
- Wallet and accounts -- HD wallet derivation from mnemonic phrases
- Keystore -- secure key storage
- Transaction encoding/decoding -- base64 and wire format support
- Message encoding/decoding -- base64 and wire format support
- Instruction decompilation -- decode instructions back to structured data
- Program interfaces -- typed wrappers for native and SPL programs
System Program
BPF Loader Program
Compute Budget Program | Address Lookup Table Program | Memo Program | Token Program | Token Swap Program | Associated Token Account Program | Shared Memory Program
| Compiler | Minimum Version |
|---|---|
| Delphi | 10.4 or later |
Add the SolLib sources and its dependencies to your compiler search path.
var
LRpc: IRpcClient;
LHttpClient: IHttpApiClient;
LWallet: IWallet;
LFrom: IAccount;
LBlock: IRequestResult<TResponseValue<TLatestBlockHash>>;
LBalance: IRequestResult<TResponseValue<UInt64>>;
LTxBytes: TBytes;
LSignature, LMnemonicWords: string;
LBuilder: ITransactionBuilder;
LPriorityFees: IPriorityFeesInformation;
begin
LHttpClient := THttpApiClient.Create();
LRpc := TClientFactory.GetClient(TCluster.MainNet, LHttpClient);
LMnemonicWords := 'Your Mnemonic Words';
LWallet := TWallet.Create(LMnemonicWords);
LFrom := LWallet.GetAccountByIndex(0);
// Get balance
LBalance := LRpc.GetBalance(LFrom.PublicKey.Key);
if LBalance.WasSuccessful then
Writeln(Format('Balance: %d lamports', [LBalance.Result.Value]))
else
Writeln('Balance: <unavailable>');
LBlock := LRpc.GetLatestBlockHash;
if (LBlock = nil) or (not LBlock.WasSuccessful) or (LBlock.Result = nil) then
raise Exception.Create('Failed to fetch recent blockhash.');
// Build priority fee information
LPriorityFees := TPriorityFeesInformation.Create(
TComputeBudgetProgram.SetComputeUnitLimit(400000), // limit
TComputeBudgetProgram.SetComputeUnitPrice(100000) // price (micro-lamports)
);
// Build transaction (Send a simple memo transaction)
LBuilder := TTransactionBuilders.Legacy;
LTxBytes :=
LBuilder
.SetRecentBlockHash(LBlock.Result.Value.Blockhash)
.SetFeePayer(LFrom.PublicKey)
.SetPriorityFeesInformation(LPriorityFees)
.AddInstruction(TMemoProgram.NewMemo(LFrom.PublicKey, 'Hello from SolLib'))
.Build(LFrom);
LSignature := LRpc.SendTransaction(LTxBytes);
Writeln(Format('Transaction Signature: %s', [LSignature]));
end;TTransactionBuilders.V0 and .V1 build versioned transactions, each exposing only the methods
valid for that version, so invalid combinations don't compile. Version 0 carries address lookup
tables (AddAddressTableLookup); version 1 (SIMD-0385, live on mainnet since epoch 1035) instead
carries the compute-budget and priority-fee settings in the message via SetTransactionConfig, and
allows larger transactions (up to 4096 bytes). Legacy (unversioned) transactions use
TTransactionBuilders.Legacy, shown in the example above.
var
LV0Builder: IVersionedTxV0Builder;
LV1Builder: IVersionedTxV1Builder;
LConfig: TTransactionConfig;
LV0Bytes, LV1Bytes: TBytes;
begin
// Version 0: address lookup tables.
LV0Builder := TTransactionBuilders.V0;
LV0Bytes :=
LV0Builder
.SetRecentBlockHash(LBlockHash)
.SetFeePayer(LFrom.PublicKey)
.AddAddressTableLookup(LLookup)
.AddInstruction(TSystemProgram.Transfer(LFrom.PublicKey, LTo, 1000))
.Build(LFrom);
// Version 1: in-message transaction config (no Compute Budget instructions needed).
// The builder takes ownership of the config passed to SetTransactionConfig.
LConfig := TTransactionConfig.Create;
LConfig.ComputeUnitLimit := UInt32(20000);
LConfig.PriorityFee := UInt64(5000);
LConfig.HeapSize := UInt32(64 * 1024);
LConfig.LoadedAccountsDataSizeLimit := UInt32(64 * 1024);
LV1Builder := TTransactionBuilders.V1;
LV1Bytes :=
LV1Builder
.SetRecentBlockHash(LBlockHash)
.SetFeePayer(LFrom.PublicKey)
.SetTransactionConfig(LConfig)
.AddInstruction(TSystemProgram.Transfer(LFrom.PublicKey, LTo, 1000))
.Build(LFrom);
end;Tests are provided for Delphi.
- Delphi (desktop): Open and run
SolLib.Tests/Delphi.Tests/SolLib.Tests.dprin the IDE.
Additional samples can be found in the SolLib.Examples folder.
Contributions are welcome. Please open an issue for bug reports or feature requests, and submit pull requests.
If you find this library useful and would like to support its continued development, tips are greatly appreciated! 🙏
This project is licensed under the MIT License.