智能合约返回hexbytes对象,而不是int

问题描述 投票:0回答:1

我正在开发一个智能合约,当我使用web3.py用python脚本调用它时,它应该返回1,但是我在Python脚本中没有得到1,而是收到了一个hexbytes对象。我想我需要使用ABI和web3.py对其进行解码,但我不知道如何?

<class 'hexbytes.main.HexBytes'>
0x3791e76f3c1244722e60f72ac062765fca0c00c25ac8d5fcb22c5a9637c3706d

有人可以帮忙吗?

python hex ethereum solidity smartcontracts
1个回答
0
投票

我确实具有这样的功能:

function test(int a) public returns (int) {
        if(a > 0){
            return 1;
        }
    }

当我用python脚本调用它时:

con = contract.functions.test(52).transact()
print(con.hex())

我有这样的结果:

<class 'hexbytes.main.HexBytes'>
0x3791e76f3c1244722e60f72ac062765fca0c00c25ac8d5fcb22c5a9637c3706d
© www.soinside.com 2019 - 2024. All rights reserved.