web3j icon indicating copy to clipboard operation
web3j copied to clipboard

ContractCallException: Empty value (0x) returned from contract

Open IcyLemon opened this issue 6 years ago • 20 comments

I encountered a problem. My environment is:Centos 7 64,geth-1.7.3, web3j 3.3.1

It needs to be emphasized that I could be sure of that my contract was deployed and loaded normally, but once any of the APIs in the contract was invoked, the following exception(fragment) occurred: Caused by: org.web3j.tx.exceptions.ContractCallException: Empty value (0x) returned from contract at org.web3j.tx.Contract.executeCallSingleValueReturn(Contract.java:197) at org.web3j.tx.Contract.lambda$executeRemoteCallSingleValueReturn$1(Contract.java:251) at org.web3j.protocol.core.RemoteCall.send(RemoteCall.java:30)

I want to know that what happened, because these APIs were all normal before, it seemed that this problem suddenly happened.

Who encountered this too? Thanks.

IcyLemon avatar May 18 '18 01:05 IcyLemon

Web3j version 3.4.0
this.contract = (Greeter) Greeter.load(
			this.contractAddress, web3jAdmin, credentials, gasPrice, gasLimit);
	log.info("isContractValid=" + contract.isValid());

while the contract returned from deploy worked just fine, the loaded contract always has contract.isValid() false, isContractValid=false the String gr = this.contract.greet().send(); always through the following exceptions: I have tried a variety of ethereum testnet and local private networks, single or multiple. It must be a bug. Please fix it. Exception in thread "main" org.web3j.tx.exceptions.ContractCallException: Empty value (0x) returned from contract at org.web3j.tx.Contract.executeCallSingleValueReturn(Contract.java:230) at org.web3j.tx.Contract.lambda$executeRemoteCallSingleValueReturn$1(Contract.java:297) at org.web3j.protocol.core.RemoteCall.send(RemoteCall.java:30)

glomarch avatar Jul 06 '18 03:07 glomarch

public void deploy() throws Exception { log.info("Deploying smart contract"); String greetMessage = "Hi this is a greeter app"; gasPrice=BigInteger.valueOf(100);

    this.contract = Greeter.deploy(web3j, credentials, gasPrice, gasLimit, greetMessage).send();

    log.info("contract deployed "  );

String gr = this.contract.greet().send(); } works fine. however log.info("loading contract"); this.contract = (Greeter) Greeter.load( this.contactAddress, web3j, credentials, gasPrice, gasLimit); String gr = this.contract.greet().send(); always return the above error. Eventhough the contract binary returned from both contract are the same. This is reproducible from many ethereum networks

glomarch avatar Jul 06 '18 03:07 glomarch

Try sleeping for a while after deploy(). I've noticed it's not synchronous.

xhliu avatar Jul 26 '18 15:07 xhliu

i came across this issue again:

chain-scrawler        | 2018-10-13 10:38:58.672 ERROR 1 --- [ool-22-thread-1] c.c.s.b.walletwatcher.EthereumWatcher    : Empty value (0x) returned from contract                  
chain-scrawler        | org.web3j.tx.exceptions.ContractCallException: Empty value (0x) returned from contract                       
chain-scrawler        |         at org.web3j.tx.Contract.executeCallSingleValueReturn(Contract.java:230)                                                                          
chain-scrawler        |         at org.web3j.tx.Contract.lambda$executeRemoteCallSingleValueReturn$1(Contract.java:297)   
chain-scrawler        |         at org.web3j.protocol.core.RemoteCall.send(RemoteCall.java:30)                                                                                    
chain-scrawler        |         at com.coin.scrawler.blockscan.walletwatcher.EthereumWatcher.getContract(EthereumWatcher.java:386)

xiaods avatar Oct 13 '18 11:10 xiaods

Same on my side. Arch-based architecture, recurrent error on function's return (string, uint ...)

Bobavince avatar Oct 19 '18 12:10 Bobavince

Don't know if it can help out, but I had the same issue and in my wrapped compiled solidity script, it was :

private static final String BINARY = "[{\"constant\":true,\"inputs\":[],\"name\":\"chars\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"}, ( ... )se,\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"}]";

instead of :

private static final String BINARY = "608060405234801561001057600080fd5b5060008054600160a060020a0319163317815560015561027f806100356000 (...) ffffffffffffffffffff163314156102515760005473ffffffffffffffffffffffffffffffffffffffff16ff5b5600a165627a7a72305820545e60010ee0d4b8f1315f9743499c370f058e1ab280aab90d9795cd074ff9e60029";

Which means, that web3j or solidity compiler does not correctly do its job. Personal issue, but it was not obvious.

Bobavince avatar Oct 19 '18 13:10 Bobavince

Issue still exists. Deploying the contract works fine, loading it does not, it is always invalid. You shouldn't have to deploy a new contract every time you run your program...is this issue known to the developers? Is it being fixed?

EDIT: Nevermind, there is no issue. I used my wallet address instead of the contract address. However, during testing I found out that the wallet address binary was equal to the smart contract wrapper binary. Thismight lead to confusion.

