core

Scala library for integration with Ethereum clients

License

License

Categories

Categories

Scala Languages
GroupId

GroupId

org.web3scala
ArtifactId

ArtifactId

core
Last Version

Last Version

0.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

core
Scala library for integration with Ethereum clients
Project URL

Project URL

https://github.com/web3scala/web3scala
Project Organization

Project Organization

org.web3scala
Source Code Management

Source Code Management

https://github.com/web3scala/web3scala

Download core

How to add to project

<!-- https://jarcasting.com/artifacts/org.web3scala/core/ -->
<dependency>
    <groupId>org.web3scala</groupId>
    <artifactId>core</artifactId>
    <version>0.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.web3scala/core/
implementation 'org.web3scala:core:0.1.0'
// https://jarcasting.com/artifacts/org.web3scala/core/
implementation ("org.web3scala:core:0.1.0")
'org.web3scala:core:jar:0.1.0'
<dependency org="org.web3scala" name="core" rev="0.1.0">
  <artifact name="core" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.web3scala', module='core', version='0.1.0')
)
libraryDependencies += "org.web3scala" % "core" % "0.1.0"
[org.web3scala/core "0.1.0"]

Dependencies

compile (5)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.12.3
ch.qos.logback : logback-classic jar 1.2.3
net.databinder.dispatch : dispatch-core_2.12 jar 0.13.1
net.databinder.dispatch : dispatch-json4s-jackson_2.12 jar 0.13.1
com.fasterxml.jackson.module : jackson-module-scala_2.12 jar 2.9.0

test (2)

Group / Artifact Type Version
org.scalatest : scalatest_2.12 jar 3.0.1
org.mockito : mockito-core jar 2.9.0

Project Modules

There are no modules declared in this project.

Build Status codecov

web3scala

web3scala allows seamless integration with Ethereum blockchain, using Scala programming language.

Lightweight, efficient, using Scala idioms, it spares you the trouble of writing own low-level code controlling the work of Ethereum nodes.

Features

  • Complete implementation of JSON-RPC Ethereum client API over HTTP
  • Support for Whisper v5 (work in-progress)

Getting started

SBT

libraryDependencies += "org.web3scala" % "core" % "0.1.0"

Ethereum client

$ geth --rpcapi personal,db,eth,net,web3,shh --shh --rpc --testnet

Sending requests

  val service = new Service
  
  // synchronous call (returns Either[Error, Response])
  service.web3ClientVersion match {
    case Left(e) => println("Error: " + e.error)
    case Right(s) => println("Client Version: " + s.result)
  }

  // asynchronous call (returns a future wrapped in AsyncResponse)
  val future = service.asyncWeb3ClientVersion.future
  val response = future().as[GenericResponse]
  response.result match {
    case Some(s) => println(s)
    case None => println(response.error)
  }

Stacking futures

Assuming you have three Ethereum wallets:

  val rq1 = ("0x1f2e3994505ea24642d94d00a4bcf0159ed1a617", BlockName("latest"))
  val rq2 = ("0xf9C510e90bCb47cc49549e57b80814aE3A8bb683", BlockName("pending"))
  val rq3 = ("0x902c4fD71e196E86e7C82126Ff88ADa63a590d22", BlockNumber(1559297))

and want to choose one with most Ether in it:

  val result = highestBalance(rq1, rq2, rq3)

  println("Highest Balance: " + result())

Here's how to achieve that with web3scala:

   def highestBalance(requestParams: (String, Block)*) = {
     
     // execute async requests
     val responses =
       for (requestParam <- requestParams)
         yield requestParam._1 -> service.asyncEthGetBalance(requestParam._1, requestParam._2)
 
     // parse responses
     val futures =
       for (response <- responses)
         yield for (json <- response._2.future)
           yield response._1 -> Utils.hex2long((json \ "result").extract[String])
 
     // select max balance and return corresponding address
     for (future <- Future.sequence(futures))
       yield future.maxBy(_._2)._1
   }

Result:

$ Highest Balance: 0x1f2e3994505ea24642d94d00a4bcf0159ed1a617

The code is non-blocking on I/O at any point, and http requests execution fully parallelized. You'll find a working sample in the examples directory.

Dependencies

The library has following runtime dependencies:

org.web3scala

Web3scala

Blockchain software

Versions

Version
0.1.0