Java library for Electrum API

This package was developed for sending and receiving RPC requests. It is using jackson library to convert between java and json objects.

It has three sub-packages

The most of the method classes have their own request classes where are kept the parameters and response class which is a method’s return type.

You can download maven project here.

Click the Code button and then download zip.

Unzip it to workspace directory and import as maven project.

The only SendRequest class’ send() method sends request to Electrum so you need to configure it in accordance your Electrum RPC configuration.

package electrum.methods;

import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpRequest.BodyPublishers;
import java.util.Base64;

public class SendRequest {
	
	public synchronized InputStream send(String json) {
		HttpClient client = HttpClient.newHttpClient();
	
		// replace to your rpcuser and rpcpassowrd
		String credentials = "user" + ":" + "t";
		String auth = "Basic " + Base64.getEncoder().encodeToString(credentials.getBytes());
		HttpRequest request = HttpRequest.newBuilder()
	    .uri(URI.create("http://127.0.0.1:7777"))
	    .POST(BodyPublishers.ofString(json))
	    .setHeader("Content-Type", "application/x-www-form-urlencoded")
	    .setHeader("Authorization", auth)
	    .build();
		
		HttpResponse<InputStream> response = null;
		try {
			response = client.send(request, HttpResponse.BodyHandlers.ofInputStream());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return response.body();
	}
}

There are some examples in main().

package electrum.demo;



import java.util.Arrays;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import electrum.methods.Deserialize;
import electrum.methods.GetFeeRate;
import electrum.methods.GetOnChainHistory;
import electrum.methods.ListAddresses;
import electrum.methods.PayTo;
import electrum.methods.PayToMany;
import electrum.response.Output;
import electrum.response.Result;
import electrum.response.Transaction;


public class Main {

