3

I am working on a Solidity Smart Contract. The idea is to automate some of the tasks using Python. So I have this code:

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()}")

for which I get the following error:

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.

However, it works and send the tx to the blockchain when I ran this manually:

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

the function signature in Solidity:

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

So I guess the issue is that the data I am sending from Python is not compatible with Solidity u256. Is there any way to solve this?

TylerH
  • 20,799
  • 66
  • 75
  • 101
Martin Rasumoff
  • 1,463
  • 1
  • 11
  • 12
  • ```betcreation_txn = contract.functions.publishEvent(69295,1628516242331,24,28).buildTransaction({'from': , '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)``` this is the code...this works with 'publishEvent(69295,1628516242331,24,28)' – Martin Rasumoff Aug 09 '21 at 18:42

1 Answers1

1

I'd convert your x and y to this, like so:

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

EDIT: I have refactored this answer to convert the numpy int64's to Python int's using the numpy item() method.

dir
  • 661
  • 3
  • 13
  • Thanks a lot for the pointer...I am getting this error now... ```TypeError: Unsupported type: ''. Must be one of: bool, str, bytes, bytearrayor int.``` – Martin Rasumoff Aug 09 '21 at 18:47
  • @MartinRasumoff just gave it an edit, let me know how that works. – dir Aug 09 '21 at 18:50
  • thanks a lot sir....no, it did not...it is converting it as strings now: ```ValidationError: Could not identify the intended function with name `publishEvent`, positional argument(s) of type `(, , , )` 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. ``` have been working on this for 2 days now :( thanks for any pointer... – Martin Rasumoff Aug 09 '21 at 18:55
  • @MartinRasumoff try giving that answer a go, get rid of the toHex lines, and just use this `x` and `y` – dir Aug 09 '21 at 18:56
  • YES!!!!! now I am getting a gas error but at least not the data type!!!! Thanks a lot sir!!!!! – Martin Rasumoff Aug 09 '21 at 18:59
  • 1
    @MartinRasumoff :) happy coding, Solidity / Python / Numpy data types are a bit of a headache to deal with sometimes. – dir Aug 09 '21 at 18:59