Skip to main content

Wallets

Wallets are a crucial component of the ULedger ecosystem, serving as secure containers for digital assets and facilitating seamless transactions. This section provides an in-depth guide on working with ULedger wallets, including key operations like wallet creation, registration, serialization, and more.

Creating a New Wallet

The first step to getting started with ULedger wallets is creating a new one. To create a wallet, follow these steps:

Generate a Seed Phrase

A wallet in ULedger is securely generated using a seed phrase. This seed phrase is a sequence of words that act as a cryptographic key to your wallet. You can create a seed phrase using the ULedger SDK. Supported languages include English, Español, Français, Italiano, and Portuguese. Here's how to generate a seed phrase with 12 words in English:

word_list = WalletGenerator.get_seed_words(12, 'en')
print("Generated word list:", word_list)

Create a Wallet Instance

Once you have your seed phrase, you can create a ULedger Wallet instance using the seed phrase and specify the language used. This instance will serve as your wallet, allowing you to manage your digital assets securely.

my_wallet = WalletGenerator.create(word_list, 'en')
print(my_wallet)

Retrieve Wallet Information

You can access essential information from your wallet instance, such as the wallet's address and public key. Here are some commands to retrieve this information:

print("Wallet address:", my_wallet.get_address())
print("Public key in hexadecimal:", my_wallet.get_public_key_hex())

Registering the Wallet in a Blockchain

In order to start using your wallet, you need to register it with a specific blockchain. This registration associates your wallet with the blockchain, enabling you to send and receive transactions. While the process may differ for various blockchains, here's the basic idea:

blockchain_id = "some_blockchain_id"
node_url = "some_node_url"

my_wallet.register(blockchain_id, node_url)

Serializing and Saving the Wallet

It's essential to securely store and back up your wallet. ULedger provides a mechanism to serialize and save your wallet to a file. This ensures that you can restore your wallet in case of data loss or migration to a different device. Here's how to serialize and save your wallet:

serialized_wallet = WalletFactory.serialize(my_wallet)

# Choose where to save the wallet; in this example, we save it to a file.
file_path = "my_wallet.ukey"
with open(file_path, "w") as file:
file.write(serialized_wallet)
print(f"Wallet written to {file_path}")
info

You have the flexibility to manage your wallets in various storage solutions, including S3 buckets, databases, or any other persistence-based hosts.

Deserialize the wallet from the saved file

To restore your wallet from a serialized format, you can use the following steps:

wallet = WalletFactory.deserialize(serialized_wallet)
print("Wallet address:", wallet.get_address())

You can also enhance the security of your serialized wallet by encrypting it with a password. Here's how to serialize, save, and later deserialize a password-protected wallet:

serialized_wallet = WalletFactory.serialize(my_wallet, "my_very_secure_password")

file_path = "my_wallet_w_password.ukey"
with open(file_path, "w") as file:
file.write(serialized_wallet)
print(f"Wallet written to {file_path}")

wallet = WalletFactory.deserialize(serialized_wallet, "my_very_secure_password")
print("Wallet address:", wallet.get_address())
note

Ensure you keep your wallet and any password used for encryption secure, as they are crucial for accessing and managing your digital assets.

© 2023 ULedger Inc. All rights reserved