Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to convert bounceable address to non bounceable address #41

Open
smiles-leon opened this issue Aug 7, 2024 · 1 comment
Open

How to convert bounceable address to non bounceable address #41

smiles-leon opened this issue Aug 7, 2024 · 1 comment

Comments

@smiles-leon
Copy link

smiles-leon commented Aug 7, 2024

i'm try to convert 'kQAvlWFDxGF2lXm67y4yzC17wYKD9A0guwPkMs1gOsM__GgZ' to 'EQAvlWFDxGF2lXm67y4yzC17wYKD9A0guwPkMs1gOsM__NOT',
I tried changing the is_bounceable parameter, but it didn't work.

from tonsdk.utils import Address

def convert_to_base64_format(address):
    try:
        # 判断并处理Hex格式地址
        if address.startswith('0:') or address.startswith('-1:'):
            # 创建Address对象
            addr = Address(address)
        elif address.startswith('EQ') or address.startswith('kQ'):
            # 创建Address对象
            addr = Address(address)
        else:
            raise ValueError("Unsupported address format")

        # 将地址转换为Base64 URL安全编码格式(可弹回)
        base64_address = addr.to_string(1, is_bounceable=True, is_url_safe=True)
        return base64_address
    except Exception as e:
        return f"Error: {e}"


# 示例地址
address1 = "EQAvlWFDxGF2lXm67y4yzC17wYKD9A0guwPkMs1gOsM__NOT"
address2 = "0:2f956143c461769579baef2e32cc2d7bc18283f40d20bb03e432cd603ac33ffc"
address3 = "kQAvlWFDxGF2lXm67y4yzC17wYKD9A0guwPkMs1gOsM__GgZ"

# 转换地址
converted_address1 = convert_to_base64_format(address1)
converted_address2 = convert_to_base64_format(address2)
converted_address3 = convert_to_base64_format(address3)

print(f"Converted Address 1: {converted_address1}")
print(f"Converted Address 2: {converted_address2}")
print(f"Converted Address 3: {converted_address3}")

The result is

Converted Address 1: EQAvlWFDxGF2lXm67y4yzC17wYKD9A0guwPkMs1gOsM__NOT
Converted Address 2: EQAvlWFDxGF2lXm67y4yzC17wYKD9A0guwPkMs1gOsM__NOT
Converted Address 3: kQAvlWFDxGF2lXm67y4yzC17wYKD9A0guwPkMs1gOsM__GgZ
@FaiqAli-dot
Copy link

did you find any solution for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants