11

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?

4

No, the only currently supported languages for contract development are lll (dead), serpent and solidity with the later being most used.

4

Currently, Smart Contracts can be written in three languages:

Solidity - Similar to JavaScript

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.

3

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.

3

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:

Ex:

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();
  • Please don't submit link-only answers. Describe the content and how it solves the problem. – Tjaden Hess Jul 8 '17 at 21:58
  • I think is misleading. You can write your code in a few languages for which an EVM compiler exists, but Java isn't one of them. JavaScript != Java. You can indeed deploy bytecode via JavaScript using Web3 but it seems like we are far away from the original question. – Rob Hitchens - B9lab Jul 8 '17 at 22:50
  • 1
    @RobHitchens: plesase note this is web3j, not web3 - it is, as described a Java library. – jsbueno Jul 11 '17 at 16:36
  • 1
    (whoever downvoted this, the answer seems to have improved since) – jsbueno Jul 11 '17 at 16:36
2

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

  • "doesn't use a blockchain, as is appropriate for a lot of private blockchain projects" Upvoted for this. – Jesse Busman Apr 13 at 11:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.