【发布时间】:2021-10-13 10:22:57
【问题描述】:
我正在研究 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 发送到区块链:
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 不兼容。有没有办法解决这个问题?
【问题讨论】:
-
你在使用 web3.py 吗?
-
from web3 import Web3 -
你确实是:)
-
betcreation_txn = contract.functions.publishEvent(69295,1628516242331,24,28).buildTransaction({'from': <wallet>, 'value': 0,'gas': 3000000,'gasPrice': w3.toWei('1', 'gwei'),'nonce': nonce_var})signed_txn = w3.eth.account.sign_transaction(betcreation_txn, private_key=pk)result = w3.eth.send_raw_transaction(signed_txn.rawTransaction)这是代码...这适用于 'publishEvent(69295,1628516242331,24,28)'