gpt4 book ai didi

Python 相当于 Solidity u256

转载 作者:行者123 更新时间:2023-12-05 05:57:48 24 4
gpt4 key购买 nike

我正在研究 Solidity 智能合约。这个想法是使用 Python 来自动化一些任务。所以我有这段代码:

idx = 1
event_id = cDF.iloc[idx]["A"].astype(int)
event_date = cDF.iloc[idx]["B"].astype(int)
x = cDF.iloc[idx]["C"].astype(int)
y = cDF.iloc[idx]["D"].astype(int)

a = 69295
print(type(a))
print(type(event_id))

txcreation_txn = contract.functions.publishEvent(event_id, event_date, x, y).buildTransaction({
'from': <some_testing_wallet>,
'value': 0,
'gas': 3000000000000,
'gasPrice': w3.toWei('1', 'gwei'),
'nonce': nonce_var})
signed_txn = w3.eth.account.sign_transaction(txcreation_txn, private_key=private_key)
result = w3.eth.send_raw_transaction(signed_txn.rawTransaction)
print(f"result # {idx} - {result.hex()}")

为此我收到以下错误:

Could not identify the intended function with name `publishEvent`, positional argument(s) of type 
`(<class 'numpy.int64'>, <class 'numpy.int64'>, <class 'numpy.int64'>, <class 'numpy.int64'>)` and keyword
argument(s) of type `{}`.
Found 1 function(s) with the name `publishEvent`: ['publishEvent(uint256,uint256,uint256,uint256)']
Function invocation failed due to no matching argument types.

但是,当我手动运行它时,它可以工作并将 tx 发送到区 block 链:

betcreation_txn = contract.functions.publishEvent(69295,1628516242331,24,28)
.buildTransaction({'from': '0xDaf36E4570e2f0A587331b8E1E3645Ce8861B6A5', 'value': 0,
'gas': 3000000,'gasPrice': w3.toWei('1', 'gwei'),'nonce': nonce_var})

Solidity 中的函数签名:

  function publishEvent(uint256 _event_id, uint256 _event_date, uint256 _x, uint256 _y) payable public

所以我猜问题是我从 Python 发送的数据与 Solidity u256 不兼容。有什么办法可以解决吗?

最佳答案

我会将你的 xy 转换成这样,如下所示:

x = cDF.iloc[idx]["C"].astype(int).item()
y = cDF.iloc[idx]["D"].astype(int).item()

编辑:我重构了这个答案,使用 numpy item() method 将 numpy int64 转换为 Python int .

关于Python 相当于 Solidity u256,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68716896/

24 4 0