This is the Scala library for the IOTA Core APIs. It's a simple scala wrapper around IOTA and allows to connect to a local or a remote IOTA node easily using it's Scala API interface.
The Scala wrapper around IOTA is designed to be thread-safe and kept as simple as possible in order to be easily maintainable, accordingly with the ongoing natural evolution of IOTA’s API. It provides the flexability to choose between API backends like OkHTTP
, Akka HTTP
and other native STTP
syncronous and asyncronous API Backends depending on the concurrency needs of the Application. This unlocks the world of scala for IOTA Core.
It should be noted that the Scala Library as it stands right now is an early release. There might be some unexpected results. Please let us know here.
The SOTA library is available on jitpack.io.
To use the SOTA library in your SBT build add this to your root build.sbt
file
resolvers += "jitpack" at "https://jitpack.io"
Add this library dependency in your build.sbt
file
libraryDependencies += "com.github.ahab94" % "iota.lib.scala" % "0.3"
After you've successfully installed the library dependency, it is fairly easy to get started by simply creating a new IotaClient instance.
val iotaClient = new IotaClient() //This will hit http://localhost:14625
Connecting to your device's local node with the default settings and fetching the node info is quite easy...
val iotaCore = new IotaClient(IotaClientConfig(protocol = "http", host = "localhost", port = 14265))
val nodeInfo = iotaCore.getNodeInfo
For Asynchronous API calls
val iotaAsyncClient = new IotaAsyncClient()
val nodeInfo: Future[GetNodeInfoResponse] = iotaAsyncClient.getNodeInfo
Specifying host
, protocol
and port
is done in similar fashion.
val iotaAsyncClient = new IotaAsyncClient(IotaClientConfig(protocol = "http", host = "localhost", port = 14265))
val nodeInfo: Future[GetNodeInfoResponse] = iotaAsyncClient.getNodeInfo
This Iota Client Library supports the flexibility of using different API Backends of varying concurrency needs of different Applications.
Supported API Backends are listed below
Custom-Backend | Type | Class | Response wrapper |
---|---|---|---|
Akka-Http | Async | AkkaHttpBackend() |
scala.concurrent.Future |
OkHttp-Future-Backend | Async | OkHttpFutureBackend() |
scala.concurrent.Future |
OkHttp-Backend | Sync | OkHttpBackend() |
None (Id) |
Using a custom api backend is very simple...
Lets say you want to use OkHttp Async Backend
import com.softwaremill.sttp.okhttp.OkHttpFutureBackend
val iotaAsyncClient = new IotaAsyncClient(asyncApiBackend = Some(OkHttpFutureBackend()))
or Akka-Http Async Backend
import com.softwaremill.sttp.akkahttp.AkkaHttpBackend
val iotaAsyncClient = new IotaAsyncClient(asyncApiBackend = Some(AkkaHttpBackend()))
or OkHttp Sync Backend
import com.softwaremill.sttp.okhttp.OkHttpBackend
val iotaClient = new IotaClient(customApiBackend = Some(OkHttpBackend()))
Switching API Backends is that simple...