	public static void main(String[] args)  {
		
		ObjectMapper objectMapper = new ObjectMapper();
		
		//getting feerate
		int feerate = new GetFeeRate().getFeeRate();
		System.out.println("feerate = "+ feerate);
		
		//getting history
		Result result = new GetOnChainHistory().getResult();
		System.out.println("wallet balance = "+result.getSummary().getBegin().getBTC_balance()+" date = "+result.getSummary().getBegin().getDate());
		System.out.println("wallet balance = "+result.getSummary().getEnd().getBTC_balance()+" date = "+result.getSummary().getEnd().getDate());
		System.out.println("btc_incoming = "+result.getSummary().getFlow().getbTC_incoming());
		Transaction[] transactions = result.getTransactions();
		for(Transaction transaction : transactions) {
			System.out.println("bc_value = "+transaction.getBc_value());
			System.out.println("incoming = "+transaction.getIncoming());
			System.out.println("conformations = "+transaction.getConfirmations());
			System.out.println("txid = "+transaction.getTxid());
			for(Output output : transaction.getOutputs()) {
				System.out.println("address = " + output.getAddress());
			}
			System.out.println("Bc_value = "+transaction.getBc_value());
		}
		
		//deserialisig the code which you get when use payTo() or payToMany() 
		Output[] outputs = new Deserialize().deserialize("0200000000010126a65160de2bcc1e46308209670ed320ff23550fdb31b96a661608ede6a49d000000000000fdffffff02ac260000000000001600140ab8ce8b4c63186710c90ed4cbb14f64fecac7e310270000000000001600144fda16bb1c1d870875f54b27d705c03f89f92d4702473044022067ff1cccfaec698aeb81b74c9ff5872a4769e2e705865ad1dcbee78ce37e8cea02202c194a4d5b4e54f396c5482523fe001e31acbd75e966c4b4d29cd931df6c155a0121025ad75aac47e461cfebc26e2d3d1a53d90cc4f48556e1a89ceda06206f61a6d44493e2500");
		for(Output output : outputs) {
			System.out.println("address = " + output.getAddress());
			//System.out.println("value_sats = " + output.getValue_sats());
		}
		
		// paying
		String txid;
		String[][] outputs1 = {{"tb1qq43jsy5q46sf3wljg8l7luqrjwjczeqhywjjfj", "0.0008"}, {"tb1qzs6fq7j9wn4x4w9daruvke5793fkw4yty03u5f", "0.0009"}, {"tb1q3pctvpvyzm799zmtw894achdxdw0l86zpcceu2", "0.0006"}};
		
		txid = new PayToMany().payToMany(outputs1);
		txid = new PayToMany().payToMany(outputs1);
		System.out.println(txid);
		
		txid = new PayTo().payTo("tb1qy8y23vgyzkgq438l4xpy0kp6dscp0yvkxt224l", 0.0001);
		
		System.out.println(txid);
		
		// getting electrum addresses
		String[] strings = new ListAddresses().listAddresses();
		System.out.println(Arrays.toString(strings));
		
		
		try {
			System.out.println(objectMapper.writeValueAsString(transactions[0].getOutputs()));
		} catch (JsonProcessingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}

21 responses to “Java library for Electrum API”

  1. lodibet says:

    Keno’s probability is fascinating – understanding patterns can subtly improve your game! I’ve been exploring platforms like lodibet club, and their app seems to make tracking numbers easier – a nice touch for serious players!

  2. ph978casino says:

    Smart bankroll management is key, even with accessible platforms. Seeing the emphasis on KYC & secure logins at ph978 casino login is reassuring – compliance matters! Just remember responsible gaming always.

  3. ph987 says:

    Just scratched into the world of online gaming and PH987 is a real gem! The slots and live dealers are top-notch. Check out ph978 for an epic gaming rush!

  4. fil777 says:

    Really insightful article! Seeing more strategic approaches to esports is awesome. Managing risk & maximizing returns-sounds like the philosophy behind a solid platform like fil777 app download. Definitely checking that out too! 🔥

  5. ph978casino says:

    Roulette’s allure is fascinating – the probabilities are deceptively simple, yet endlessly complex! Seeing platforms like ph978 casino games prioritize compliance & secure access (KYC is key!) is reassuring for players in the Philippines. It’s good to see responsible gaming gaining traction.

  6. ph987 says:

    If you’re into slots and live games, PH987 offers a thrilling mix of excitement and top-notch security. The PH987 login process is smooth, making it easy to jump into the action. Definitely worth checking out!

  7. legendlink says:

    Responsible gaming is key, folks! It’s easy to get carried away. Seeing platforms like legend link games focusing on secure logins & localized options (like Maya!) is a good sign. Remember to set limits!

  8. wjpeso says:

    That’s a great point about longshot value – often overlooked! Seeing platforms like wjpeso slot prioritize secure, modern tech and fast verification (KYC seems quick!) is encouraging for Philippine players. Definitely boosts trust!

  9. phlaro says:

    Interesting read! Security in online gaming is crucial, especially with mobile access. Seeing platforms like Phlaro prioritize KYC & fast deposits is good. Check out phlaro download apk for a modern experience, but always gamble responsibly!

  10. ph978 says:

    Interesting read! Transparency in gaming is key, and platforms like PH978 seem to be prioritizing that-especially with quick deposits via GCash. Check out the ph978 link for a data-driven experience – security & speed are a great combo!

  11. ph789 says:

    That’s a great point about dealer interaction – it really makes or breaks a live game! Seeing how PH987 focuses on that social aspect, creating a true casino feel, is impressive. It’s not just about the tech, it’s the vibe!

  12. gamesphp says:

    Really enjoying the shift towards provably fair gaming! It’s cool seeing platforms like gamesphp club offer that transparency, plus easy funding with GCash & PayMaya is a huge win for Filipino players. Definitely checking out their slots!

  13. bonos777club says:

    bonos777club, sounds exclusive! Gonna see if I can claim my place amongst the winners! What’s everyone’s experience here been? bonos777club

  14. ph799ph says:

    That anticipation of a win is huge in poker, and seems key to a good gaming experience. Quick access is vital – I saw ph799 ph club offers instant registration & deposits, streamlining the fun! Definitely a plus for serious players.

  15. bbjl says:

    Tight play pre-flop is crucial in tournaments, especially with escalating blinds. Seeing platforms like bbjl app download offer diverse games makes adapting strategy easier. Solid bankroll management is key, though! 😉

  16. buenas says:

    RTP analysis is key to enjoying slots – understanding those percentages really helps! Seeing platforms like buenas com cater specifically to the Philippines market with local options is smart. Accessibility via app & APK is a plus!

  17. 992bet77 says:

    What’s up, found 992bet77 randomly browsing. It’s alright. See if it clicks with you! 992bet77

  18. phpfamous says:

    Keno’s all about probability, right? Seeing platforms like phpfamous app casino focus on solid game mechanics & security is impressive – crucial for building trust & a fair playing field! Strategic registration seems key there too.

  19. Downloaded a game from 99abgamedownload. It downloaded fine, games run smoothly, no real issues so far. Here’s how to get it: 99abgamedownload

  20. 188V says:

    Thông tin cá nhân của người chơi được bảo mật với bất kỳ bên thứ ba nào khi không có sự đồng ý của bạn. 188V Mọi dữ liệu người dùng cung cấp khi đăng ký tài khoản hoặc thực hiện giao dịch đều được lưu trữ an toàn chỉ được sử dụng cho mục đích duy nhất là phục vụ khách hàng tốt hơn. TONY01-29O

  21. Sau khi cài đặt ứng dụng, mở ứng dụng và chọn “Đăng ký”. asia slot365 login Bạn nên đủ các thông tin yêu cầu bao gồm tên đăng nhập, mật khẩu, địa chỉ email và số điện thoại khi bạn thực hiện đăng ký tài khoản mới. Thông tin chính xác thì quá trình xác minh tài khoản diễn ra thuận lợi. TONY02-02O

Leave a Reply to buenas Cancel reply

Your email address will not be published. Required fields are marked *