Back to Tutorials
Beginner10 min

Creating and Managing Accounts

Learn how to create wallets and manage private keys

Creating and Managing Accounts

In this tutorial, you'll learn how to create Beatoz accounts and manage private keys securely.

Security Warning

Never share your private key with anyone. Store it securely and never commit it to version control.

What is an Account?

A Beatoz account consists of:

  • Address: A 40-character hex identifier. SDK-created addresses may be returned without 0x; add the prefix when a UI such as Faucet asks for it.
  • Private Key: Secret key used to sign transactions
  • Public Key: Derived from the private key

Creating a New Account

const { Web3 } = require('@beatoz/web3');

const web3 = new Web3('https://rpc-testnet0.beatoz.io');

// Create a new random account
const account = web3.beatoz.accounts.create();

console.log('Address:', account.address);
console.log('Private Key:', account.privateKey);

Save Your Keys

Make sure to securely save your private key. You'll need it to access your account later.

Importing an Existing Account

If you already have a private key, you can import it:

const privateKey = '0x...your_private_key_here';
const account = web3.beatoz.accounts.privateKeyToAccount(privateKey);

console.log('Imported Address:', account.address);

Checking Account Balance

Testnet
async function checkBalance(address) {
  const accountInfo = await web3.beatoz.getAccount(address);
  
  // Convert from fons (smallest unit) to BTZ
  const balance = web3.utils.fromFons(accountInfo.value.balance, 'beatoz');
  
  console.log('Balance:', balance, 'BTZ');
  return balance;
}

// Usage
checkBalance(account.address);

Best Practices

  1. Never hardcode private keys - Use environment variables
  2. Use .env files - Add to .gitignore
  3. Backup your keys - Store in multiple secure locations
// Using environment variables
require('dotenv').config();

const privateKey = process.env.PRIVATE_KEY;
const account = web3.beatoz.accounts.privateKeyToAccount(privateKey);

You now know how to create and manage Beatoz accounts!

Next Steps

Beatoz Developer Portal