对新手的问题很抱歉。我正在试验hedera合同。每当试图调用一个简单的函数(将uint参数与契约的uint成员进行比较)时,我就会系统地获得一个CONTRACT_REVERT_EXECUTED状态。
固体
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);
}线程"main“com.hedera.hashgraph.sdk.PrecheckStatusException: Hedera transaction 0.0.34318751@1651508840.487521537中的异常*异常未能预先检查状态CONTRACT_REVERT_EXECUTED在com.hedera.hashgraph.sdk.Executable.execute(Executable.java:241) 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。hbarTexting.GuessNumberSmartContract.compare(GuessNumberSmartContract.java:132) at hbarTexting.GuessNumberSmartContract.main(GuessNumberSmartContract.java:257) *的sdk.Query.execute(Query.java:29)
我在这里做错什么了?
任何帮助都非常感谢!
发布于 2022-05-25 12:21:23
在正确设置合同函数参数后,我终于开始工作了。
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);
}使用SolityVersion0.7.0编译后,得到函数参数所需的Uint256类型。换句话说,Uint32不起作用,但这不仅在编译和在混合内部测试之后是明确的。从最初的可靠源代码看不清楚..。
发布于 2022-05-02 18:57:45
根据sdk的单元测试,有三种情况下会抛出操作码:
当未设置合同函数参数时,
测试: ContractExecuteIntegrationTest
未设置合同函数时,
测试: ContractCallIntegrationTest
未设置构造函数参数时,
测试: ContractCreateIntegrationTest
金:-)
https://stackoverflow.com/questions/72089689
复制相似问题