Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Spring Boot and web3j: Easy Microservices for Ethereum Blockchain

DZone's Guide to

Spring Boot and web3j: Easy Microservices for Ethereum Blockchain

web3j seamlessly integrates with Spring Frameworks. Simply create a new Spring Boot app, add the starter to your configuration, and create a service with web3j.

· Integration Zone
Free Resource

Build APIs from SQL and NoSQL or Salesforce data sources in seconds. Read the Creating REST APIs white paper, brought to you in partnership with CA Technologies.

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-starter to 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();
    }
}

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 it, check out the web3j project home page and the spring-boot-starter project.

The Integration Zone is brought to you in partnership with CA Technologies.  Use CA Live API Creator to quickly create complete application backends, with secure APIs and robust application logic, in an easy to use interface.

Topics:
ethereum ,integration ,web3j ,microservices ,blockchain ,tutorial ,spring

Published at DZone with permission of Conor Svensson, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}