Web3J

  1. Web3J is a Java and Android library for interacting with nodes and smart contracts on the Ethereum network.

  2. Add the following dependencies to Maven to start using Web3J:
// Java 8
<dependency> <groupId>org.web3j</groupId> <artifactId>core</artifactId> <version>3.3.1</version> </dependency>

// Android
<dependency> <groupId>org.web3j</groupId> <artifactId>core</artifactId> <version>3.3.1-android</version> </dependency>
  1. If you are using Gradle, then use the following methods:
// Java 8
compile ('org.web3j:core:3.3.1')

// Android
compile ('org.web3j:core:3.3.1-android')
  1. To connect to a node and initialize an object, use Web3J.build. It defaults to localhost:8545 and can be changed:
Web3j web3 = Web3j.build(new HttpService()); 
  1. To send a synchronous request using Web3J, use the following method:
Web3ClientVersion web3ClientVersion = web3.web3ClientVersion().send();
String clientVersion = web3ClientVersion.getWeb3ClientVersion();
  1. To make it asynchronous, use the following method:
Web3ClientVersion web3ClientVersion = web3.web3ClientVersion().sendAsync().get();
String clientVersion = web3ClientVersion.getWeb3ClientVersion();

More information about using this library is available in the official documentation at https://github.com/web3j/web3j.

 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.221.249.198