Untitled
unknown
python
a year ago
1.3 kB
28
Indexable
import numpy as np
import logging
import asyncio
import base64
from pytoniq import LiteClient
from pytoniq.contract.wallets import WalletV4R2
client = LiteClient.from_testnet_config(trust_level=2)
async def string_to_public_key(public_key_str: str) -> bytes:
return base64.b64decode(public_key_str)
async def generate_positive_int32(exclude_value=698983191):
while True:
random_value = int(np.random.randint(1, np.iinfo(np.int32).max, dtype=np.int32))
if random_value != exclude_value:
return random_value
await asyncio.sleep(0)
async def new_wallet_with_public_key(str_public_key):
random_num = await generate_positive_int32()
try:
await client.connect()
public_key = await string_to_public_key(str_public_key)
wallet = await WalletV4R2.from_data(provider=client, public_key=public_key, wallet_id=random_num)
address = wallet.address.to_str(is_bounceable=True)
print(address)
logging.info(f'Created wallet with address -> {wallet.address} bounceable address -> {address}')
await client.close()
return address
except Exception as e:
logging.error(e)
await client.close()
if __name__ == "__main__":
asyncio.run(new_wallet_with_public_key("<pub key>"))
Editor is loading...
Leave a Comment