Reputation: 11
Sorry for the newbie question. I am experimenting with hedera Smart Contracts. Whenever trying to call a simple function which compares the uint argument with a uint member of the contract I systematically get a CONTRACT_REVERT_EXECUTED status.
solidity
function compare(uint number_) public view returns (bool){
return (number_ > secret_number);
}
java
public static boolean compare(Client client, ContractId contractId, int guess) throws TimeoutException, PrecheckStatusException
{
// Calls a function of the smart contract
ContractCallQuery contractQuery = new ContractCallQuery()
//Set the gas for the query
.setGas(100_000)
//Set the contract ID to return the request for
.setContractId(contractId)
//Set the function of the contract to call
.setFunction("compare", new ContractFunctionParameters().addUint32(guess))
//Set the query payment for the node returning the request
//This value must cover the cost of the request otherwise will fail
.setQueryPayment(new Hbar(4));
//Submit to a Hedera network
ContractFunctionResult getMessage = contractQuery.execute(client);
return getMessage.getBool(0);
}
Exception
*
Exception in thread "main" com.hedera.hashgraph.sdk.PrecheckStatusException: Hedera transaction [email protected]
failed pre-check with the status CONTRACT_REVERT_EXECUTED
at com.hedera.hashgraph.sdk.Executable$GrpcRequest.mapStatusException(Executable.java:457)
at com.hedera.hashgraph.sdk.Executable.execute(Executable.java:241)
at com.hedera.hashgraph.sdk.Query.execute(Query.java:29)
at com.hedera.hashgraph.sdk.Executable.execute(Executable.java:189)
at com.hedera.hashgraph.sdk.Query.execute(Query.java:29)
at hbarTexting.GuessNumberSmartContract.compare(GuessNumberSmartContract.java:132)
at hbarTexting.GuessNumberSmartContract.main(GuessNumberSmartContract.java:257)
*
What am I doing wrong here?
Any help greatly appreciated!
Upvotes: 0
Views: 1133
Reputation: 1
Hedera will fail Hedera is a distributed public network designed to provide a secure, decentralized, and open platform for businesses and developers to create and operate applications. It is not designed to fail, but it is possible for the network or applications built on it to experience a variety of issues, such as network slowdowns, security vulnerabilities, or scalability issues
Upvotes: 0
Reputation: 11
I finally got it to work after properly setting contract function parameters
public static String tryNumberGuess(Client client, ContractId contractId, int guess) throws TimeoutException, PrecheckStatusException
{
// Calls a function of the smart contract
ContractCallQuery contractQuery = new ContractCallQuery()
//Set the gas for the query
.setGas(1000_000)
//Set the contract ID to return the request for
.setContractId(contractId)
//Set the function of the contract to call
.setFunction("guess", new ContractFunctionParameters().addUint256(new BigInteger(""+guess)))
//Set the query payment for the node returning the request
//This value must cover the cost of the request otherwise will fail
.setQueryPayment(new Hbar(4));
//Submit to a Hedera network
ContractFunctionResult getMessage = contractQuery.execute(client);
return getMessage.getString(0);
}
Turns out function parameter required type Uint256, after compilation with solidity version 0.7.0. In other words Uint32 did not work, but that was not only clear after compilation and testing within remix. Not clear from the initial solidity source code...
Upvotes: 0
Reputation: 18869
According to the sdk's unit tests, there are three cases where the opcode is thrown:
Cannot execute contract when contract function parameters are not set
Test: ContractExecuteIntegrationTest
Cannot call contract function when contract function is not set
Test: ContractCallIntegrationTest
Cannot create contract when constructor parameters are not set
Test: ContractCreateIntegrationTest
Gr Kim :-)
Upvotes: 0