core

Scala library for integration with Ethereum clients

Лицензия

Лицензия

Категории

Категории

Scala Языки программирования
Группа

Группа

org.web3scala
Идентификатор

Идентификатор

core
Последняя версия

Последняя версия

0.1.0
Дата

Дата

Тип

Тип

jar
Описание

Описание

core
Scala library for integration with Ethereum clients
Ссылка на сайт

Ссылка на сайт

https://github.com/web3scala/web3scala
Организация-разработчик

Организация-разработчик

org.web3scala
Система контроля версий

Система контроля версий

https://github.com/web3scala/web3scala

Скачать core

Как подключить последнюю версию

<!-- 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"]

Зависимости

compile (5)

Идентификатор библиотеки Тип Версия
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)

Идентификатор библиотеки Тип Версия
org.scalatest : scalatest_2.12 jar 3.0.1
org.mockito : mockito-core jar 2.9.0

Модули Проекта

Данный проект не имеет модулей.

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

Версии библиотеки

Версия
0.1.0