我正在学习本教程教程
在契约包装器一节中,我遵循了相同的步骤,但我在这里获得了<#>Working,这是完整的堆栈跟踪
java.lang.RuntimeException: java.lang.NoSuchMethodException: smartcontract.Counter1.(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)这是我的代码
public static RemoteCall deploy(Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) {
return deployRemoteCall(Counter1.class, web3j, credentials, gasPrice, gasLimit, BINARY, "");
}
public static RemoteCall 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;
}
}下面是play控制器操作,我将根据该操作获得一个已部署的契约地址。
def counterContractDemo() = Action {
val web3j = Web3j.build(new HttpService("http://localhost:8080/"))
val CounterDemo = new CounterDemo();
Ok(CounterDemo.deployContract())
}我使用的是运行框架2.3.4,并通过了正确数量的参数,以便使用正确的参数
发布于 2018-12-26 17:43:53
protected Counter1(String contractAddress, Web3j web3j, TransactionManager transactionManager, ContractGasProvider gasProvider) {
super(BINARY, contractAddress, web3j, transactionManager, gasProvider);
}如果我记得很好,我就有了这个问题,并通过将它添加到生成的java类中来解决它。
https://ethereum.stackexchange.com/questions/64479
复制相似问题