LoginSignup
1
2

More than 5 years have passed since last update.

Ethereum: Web3.pyで取得したトランザクション・ハッシュを文字列へ変換する

Posted at

メモ書き。Web3.pyでtx_hashを扱う場合は str(tx_hash) しても素直に文字列にならないので注意。
以下のように変換する必要がある。

tx_hash.hex()

原因

Web3.py でトランザクションを取得する場合、返り値の型は <class 'hexbytes.main.HexBytes'> であるため。

吐かれるエラーの例

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xbb in position 0: invalid start byte

環境

  • Python 3.6.1
  • AWS Lambda
  • Web3.py 4.2.0
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2