1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Trouble getting started with web3j for java

Discussion in 'Finance' started by Hentai Ousama, Aug 2, 2020 at 9:55 AM.

  1. This is my first time working with blockchain related programming. I am using java so i have added the web3j dependencies in my project.

    So what i want to do is :-


    1. Connect to a smart contract whose contract address i have. It's on ropsten network.


    2. Say my application starts at 12 p.m. today. So i have to read all the transactions made with the smart contract after the last transaction before current time.

    What i want to know who made to transaction, to whom the address was sent and how much tokens were sent.

    How can i achieve this?

    I searched a lot and i got stuck at this point (which i don't know is correct is wrong) :-

    (What i want to do and what i have end up doing below might be totally different)

    public class Game {

    final String RTKTestNetContractAddress = "0xa59b4d4c371a4b7957d7a3bf06c19ec3ac5885f1";
    EthFilter filter = new EthFilter(DefaultBlockParameterName.EARLIEST,
    DefaultBlockParameterName.LATEST, RTKTestNetContractAddress.substring(2));

    Web3j web3j = Web3j.build(new HttpService("https://ropsten.etherscan.io/"));
    EthBlockNumber startBlockNumber = null;
    Subscription subscriptionToSmartContract;

    Thread t = new Thread() {
    try {
    startBlockNumber = web3j.ethBlockNumber().sendAsync().get().getBlockNumber();
    } catch (Exception e) {
    e.printStackTrace();
    }
    subscriptionToSmartContract = (Subscription)
    web3j.replayPastAndFutureTransactionsFlowable((DefaultBlockParameter) startBlockNumber).subscribe(tx -> {});
    }
    }


    But this just ends up giving me error in the catch block saying :-

    java.util.concurrent.ExecutionException: com.fasterxml.jackson.core.JsonParseException: Unexpected character ('<' (code 60)): expected a valid value (JSON String, Number, Array, Object or token 'null', 'true' or 'false')


    Please tell me how it is properly done.

    Login To add answer/comment
     

Share This Page