May 8, 2020: I have abandoned this project and will not update it. If someone else wants to take it over please contact me.
web3j-scala is an idiomatic Scala wrapper around Web3J for Ethereum.
Web3J is a lightweight, reactive, somewhat type safe Java and Android library for integrating with nodes on Ethereum blockchains.
Web3J features RxJava extensions, and
web3j-scala wraps that syntax in Scala goodness.
For example, the
web3j-scala observable methods
provide simple and efficient application code.
Scala's value classes are used
to provide much stronger type safety than Web3J, without incurring a runtime penalty.
Use As a Library
Add this to your SBT project's
resolvers ++= Seq( "micronautics/scala on bintray" at "https://dl.bintray.com/micronautics/scala", "ethereum" at "https://dl.bintray.com/ethereum/maven/" ) libraryDependencies += "com.micronautics" %% "web3j-scala" % "4.5.17" withSources()
This library is cross-built for Scala 2.12 and 2.13. Tested with Oracle JDK 8 and OpenJDK 8 & 11.
Questions and Problems
If you find a bug in this library you can post an issue here.
Run the Demo Program
The demo program performs the following:
- Follows the outline of the Web3J Getting Started documentation, adapted for Web3J-Scala, including synchronous and asynchronous versions of the available methods.
- Compiles an example Solidity program that defines a smart contract.
- Creates a JVM wrapper from an example smart contract.
To run the demo:
- Start up an Ethereum client if you don’t already have one running, such as
gethwith the following options, which are convenient for development but not secure enough for production:
- The Ethereum data directory is set to
~/.ethereum, or a subdirectory that depends on the network chosen; the directory will be created if required.
- HTTP-RPC server at
localhost:8545is enabled, and all APIs are allowed.
- Ethereum's experimental Whisper message facility is enabled.
- Inter-process communication will be via a virtual file called
geth.ipc, located at
~/.ethereumor a subdirectory.
- WS-RPC server at
localhost:8546is enabled, and all APIs are allowed.
- Info verbosity is specified.
- A log file for the
gethoutput will be written, or overwritten, in
log/directory will be created if it does not already exist.
You will see the message
$ mkdir logs/ $ geth \ #--datadir .ethereum/devnet --dev \ # boots quickly but has no deployed contracts from others --datadir .ethereum/rinkeby --rinkeby \ # takes about 15 minutes to boot, but has contracts --ipcpath geth.ipc \ --metrics \ --rpc \ --rpcapi eth,net,web3,clique,debug,eth,miner,personal,rpc,ssh,txpool \ --shh \ --ws \ --wsapi eth,net,web3,clique,debug,eth,miner,personal,rpc,ssh,txpool \ --verbosity 2
No etherbase set and no accounts found as default. Etherbase is the index into
personal.listAccountswhich determines the account to send Ether too. You can specify this value with the option
- The Ethereum data directory is set to
- The shell that you just used will continuously scroll output so long as
gethcontinues to run, so type the following into another shell:
The demo has two major components:
- Creates a JVM wrapper for the sample smart contract.
- The second portion of the demo consists of the following:
bin/web3jscript runs the Web3J command-line console. The script builds a fat jar the first time it is run, so the command runs quickly on subsequent invocations.
- More scripts are provided in the
- bin/attachIpc -
This script might need to be edited if a network other than
- bin/getApis -
Reports the available APIs exposed by this
- bin/isGethListening -
gethis listening on HTTP port 8545
- Update the version string in
build.sbtand in this
README.mdbefore attempting to publish to Bintray.
- Commit changes with a descriptive comment:
$ git add -a && git commit -m "Comment here"
- Publish a new version of this library, including committing changes and updating the Scaladoc with this command:
$ sbt publishAndTag
Use the Scaladoc project; first do a preflight check of the Scaladoc output:
sbt "; project web3j-scala; doc; project demo; doc"
Updating Scaladoc and Committing Changes Without Publishing a New Version
This task rebuilds the docs, commits the git repository, and publishes the updated Scaladoc without publishing a new version:
$ sbt commitAndDoc
This project is sponsored by Micronautics Research Corporation, the company that delivers online Scala training via ScalaCourses.com. You can learn Scala by taking the Introduction to Scala, and Intermediate Scala courses.
Please contact us to discuss your organization’s training needs.
This software is published under the Apache 2.0 License.