ghost avatar Oct 25 '18 19:10 ghost

Hi guys,

I running a private go-ethereum on Azure.

I would like to add two scenarios that I'm getting issues using Web3j.

  1. When I deploy a contract from a Java Application using Web3j API, which it seems to work fine, and then when I try to call contract's methods by Remix IDE it always return 0.

  2. If I do the same and try to call the contract's methods from Java I get "Empty value (0x) returned from contract at xyz"

But, If I deploy the contract by REMIX IDE, both Java and REMIX work fine.

Is it a bug in the library ? Thanks

metiago avatar Jun 01 '19 14:06 metiago

Is this still an issue with web3j 4.3.0

@glomarch in the code snippet above you do not set this.contractAddress after deploying, so you are not loading the contract correctly because this.contractAddress is null.

@Bobavince it seems that you have swapped the arguments to the flags of the web3j command line tools.

@metiago please open a separate issue if this is still a problem. It is unrelated to this issue. Please provide instructions to reproduce.

AlexandrouR avatar Jul 15 '19 12:07 AlexandrouR

Here's a sample abstract contract

public class IERC20 extends Contract {
    private static final String BINARY = "";
    public static final String FUNC_APPROVE = "approve";
    public static final String FUNC_TOTALSUPPLY = "totalSupply";
    .....
}

What happens When you try to deploy this?

// this will give no error.
IERC20 token = IERC20.deploy(web3j, adminCredentials, new DefaultGasProvider(), name,symbol);

// this will give the contract returned 0x error
token.getTotalSupply().send()

How did we begin with a empty binary?

solc generates both .abi and .bin files for abstract contracts. The .abi file will be blank for abstract contract. web3j will create wrapper out of it with blank BINARY

This can happen when you modify contract and accidently change a function to different signature.

Resolution

  • The deploy method should throw an Exception when the BINARY field in contract is empty.
  • Web3j program should generate only the load functions for abstract contracts not the deploy functions.

mesudip avatar Jul 23 '19 12:07 mesudip

The .abi file will be blank

do you mean the .bin will be blank?

I think a better resolution would be not to generate the deploy methods in this case.

I am happy with this proposal. We need an accompanying PR to move this forward.

AlexandrouR avatar Aug 02 '19 09:08 AlexandrouR

Hi! Any possible solution about this issue ? I'm getting the same error in Ubuntu 18 + Geth. ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console. Unlocked account: true Exception in thread "main" org.web3j.tx.exceptions.ContractCallException: Empty value (0x) returned from contract at org.web3j.tx.Contract.executeCallSingleValueReturn(Contract.java:313) at org.web3j.tx.Contract.lambda$executeRemoteCallSingleValueReturn$1(Contract.java:397) at org.web3j.protocol.core.RemoteCall.send(RemoteCall.java:42) at io.tiago.pyg.contracts.DeployContract.defineMileage(DeployContract.java:56) at io.tiago.pyg.contracts.DeployContract.main(DeployContract.java:46)

metiago avatar Apr 10 '21 01:04 metiago

顶一下 , 同样遇到这个问题了

zhanghzong avatar Jun 28 '21 03:06 zhanghzong

web3j core, codegen 4.8.8 also have this issue, somebody solve this?

jianchengwang avatar Oct 12 '21 10:10 jianchengwang

@jianchengwang Same here, did you find any solution to this issue?

Gasu16 avatar Oct 25 '21 13:10 Gasu16

@jianchengwang Same here, did you find any solution to this issue?

it is usually the contract address is wrong, at least I am wrong like this,so check your contract address first, good luck.

jianchengwang avatar Oct 25 '21 13:10 jianchengwang

@jianchengwang Same here, did you find any solution to this issue?

it is usually the contract address is wrong, at least I am wrong like this,so check your contract address first, good luck.

It was due to the same problem, wrong contract address, thank you!

Gasu16 avatar Oct 25 '21 17:10 Gasu16

I ran into the same problem, but I solved it. The reason for my error was that I used the wrong RPC URL

it-honghui avatar Dec 02 '21 10:12 it-honghui

I ran into the same problem, but I solved it. The reason for my error was that I used the wrong RPC URL

it-honghui avatar Dec 02 '21 10:12 it-honghui

I ran into the same problem,but other environment is ok . i don't know what the problem, it is prossible incorrect install geth

huangxuanheng avatar Jun 24 '22 11:06 huangxuanheng

Making this as resolved based on the latest comments

mohamedelshami avatar Oct 21 '22 15:10 mohamedelshami

Sorry to comment on a closed issue, but with web3j 4.9.4 i have the same issue. I'm writing integration tests and using OPEN_ETHEREUM as node. The deploy function correctly returns an instance of the java class, the contractaddress is not null, but when I call any function it returns 0x0. Loading the contract does not solve the issue.

With BESU node it works fine (but it gives other issues). Any suggestion?

saugion avatar Mar 24 '23 19:03 saugion