RPC Client Libraries [Community Bounty]

Description/Bounty

The RPC API allows developers to connect to a Nimiq node from their favorite language. To facilitate their work, we want to create RPC client libraries for various popular languages:

  • Python - 250’000 NIM :white_check_mark: - delivered by @rraallvv
    • Already partially started, linked as an example below, but needs to be completed.
    • nimiq-api-python could use some polishing. A lot of RPC methods may be missing and the documentation is not very exhaustive.
    • Also a release to the package index would be nice.
  • PHP - 600’000 NIM :white_check_mark: - delivered by @mario
  • Swift for iOS 600’000 NIM :white_check_mark: - delivered by @rraallvv
  • Java or Kotlin for Android and standalone Java applications 600’000 NIM :white_check_mark: - delivered by @tomkha
  • Go 400’000 NIM :white_check_mark: - delivered by @redmaner
  • Ruby 400’000 NIM :white_check_mark: - delivered by @emile
  • Rust 400’000 NIM :white_check_mark: - delivered by @Stefan
  • C# 400’000 NIM :white_check_mark: - delivered by @rraallvv
  • Suggest more

Suggested Solution

The code for the JavaScript RPC Client can be found here. The suggested solution is to port this code to the chosen language.

An example for Python can be found here: https://github.com/jgraef/nimiq-api-python

Completion Criteria

The proposal is completed when

  • The library has been created natively in the chosen language.
  • All calls to the RPC client using the new library work successfully against core-js.
  • Complete documentation: in code and as /docs/ using e.g. markdown for GitHub Pages
  • Finally, send a PR to the appropriate repo in https://github.com/nimiq-community for review. If the repo for your language does not exist yet, contact @svub or @Richy.
  • The submission is complete when the code has been merged.
6 Likes

Go RPC library proposal

I have implemented the Nimiq RPC specification as defined here in native GO. You will find my library here.

Docs

The documentation can be found on GoDoc (see link in repository README). Because GoDoc is the general way of documenting go libraries I have refrained from documenting the library in a separate /doc/ folder.

Testing

The library has been tested on a test core-js node. It might require some futher testing, as the SubmitBlock() was quite difficult to test :slight_smile: . My test code, that uses the library, is part of the repository in the /example folder.

4 Likes

Java version can be found here https://github.com/tomkha/nimiq-rpc-client/

5 Likes

Tested on mainnet seednode: http://seed01.nimiq.ovh:8648/

1 Like

Thanks a lot for helping people to test :+1:

Does yours work for Android?

I haven’t checked yet, targeted standalone Java first.

1 Like

Maybe add C# to the list of languages?

2 Likes

A Rust client is WIP

4 Likes

I tried to create a bit more complicated application - sent an offline transaction from my mobile:


so yeah, the RPC client works fine in Android.

7 Likes

An approach that I’ve seen being used in many game engines with support for scripting languages is having a “bindings generator” script that can be run to generate a module that can be imported from the scripting language.

For instance:

Since the functionality intended to be packed as a module can be added to a binary library, and most compilers or interpreters support linking or loading binary libraries, the bindings generator would only need to parse the public methods in the binary library from the source code - or in the case of the Nimiq RPC Client only those methods supported by the server - and then automatically generate the interface that is exposed in the module to any program written that particular programing language.

Thus, packing the Nimiq RPC client functionality into a library with support for most popular mobile and desktop platforms would allow for adding that functionality to any cross-platform framework (NativeScript, ReactNative, Flutter, Xamarin, etc.), or game engine/framework (Cocos2D, Godot, Unity, Unreal Engine, etc.).

Sounds cool but would this meet the first Completion Criteria of the bounty?

  • The library has been created natively in the chosen language.

@Stefan , thanks for pointing that out, although I’m not sure if loading a binary library doesn’t count as native functionality for a given language.

The way I interpret it is that the source code of the library has to be the same as the language you can use it. So for example, I create a binary from Rust which you can include within Swift doesn’t meet up with the criteria. Again that’s what I think :slight_smile:

Maybe somebody else could elaborate on this

I see your point. Maybe a Nimiq RPC Client isn’t too complicated as to require a “core” binary library and an “interface” generator for all the supported languages, but still parsing the supported methods in the RPC server cold be done with a script so that updating the client in any language could be as easily done as running a script, but maybe it’s just me trying to make things a bit too complicated again :sweat_smile:

I understand the reason why you want to take this approach. It could greatly increase the amount of language you could generate a client for

1 Like

Nimiq Rust RPC client

Nimiq Rust RPC client: Github link.
The client has been published to crates.io already: link.

The repository already provides some examples. Full documentation can be found at docs.rs since that’s the standard location to host your Rust documentation rather than having a /docs/ folder.

Edit: some enhancements to the library are on its way:

  • properly deserialize error responses from the server and use error codes specified in the jsonrpc2 specification
  • username/password support
  • verify jsonrpc id

Edit 2:
The enhancements stated above are actually implemented.

5 Likes

I suggest a bounty for the Nim programming language.

4 Likes

Just released a new version of the Rust client, including support for username/password authentication :slight_smile:

5 Likes

How about Haxe?

It compiles (or rather transpiles) to a bunch of languages.

1 Like