Constructor takes byte32 value. How send32 value, using web3.py or only python?


In web3.py v4+, you can send either a hex string, or native Python bytes, like:

  • It doesn't work because I get "Could not identify the intended function with name"
    – 0x3bfc
    Jun 11 '18 at 10:24
  • @aabdulwahed I'm guessing that you're using ConciseContract. Try it again without ConciseContract. If that doesn't solve your problem, please start a new question.
    – carver
    Jun 12 '18 at 22:12

How to convert/encode string to bytes32 in Python for Solidity bytes32 arguments via web3.py

zBytes = "YAY!! Less than 32"
#zBytes = "YAY!! We Are Going To Make Ethereum & Python Great! Go Crypto and Blockchain and DAG, etc...!!!"
len1 = len(zBytes)
if len1 > 32:
    print('input string length: '+ str(len1)+ ' is too long')
    zBytes32 = zBytes[:32]
    print('input string length: '+ str(len1)+ ' is too short')
    print('More characters needed: '+ str(32-len1))
    zBytes32 = zBytes.ljust(32, '0')
print('zBytes32 = '+ str(zBytes32)+ ' and its length: '+ str(len(zBytes32)))
xBytes32 = bytes(zBytes32, 'utf-8')
print('xBytes32 = '+ str(xBytes32))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.