3

I worked with web3js(JavaScript) and used web3.eth.Contract with 2 params (json, address) and successfully got contract object. Now I started to work with web3j(Java) and don`t understand how I have to work now. How can I do this ?

3
  • Like java and javascript are totally unrelated languages, web3j is different from the javascript library with similar name. I'd suggest to start reading web3j's documentation at docs.web3j.io.
    – Ismael
    Commented Sep 3, 2020 at 16:44
  • 1
    Yes, I found this documentation, but it doesn`t clarify what exactly I have to do. It seems to me, that I need to deploy somehow a contract via Solidity or Truffle. Both of them I did not use before. So, how can I deploy a contract having json and address - that is a question) May be someone has an example ? Commented Sep 4, 2020 at 7:25
  • Last time I did something with java you had to use some utility to convert json file to a smart contract wrapper. Then use that wrapper to deploy instances or interact with deployed instances, see docs.web3j.io/getting_started/…. Sorry, but I did use very little of web3j so I can't help much there.
    – Ismael
    Commented Sep 4, 2020 at 16:58

1 Answer 1

1

I found a solution

I installed epirus wrapper, then I generated java package with command epirus solidity generate

-a=/root/my_json.abi -o=/root/ -p=my_java

(before I changed extension of my file from json to abi). After getting this package, I could use smart contract object with his methods from json file.

Also, after installation of epirus and before generating package I used this commands

JAVA_HOME=$(dirname $( readlink -f $(which java) ))
JAVA_HOME=$(realpath "$JAVA_HOME"/../)
export JAVA_HOME

sudo update-alternatives --config java

Don`t know exactly what they do, but without them I could not use epirus.

To check if epirus ready to generate I used command

epirus -V 

It returns version of wrapper. If not - use two commands above.

Ismael, thank you for the direction)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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