微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

从智能合约交易中获取解码输出

如何解决从智能合约交易中获取解码输出

我正在使用以下代码通过 web3j 执行智能合约的功能

Credentials creds = getCredentialsFromPrivateKey("private-key");
            RawTransactionManager manager = new RawTransactionManager(web3j,creds);
            String contractAddress = "0x1278f8c858d799fe1010cfc0d1eeb56508243a4d";
            BigInteger sum = new BigInteger("10000000000"); // amount you want to send
            String data = encodeTransferData(sum);
            BigInteger gasPrice = web3j.ethGasPrice().send().getGasPrice();
            BigInteger gasLimit = BigInteger.valueOf(120000); // set gas limit here
            EthSendTransaction transaction = manager.sendTransaction(gasPrice,gasLimit,contractAddress,data,null);
            System.out.println(transaction.getTransactionHash());

它执行正常并且函数运行,但是我不知道如何读取合约给出的输出,我如何读取该输出

解决方法

以太坊交易哈希是交易的唯一ID。有了这个交易哈希,你就可以从网络上查询交易状态。

底层 JSON-RPC 调用称为 eth_getTransactionReceipt。这是Web3.js documentation

如果您的智能合约发出事件,您可以also read those

,

这将返回函数调用的十六进制值

"" 私有静态列表 executeCall(Function function) 抛出 IOException { String encodingFunction = FunctionEncoder.encode(function); org.web3j.protocol.core.methods.response.EthCall ethCall = web3j.ethCall( Transaction.createEthCallTransaction( "0x753ebAf6F6D5C2e3E6D469DEc5694Cd3Aa1A0c21","0x47480bac30de77cd030b8a8dad2d6a2ecdb7f27a",编码函数),DefaultBlockParameterName.LATEST) 。发送(); 字符串值 = ethCall.getValue(); System.out.println(value); System.out.println(FunctionReturnDecoder.decode(value,function.getOutputParameters())); return FunctionReturnDecoder.decode(value,function.getOutputParameters()); }""

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?