An open API service indexing awesome lists of open source software.

https://github.com/maxmmin/sol4j

Java client for Solana web3 RPC API
https://github.com/maxmmin/sol4j

blockchain java library rpc rpc-client sol sol4j solana solana-web3 solana4j web3

Last synced: 3 months ago
JSON representation

Java client for Solana web3 RPC API

Awesome Lists containing this project

README

          

Sol4j 👾

[![License: MIT](https://img.shields.io/badge/License-MIT-blue)](https://github.com/maxmmin/sol4j/blob/dev/LICENSE)
![Java required version: 11](https://img.shields.io/badge/Java-11+-yellow)
[![Solana Badge](https://img.shields.io/badge/Solana-%23000000?logo=solana&logoColor=white)](https://solana.com/docs/rpc)

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

```xml

io.github.maxmmin
sol4j
1.3.91

```

Creating gateway

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

Creating RPC Client

```java
RpcClient client = RpcClient.create(rpcGateway);
```

Making requests

```java
List nodes = client.getClusterNodes().send();
```

Multiple encodings support for specific methods

```java
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

```java
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();
```