0

I am trying to set a delegate with gnosis safe. The following code shows that we need to send a POST request with python3 to register a delegate with gnosis safe: https://safe-docs.dev.gnosisdev.com/safe/docs/tutorial_tx_service_set_delegate/ I have put the following code together in a script however i cannot get it to work

import requests
import time
import sha3

SAFE_ADDRESS = '*'
OWNER_PRIVATE_KEY = '*'
DELEGATE_ADDRESS = '*'
TX_SERVICE_BASE_URL = 'https://safe-transaction.rinkeby.gnosis.io'

totp = int(time.time()) // 3600
hash_to_sign = sha3.keccak_256(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"
}

print(list_response.text)
print(list_response.status_code)

when i run it i get this error: Traceback (most recent call last):

  File "test.py", line 11, in <module>
    hash_to_sign = sha3.keccak_256(text=DELEGATE_ADDRESS + str(totp))
TypeError: 'text' is an invalid keyword argument for sha3_224()

i've also tried to change keccak to 512 but its not working. How can i fix it?

  • Hm, I checked out the [code behind](https://github.com/tiran/pysha3/blob/5cbf015fb1fa5d8b6a61fb9187bf59739118d5ee/Modules/_sha3/clinic/sha3module.c.h#L6) `sha3_224` (the function throwing the error), and it seems that the correct keyword argument may be `string`, not `text`. Have you tried using that? – Brent Pappas Sep 13 '22 at 15:00
  • i just tried this i now get this error: TypeError: Unicode-objects must be encoded before hashing – admin admin Sep 13 '22 at 15:03
  • @BrentPappas any ideas? – admin admin Sep 13 '22 at 16:42
  • Maybe [try this](https://docs.python.org/3/library/stdtypes.html#str.encode)? `(DELEGATE_ADDRESS + str(totp)).encode('utf-8')` – Brent Pappas Sep 13 '22 at 17:06
  • @BrentPappas now the error is TypeError: can't concat str to bytes – admin admin Sep 13 '22 at 17:08

0 Answers0