I am a Java developer. I want to write a smart contract using Java and deploy it to a private blockchain network.
Does Ethereum provide the facility to write smart contracts using Java language? If yes, how can I do this?
Ethereum Stack Exchange is a question and answer site for users of Ethereum, the decentralized application platform and smart contract enabled blockchain. It only takes a minute to sign up.Sign up to join this community
Currently, Smart Contracts can be written in three languages:
Serpent - Python derivative
LLL(Lisp Like Language) - Similar to Assembly
You can find more information about these languages here.
Solidity is designed especially for writing smart contracts and is the flagship language of Ethereum. You can start reading about it here.
You can not write contracts in Java, but deploying should work with the Ethereum Contract API native in Java. The goal is to ease the integration of Ethereum in a Java project.
- Easy configuration of the network and keypair use
- Create an interface for a smart contract
- Have type safety in regards of input and output values
- Easy transaction creation
- Easy synchronization when creating a transaction
- Transaction creation returns Future, simple calls returns the value itself
On youtube is a short presentation (15 minutes) from the Berlin Ethereum meetup.
To start you can use web3j. It is Java library that allow the iteration of java application with contracts in the Ethereum network.
It doesn't provide the capability to write contracts in java, but you can interact with contracts written in Solidity.
It generates Smart Contract wrappers in Java from a Solidity compiled binary and ABI file.
Once you've generated the wrapper code with web3j, you will be able to deploy, then call the methods on the above contract example as follows:
SimpleStorage simpleStorage = SimpleStorage.deploy( <web3j>, <credentials>, GAS_PRICE, GAS_LIMIT, BigInteger.ZERO); // ether value of contract TransactionReceipt transactionReceipt = simpleStorage.set( new Uint256(BigInteger.valueOf(1000))), .get(); Uint256 result = simpleStorage.get() .get();
It's not out yet but you might be interested in Corda, which is being developed by Mike Hearn and his team on behalf of the R3 consortium. This targets Java developers, and doesn't use a blockchain, as is appropriate for a lot of private blockchain projects in the financial sector.
Per this discussion some code will be released soon: https://m.youtube.com/watch?v=3YTSwB5UrEI