Skip to content

maxmmin/sol4j

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sol4j 👾

License: MIT Java required version: 11 Solana 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

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

Creating RPC Client

RpcClient client = RpcClient.create(rpcGateway);

Making requests

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

Multiple encodings support for specific methods

GetTransactionRequest txRequest = client.getTransaction(txSignature);

var defaultEncodedTx = txRequest.send();
BaseEncConfirmedTransaction base58EncodedTx = txRequest.base58();
BaseEncConfirmedTransaction base64EncodedTx = txRequest.base64();
JsonConfirmedTransaction jsonEncodedTx = txRequest.json();
JsonParsedConfirmedTransaction jsonParsedEncTx = txRequest.jsonParsed();

Transferring lamports via SystemProgram

Account sender = Account.fromSecretKey(secretKey);
PublicKey receiverPubkey = PublicKey.fromBase58("2ZqPxLUgUFLCyQdqokCNJqnhb4kLY7Bn8T28ABQAjfq4");
BigInteger lamports = BigInteger.valueOf(3000);

Message txMessage = Message.builder()
        .addInstruction(SystemProgram.transfer(new SystemProgram.TransferParams(sender.getPublicKey(), receiverPubkey, lamports)))
        .setBlockHash(rpcClient.getLatestBlockhash().send().getBlockhash())
        .setFeePayer(sender.getPublicKey())
        .build();

Transaction transaction = Transaction.build(txMessage, sender);
String txId = rpcClient.sendTransaction(transaction).base64();