0

I'm having some trouble with web3j and calling getter functions for structs in java.

As per the title, whenever I call the function in web3j, e.g.:

Metadata _metadata = complianceContract.getDocMetadata(hash).send();

I would get the error (for this query):

org.web3j.tx.exceptions.ContractCallException: Unable to convert response: [org.web3j.abi.datatypes.generated.Uint8@cda25fa6, AOATESTFILE.pdf] to expected type: Metadata

I used the web3j CLI to generate the wrapper file, but still to no luck. Here's the snippet for this particular type.

public static class Metadata extends DynamicStruct {
        public BigInteger docType;

        public String fileName;

        public Metadata(BigInteger docType, String fileName) {
            super(new org.web3j.abi.datatypes.generated.Uint8(docType),new org.web3j.abi.datatypes.Utf8String(fileName));
            this.docType = docType;
            this.fileName = fileName;
        }

        public Metadata(Uint8 docType, Utf8String fileName) {
            super(docType,fileName);
            this.docType = docType.getValue();
            this.fileName = fileName.getValue();
        }
    }

And it's subsequent function call:

    public RemoteFunctionCall<Metadata> getDocMetadata(byte[] _hash) {
        final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(FUNC_GETDOCMETADATA, 
                Arrays.<Type>asList(new org.web3j.abi.datatypes.generated.Bytes32(_hash)), 
                Arrays.<TypeReference<?>>asList(new TypeReference<Metadata>() {}));
        return executeRemoteCallSingleValueReturn(function, Metadata.class);
    }
Zi Hang
  • 26
  • 5

1 Answers1

0

I had the conversion issues once. However the root cause was configuration of dev-tools.

After removing the dependency from gradle file, rebuilding the project. It worked find for me.

Sourabh
  • 413
  • 5
  • 17