I have code to convert ss58 address to a different parachain using polkadot{js}, such as below:

const { Keyring } = require("@polkadot/keyring");
const keyring = new Keyring();
keyring.encodeAddress("5EChUec3ZQhUvY1g52ZbfBVkqjUY9Kcr6mcEvQMbmd38shQL", 10);

What would be the equivalent is python using the py-substrate-interface?

  • where can i find the input/output id for each parachain?
    – a_dotter
    Commented Mar 23, 2023 at 21:55

1 Answer 1


py-substrate-interface provides helper functions for that in the utils.ss58 namespace.
Transforming an address from one chain-id to another can look like this:

from substrateinterface.utils.ss58 import ss58_decode, ss58_encode

addr = "5EChUec3ZQhUvY1g52ZbfBVkqjUY9Kcr6mcEvQMbmd38shQL"
# This is optional, but good for input validation.
input_id = 42
output_id = 10

pk = ss58_decode(addr, valid_ss58_format=input_id)
output = ss58_encode(pk, ss58_format=output_id)

print("Input  addr (network={}): {}".format(input_id, addr))
print("Output addr (network={}): {}".format(output_id, output))


Input  addr (network=42): 5EChUec3ZQhUvY1g52ZbfBVkqjUY9Kcr6mcEvQMbmd38shQL
Output addr (network=10): 231bCuH9G6iDvf4q5zQqaLzAACu8PTUC4ft3EXmxxG1Xs6HW

You can verify the results on polkadot-js https://polkadot.js.org/apps/#/utilities

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.