Skip to content

Xor-el/SolLib4Pascal

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

115 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SolLib4Pascal logo

SolLib4Pascal

Solana blockchain SDK for Object Pascal

License: MIT Delphi


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.

Table of Contents

Features

  • 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

Available Programs

Native Programs

System Program

Loader Programs

BPF Loader Program

Solana Program Library (SPL)

Compute Budget Program | Address Lookup Table Program | Memo Program | Token Program | Token Swap Program | Associated Token Account Program | Shared Memory Program

Getting Started

Prerequisites

Compiler Minimum Version
Delphi 10.4 or later

Compile-Time Dependencies

Installation

Add the SolLib sources and its dependencies to your compiler search path.

Quick Examples

Fetch Balance and Send a Memo

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 := TTransactionBuilder.Create;
  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;

Running Tests

Tests are provided for Delphi.

  • Delphi: Open and run SolLib.Tests/Delphi.Tests/SolLib.Tests.dpr in the IDE.

Additional samples can be found in the SolLib.Examples folder.

Contributing

Contributions are welcome. Please open an issue for bug reports or feature requests, and submit pull requests.

Sponsors

Tip Jar

If you find this library useful and would like to support its continued development, tips are greatly appreciated! 🙏

Cryptocurrency Wallet Address
Bitcoin Bitcoin (BTC) bc1quqhe342vw4ml909g334w9ygade64szqupqulmu
Ethereum Ethereum (ETH) 0x53651185b7467c27facab542da5868bfebe2bb69
Solana Solana (SOL) BPZHjY1eYCdQjLecumvrTJRi5TXj3Yz1vAWcmyEB9Miu

License

This project is licensed under the MIT License.

About

Solana for Modern Object Pascal

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors