Skip to content
This repository was archived by the owner on Jun 24, 2026. It is now read-only.

Latest commit

History

434 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Sol4j 👾

License: MITJava required version: 11Solana Badge

Pure java lib for interacting with Solana RPC API.

The library supports both legacy and versioned transactions and provides a set of core programs for interacting with the Solana blockchain.

Requirements

- Java 11+

Dependencies

  • OkHttp
  • Jackson
  • net.i2p.crypto.eddsa

OutOfBox supported methods

HTTP
Under active development

  • getAccountInfo ✅
  • getBalance ✅
  • getBlock ✅
  • getBlockCommitment ✅
  • getBlockHeight ✅
  • getBlockProduction ✅
  • getBlocks ✅
  • getBlocksWithLimit ✅
  • getBlockTime ✅
  • getClusterNodes ✅
  • getEpochInfo ✅
  • getEpochSchedule ✅
  • getFeeForMessage ✅
  • getFirstAvailableBlock ✅
  • getGenesisHash ✅
  • getHealth ✅
  • getHighestSnapshotSlot ✅
  • getIdentity ✅
  • getInflationGovernor ✅
  • getInflationRate ✅
  • getInflationReward ✅
  • getLargestAccounts ✅
  • getLatestBlockhash ✅
  • getLeaderSchedule ✅
  • getMaxRetransmitSlot ✅
  • getMaxShredInsertSlot ✅
  • getMinimumBalanceForRentExemption ❌
  • getMultipleAccounts ✅
  • getProgramAccounts ✅
  • getRecentPerformanceSamples ❌
  • getRecentPrioritizationFees ❌
  • getSignaturesForAddress ✅
  • getSignatureStatuses ❌
  • getSlot ❌
  • getSlotLeader ❌
  • getSlotLeaders ❌
  • getStakeMinimumDelegation ✅
  • getSupply ❌
  • getTokenAccountBalance ✅
  • getTokenAccountsByDelegate ✅
  • getTokenAccountsByOwner ✅
  • getTokenLargestAccounts ✅
  • getTokenSupply ❌
  • getTransaction ✅
  • getTransactionCount ✅
  • getVersion ✅
  • getVoteAccounts ❌
  • isBlockhashValid ✅
  • minimumLedgerSlot ✅
  • requestAirdrop ❌
  • sendTransaction ✅
  • simulateTransaction ❌
WebSocket
Not implemented yet

Getting started

Installation

<dependency>
<groupId>io.github.maxmmin</groupId>
<artifactId>sol4j</artifactId>
<version>1.3.91</version>
</dependency>

Creating gateway

RpcGatewayrpcGateway = HttpRpcGateway.create("https://api.mainnet-beta.solana.com");

Creating RPC Client

RpcClientclient = RpcClient.create(rpcGateway);

Making requests

List<SolanaNodeInfo> nodes = client.getClusterNodes().send();

Multiple encodings support for specific methods

GetTransactionRequesttxRequest = client.getTransaction(txSignature);
vardefaultEncodedTx = txRequest.send();
BaseEncConfirmedTransactionbase58EncodedTx = txRequest.base58();
BaseEncConfirmedTransactionbase64EncodedTx = txRequest.base64();
JsonConfirmedTransactionjsonEncodedTx = txRequest.json();
JsonParsedConfirmedTransactionjsonParsedEncTx = txRequest.jsonParsed();

Transferring lamports via SystemProgram

Accountsender = Account.fromSecretKey(secretKey);
PublicKeyreceiverPubkey = PublicKey.fromBase58("2ZqPxLUgUFLCyQdqokCNJqnhb4kLY7Bn8T28ABQAjfq4");
BigIntegerlamports = BigInteger.valueOf(3000);
MessagetxMessage = Message.builder()
.addInstruction(SystemProgram.transfer(newSystemProgram.TransferParams(sender.getPublicKey(), receiverPubkey, lamports)))
.setBlockHash(rpcClient.getLatestBlockhash().send().getBlockhash())
.setFeePayer(sender.getPublicKey())
.build();
Transactiontransaction = Transaction.build(txMessage, sender);
StringtxId = rpcClient.sendTransaction(transaction).base64();

Releases

Packages

Used by

Contributors

Languages