Skip to content

Instantly share code, notes, and snippets.

@ochaloup
Last active May 22, 2023 06:47
Show Gist options
  • Save ochaloup/58ceee3ed436766ba7c444bf3fbc8545 to your computer and use it in GitHub Desktop.
Save ochaloup/58ceee3ed436766ba7c444bf3fbc8545 to your computer and use it in GitHub Desktop.
Python script to a binary uint8 array (decimal numbers) to base58 formatted string
#!~/.pyenv/shims/python3
# Usage:
# tobase58.py [3,0,0,0]
# Output:
# 5Sxr3
import base58
import sys
import json
if len(sys.argv) != 2:
print(f"Expecting one argument of json array listing uint items. The argument was not provided. Arguments: {sys.argv}")
exit(1)
json_string = sys.argv[1]
json_string = json_string.strip()
if not json_string.startswith("["):
print(f"Expecting the provided argument is a json array and starts with '[', but it is: {json_string}")
exit(2)
json_data = json.loads(json_string)
byte_array = bytearray(json_data)
print(base58.b58encode(byte_array).decode('utf-8'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment