i am trying to run the following python3 script however i am struggling to get keccak working:
import sha3
import requests
import time
SAFE_ADDRESS = '0x***'
OWNER_PRIVATE_KEY = '****'
DELEGATE_ADDRESS = '****'
TX_SERVICE_BASE_URL = 'https://safe-transaction.rinkeby.gnosis.io'
totp = int(time.time()) // 3600
hash_to_sign = keccak(text=DELEGATE_ADDRESS + str(totp))
account = Account.from_key(OWNER_PRIVATE_KEY)
signature = account.signHash(hash_to_sign)
add_payload = {
"safe": SAFE_ADDRESS,
"delegate": DELEGATE_ADDRESS,
"signature": signature.signature.hex(),
"label": "My new delegate2"
}
add_response = requests.post(f'{TX_SERVICE_BASE_URL}/api/v1/safes/{SAFE_ADDRESS}/delegates/', json=add_payload, headers = {'Content-type': 'application/json'})
print(add_response.text)
print(add_response.status_code)
i get the following error:
Traceback (most recent call last):
File "test.py", line 14, in <module>
hash_to_sign = keccak(text=DELEGATE_ADDRESS + str(totp))
NameError: name 'keccak' is not defined
additionally i have tried to replace import sha3 with from Crypto.Hash import keccak
but this time i get this error:
Traceback (most recent call last):
File "test.py", line 14, in <module>
hash_to_sign = keccak(text=DELEGATE_ADDRESS + str(totp))
TypeError: 'module' object is not callable
how can i fix this?