0

I have been facing this issue for some time and I realized there must be a problem with Ganache or maybe someone has any idea why it doesn't work.

I have created a very simple contract as below, it has nothing but at the time of deployment, it needs an Ethereum address.

pragma solidity ^0.5.0;

contract SampleData {
    address owner1;
    constructor  (address  _owners) public 
    {
        //the deployer of the contract must tell who are the authorities 
      owner1 = _owners;
    }        
}

I have used web3j-3.4.0 to generate a java wrapper for my contract and it generated me SampleData.java.

Here is my contract deployment code in java

SampleData contract = null;
contract = SampleData.deploy(
  web3a, credentials, ManagedTransaction.GAS_PRICE,
  BigInteger.valueOf(220000L),
  "0x5D5b8c151cc101642a5B2C461cf1538892491133").send();

The contract deployment wrapper inside SampleData.java is (this auto-generated file and I did not change any code inside):

public static RemoteCall<SampleData4> deploy(
  Web3j web3j,
  Credentials credentials,
  BigInteger gasPrice,
  BigInteger gasLimit, String _owners) {
    String encodedConstructor = FunctionEncoder.encodeConstructor(
      Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(_owners)));
    return deployRemoteCall(
      SampleData4.class, web3j, credentials, gasPrice, gasLimit, BINARY,
      encodedConstructor);
}

Now the problem is if I would change the contract constructor it works fine, if I use any other data type in the constructor then it works fine. What I understand is for some reason "Address" data type does not work at all and gives me Invalid OpCode.

Another important thing is if I would deploy this on Truffle console by connecting my java application on truffle console then it successfully gets executed. Therefore, I believe Ganache for some reason is not accepting address data type.

Could anyone please guide me since I am not interested to use geth or truffle console because Ganache is faster and easier for rapid check and balance.

EDIT: Logcart traffic log was came as below before raising error stack

22:43:44.478 [main] DEBUG org.web3j.protocol.http.HttpService - <-- 200 OK 

http://127.0.0.1:7545/ (83ms)
22:43:44.478 [main] DEBUG org.web3j.protocol.http.HttpService - Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept
22:43:44.478 [main] DEBUG org.web3j.protocol.http.HttpService - Access-Control-Allow-Origin: *
22:43:44.478 [main] DEBUG org.web3j.protocol.http.HttpService - Access-Control-Allow-Methods: *
22:43:44.478 [main] DEBUG org.web3j.protocol.http.HttpService - Content-Type: application/json
22:43:44.478 [main] DEBUG org.web3j.protocol.http.HttpService - Date: Wed, 10 Apr 2019 19:43:44 GMT
22:43:44.479 [main] DEBUG org.web3j.protocol.http.HttpService - Connection: keep-alive
22:43:44.479 [main] DEBUG org.web3j.protocol.http.HttpService - Transfer-Encoding: chunked
22:43:44.479 [main] DEBUG org.web3j.protocol.http.HttpService - 
22:43:44.479 [main] DEBUG org.web3j.protocol.http.HttpService - {"id":36,"jsonrpc":"2.0","result":"0x9aff9dbb1e02aa3398cc1c2b1b3fd8e43a4161c4b1a99b89f22523157838df92","error":{"message":"VM Exception while processing transaction: invalid opcode","data":{"name":"Error"}}}
22:43:44.480 [main] DEBUG org.web3j.protocol.http.HttpService - <-- END HTTP (207-byte body)

Here is the java exception

java.lang.RuntimeException: 

com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.lang.String out of START_OBJECT token
 at [Source: buffer(okhttp3.internal.http1.Http1Codec$ChunkedSource@32cb636e).inputStream(); line: 1, column: 190] (through reference chain: org.web3j.protocol.core.methods.response.EthSendTransaction["error"]->org.web3j.protocol.core.Response$Error["data"])
    at org.web3j.tx.Contract.deploy(Contract.java:302)
    at org.web3j.tx.Contract.lambda$deployRemoteCall$5(Contract.java:334)
    at org.web3j.protocol.core.RemoteCall.send(RemoteCall.java:30)
    at com.ateon.KycBlockchainDemo.test_ethereum.deployContract(test_ethereum.java:518)
    at com.ateon.KycBlockchainDemo.Server.main(Server.java:84)
Caused by: com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.lang.String out of START_OBJECT token
 at [Source: buffer(okhttp3.internal.http1.Http1Codec$ChunkedSource@32cb636e).inputStream(); line: 1, column: 190] (through reference chain: org.web3j.protocol.core.methods.response.EthSendTransaction["error"]->org.web3j.protocol.core.Response$Error["data"])
    at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:270)
    at com.fasterxml.jackson.databind.DeserializationContext.reportMappingException(DeserializationContext.java:1234)
    at com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1122)
    at com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1075)
    at com.fasterxml.jackson.databind.deser.std.StringDeserializer.deserialize(StringDeserializer.java:60)
    at com.fasterxml.jackson.databind.deser.std.StringDeserializer.deserialize(StringDeserializer.java:11)
    at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:499)
    at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:101)
    at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:276)
    at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:140)
    at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:499)
    at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:101)
    at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:276)
    at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:140)
    at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3798)
    at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2908)
    at org.web3j.protocol.Service.send(Service.java:33)
    at org.web3j.protocol.core.Request.send(Request.java:71)
    at org.web3j.tx.RawTransactionManager.signAndSend(RawTransactionManager.java:107)
    at org.web3j.tx.RawTransactionManager.sendTransaction(RawTransactionManager.java:91)
    at org.web3j.tx.TransactionManager.executeTransaction(TransactionManager.java:49)
    at org.web3j.tx.ManagedTransaction.send(ManagedTransaction.java:83)
    at org.web3j.tx.Contract.executeTransaction(Contract.java:242)
    at org.web3j.tx.Contract.create(Contract.java:271)
    at org.web3j.tx.Contract.deploy(Contract.java:300)
  • What is authorities??? – goodvibration Apr 10 at 9:11
  • it was a just a comment, which I have removed now. – wolvorinePk Apr 10 at 11:44
  • Could you show error message and exception stack trace? – Mikhail Vladimirov Apr 10 at 12:19
  • @MikhailVladimirov kindly check the exception and RPC communication information in the question which I have edited now. – wolvorinePk Apr 10 at 19:49
  • which solc version are you using to compile the code before generating the wrapper , and why web3j 3.4.0 and not 4.1.0 ? – Majd TL Apr 12 at 10:47

Your Answer

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

Browse other questions tagged or ask your own question.