Creating or Importing wallets

To start managing your SOL and SPL tokens, you need your address on blockchain. To do it, you need to do an integration with it by create a new wallet, or import already existing one (Terminal supports only Base58 private keys formula).

Create a new wallet

Creation of new address on Solana's blockchain is the fastest way to add another wallet to your list, it is a few-clicks operation (don't miss "Encryption" section).

def create_new_wallet(self):
    public_key, private_key, wallet_data, filename = create_wallet()
    if public_key:
        passphrase, dont_encrypt = self.prompt_for_passphrase("Encrypt New Wallet", allow_no_encrypt=True)
        if dont_encrypt:
            filepath = filename
            with open(filepath, 'w') as wallet_file:
                wallet_file.write(wallet_data)
            self.show_message(f"Wallet saved to {filepath}\nPublic Key: {public_key}", "Wallet Created")
        else:
            if not passphrase:
                self.show_message("Passphrase is required to encrypt the wallet.", "Error")
                return
            encrypted_data = encrypt_data(wallet_data.encode('utf-8'), passphrase)
            encrypted_filepath = filename.replace('.txt', '.dat')
            with open(encrypted_filepath, 'wb') as wallet_file:
                wallet_file.write(encrypted_data)
            self.show_message(f"Encrypted wallet saved to {encrypted_filepath}\nPublic Key: {public_key}", "Wallet Created")
        self.navigate_to(self.wallet_menu)
    else:
        self.show_message("Failed to create wallet.", "Error")

Import already existing wallet

If a user prefers to import wallet, which has been created before, he/she has such possibility. The only requierd action to does is gain a private key for Solana from external wallet, like Phantom, and paste it.

def import_wallet_action(self):
    private_key_base58 = self.private_key_entry.get()
    public_key, private_key_base58, wallet_data, filename = import_wallet(private_key_base58)
    
    if public_key:
        passphrase, dont_encrypt = self.prompt_for_passphrase("Encrypt Imported Wallet", allow_no_encrypt=True)
        
        if dont_encrypt:
            filepath = filename
            with open(filepath, 'w') as wallet_file:
                wallet_file.write(wallet_data)
            self.show_message(f"Wallet saved to {filepath}\nPublic Key: {public_key}", "Wallet Imported")
        else:
            if not passphrase:
                self.show_message("Passphrase is required to encrypt the wallet.", "Error")
                return
            encrypted_data = encrypt_data(wallet_data.encode('utf-8'), passphrase)
            encrypted_filename = filename.replace('.txt', '.dat')
            with open(encrypted_filename, 'wb') as wallet_file:
                wallet_file.write(encrypted_data)
            self.show_message(f"Encrypted wallet saved to {encrypted_filename}\nPublic Key: {public_key}", "Wallet Imported")
        
        self.navigate_to(self.wallet_menu)
    else:
        self.show_message("Invalid private key format.", "Error")

The Terminal in beta version supports only Base58 form, for now.

Last updated