web3j
web3j copied to clipboard
ContractCallException: Empty value (0x) returned from contract
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.
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)
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
Try sleeping for a while after deploy(). I've noticed it's not synchronous.
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)
Same on my side. Arch-based architecture, recurrent error on function's return (string, uint ...)
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.
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.
Hi guys,
I running a private go-ethereum on Azure.
I would like to add two scenarios that I'm getting issues using Web3j.
-
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.
-
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
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.
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 thedeploy
functions.
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.
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)
顶一下 , 同样遇到这个问题了
web3j core, codegen 4.8.8 also have this issue, somebody solve this?
@jianchengwang Same here, did you find any solution to this issue?
@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 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!
I ran into the same problem, but I solved it. The reason for my error was that I used the wrong RPC URL
I ran into the same problem, but I solved it. The reason for my error was that I used the wrong RPC URL
I ran into the same problem,but other environment is ok . i don't know what the problem, it is prossible incorrect install geth
Making this as resolved based on the latest comments
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?