We currently use a python script to get fingerprints from assetName and policy id. However we are resorting to using the cardano bech32 binary for the final part of the process.

from hashlib import blake2b
from subprocess import check_output
import binascii
import bech32
import sys

policyId = '60a75d4bfee53ebe583679faed1fba8a8921abfd685dbc76e313032a'
tokenId = '416433763173446576696c7331313739'
binary_asset = binascii.unhexlify(policyId + tokenId)
output = blake2b(binary_asset, digest_size=20).hexdigest()
output = check_output([f"/home/bech32bin/bech32.sh", str(output)]).decode(sys.stdout.encoding).strip()


### output is asset1rgafp0kmehn9ws6g9224fyjd550wakdhlupk0k (correct)

Where the contents of bech32.sh are:

/home/bech32bin/bech32 asset <<< $1

This utilises the bech32 binary for the final stage of the process detailed in pseudocode here https://cips.cardano.org/cips/cip14/

Does anyone have an idea for a pythonic method of doing the last part. Without having to call a subprocess (which is slow, especially when looping through on potentially thousands of nfts) I assume with pythons inbuilt bech32 lib but have been unable to replicate.

1 Answer 1


By last part I assume you mean just the bech32.sh. If so, you can use the below :

encodedstr=bech32.bech32_encode("prefix",bech32.convertbits(bytes.fromhex(hexstr), 8, 5))
  • 1
    perfect. TY mate. Commented Jul 6, 2022 at 11:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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