Make it work

Spring Boot and web3j: Easy microservices for the Ethereum Blockchain

Conor Svensson
Spring Boot
© Shutterstock /  Madrolly

web3j is a lightweight Java library for integrating with clients on the Ethereum blockchain. And now you can integrate it into your Spring Boot applications. In this article, JAX London speaker Conor Svensson shows how easily web3j integrates with the Spring Framework.

web3j now seamlessly integrates with the Spring Framework, thanks to the web3j Spring Boot Starter.

Using Spring Boot, it’s trivial to create production-ready services using web3j to work with the Ethereum blockchain.

Start by creating a new Spring Boot application. Then add the web3j-spring-boot-starterto your Gradle or Maven configuration:

dependencies {
    compile 'org.web3j:web3j-spring-boot-starter:1.0.0'
    ...
}

Now create a service using web3j, and Spring will create and configure the web3j instance for you!

@Service
public class Web3jSampleService {
 
    @Autowired
    private Web3j web3j;
 
    public String getClientVersion() throws IOException {
        Web3ClientVersion web3ClientVersion = web3j.web3ClientVersion().send();
        return web3ClientVersion.getWeb3ClientVersion();
    }
} 

SEE MORE: The ultimate beginner’s guide to Blockchain [Infographic]

The default HTTP endpoint of your Ethereum client is used (http://localhost:8545), however, you can easily change this in your application properties file.

# An infura endpoint
web3j.client-address = https://morden.infura.io/<your token id>
 
# Or, an IPC endpoing
web3j.client-address = /path/to/file.ipc 

Code for this example is available here. For further information on check out the web3j project home page and the spring-boot-starter project.

The article was originally published on Conor Svensson’s blog

l’shana tova!

Conor Svensson will be delivering a talk at JAX London that will explore using Ethereum to build Java applications on the blockchain. In his talk, Conor will be demystifying this technology and demonstrating how you can integrate JVM applications with the leading public blockchain technology, Ethereum.

Conor will also lead a workshop on developing Java applications on the Blockchain with web3j. This workshop is for anyone who wants to look beyond the hype and get some hands-on experience developing with blockchain technology. You’ll learn how to use and integrate Java applications with the dominant public blockchain Ethereum.

hey i just met you and this is crazy but here’s my number so call me maybe?

Author

Conor Svensson

Conor is the author of web3j, the Java library for working with the Ethereum blockchain. He’s also the founder of blk.io who provide an enterprise blockchain platform based on Ethereum.


Comments
comments powered by Disqus