首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用简单的比较运算符调用hedera智能契约函数会导致CONTRACT_REVERT_EXECUTED状态失败

使用简单的比较运算符调用hedera智能契约函数会导致CONTRACT_REVERT_EXECUTED状态失败
EN

Stack Overflow用户
提问于 2022-05-02 16:36:55
回答 2查看 351关注 0票数 0

对新手的问题很抱歉。我正在试验hedera合同。每当试图调用一个简单的函数(将uint参数与契约的uint成员进行比较)时,我就会系统地获得一个CONTRACT_REVERT_EXECUTED状态。

固体

代码语言:javascript
复制
    function compare(uint number_) public view returns (bool){
        
        return (number_ > secret_number);
    }

java

代码语言:javascript
复制
    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)

我在这里做错什么了?

任何帮助都非常感谢!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2022-05-25 12:21:23

在正确设置合同函数参数后,我终于开始工作了。

代码语言:javascript
复制
    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不起作用,但这不仅在编译和在混合内部测试之后是明确的。从最初的可靠源代码看不清楚..。

票数 0
EN

Stack Overflow用户

发布于 2022-05-02 18:57:45

根据sdk的单元测试,有三种情况下会抛出操作码:

当未设置合同函数参数时,

  1. 无法执行合同

测试: ContractExecuteIntegrationTest

未设置合同函数时,

  1. 无法调用合同函数

测试: ContractCallIntegrationTest

未设置构造函数参数时,

  1. 无法创建契约

测试: ContractCreateIntegrationTest

金:-)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72089689

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档