0

i am following this tutorial tutorial

under the section Working with smart contracts with Java smart contract wrappers i followed the same steps but i am getting RunTimeException here is the full stack trace

java.lang.RuntimeException: java.lang.NoSuchMethodException: smartcontract.Counter1.<init>(java.lang.String, org.web3j.protocol.Web3j, org.web3j.crypto.Credentials, org.web3j.tx.gas.ContractGasProvider)
    at org.web3j.tx.Contract.deploy(Contract.java:366)
    at org.web3j.tx.Contract.deploy(Contract.java:403)
    at org.web3j.tx.Contract.lambda$deployRemoteCall$5(Contract.java:426)
    at org.web3j.protocol.core.RemoteCall.send(RemoteCall.java:30)
    at smartcontract.CounterDemo.deployContract(CounterDemo.java:37)
    at controllers.SmartContractController$$anonfun$counterContractDemo$1.apply(SmartContractController.scala:64)
    at controllers.SmartContractController$$anonfun$counterContractDemo$1.apply(SmartContractController.scala:58)

and here is my code a code snippet of Counter1.java

public static RemoteCall<Counter1> deploy(Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) {
        return deployRemoteCall(Counter1.class, web3j, credentials, gasPrice, gasLimit, BINARY, "");
    }

    public static RemoteCall<Counter1> deploy(Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) {
        return deployRemoteCall(Counter1.class, web3j, transactionManager, gasPrice, gasLimit, BINARY, "");
    }

    public static Counter1 load(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) {
        return new Counter1(contractAddress, web3j, credentials, gasPrice, gasLimit);
    }

    public static Counter1 load(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) {
        return new Counter1(contractAddress, web3j, transactionManager, gasPrice, gasLimit);
    }

CounterDemo.java

public class CounterDemo {

    public String deployContract() {
        String deploy = "";
        BigInteger GAS_LIMIT = BigInteger.valueOf(6721975L);
        BigInteger GAS_PRICE = BigInteger.valueOf(20000000000L);
        try {

            Web3j web3j = Web3j.build(new org.web3j.protocol.http.HttpService("http://localhost:8080"));
            Credentials credentials = WalletUtils.loadCredentials("pswd",
                    "path to privatekey/UTC--2018-12-15T12-06-10.************************************1");
            System.out.println("credentails address " + credentials.getAddress());
            Counter1 counter = Counter1.deploy(web3j, credentials, GAS_PRICE,
                    GAS_LIMIT ).send();

            //Counter.deploy(web3j, credentials, GAS_PRICE,GAS_LIMIT);
            deploy = counter.getContractAddress();
            System.out.println("address is {}" + deploy);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } // defaults to http://localhost:8545/
        catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return deploy;
    }

}

and here is the play controller action on which i am getting a contract deployed address

def counterContractDemo() = Action {
    val web3j = Web3j.build(new HttpService("http://localhost:8080/"))
    val CounterDemo = new CounterDemo();

    Ok(CounterDemo.deployContract())
  }

i am using playframework 2.3.4 and passing the right amount of parameters for Counter1's deplo method still the exception shows NoSuchMethodException how is this happening is there anything missing ?which is causing the issue any help would be appreciated

0
protected Counter1(String contractAddress, Web3j web3j, TransactionManager transactionManager, ContractGasProvider gasProvider) {
    super(BINARY, contractAddress, web3j, transactionManager, gasProvider);
}

If i remember good, I had this problem and solved it by adding this to the generated java class.

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.