Your First App

Let's generate a Bitcoin wallet, address, and private key in 3 steps.

Our first app will create a wallet for Bitcoin and Ethereum. We will also generate one blockchain address and one private key from the wallet.

What is a blockchain wallet, mnemonic, and private key?

Like Bitcoin or Ethereum, major public blockchains use the terms wallet, mnemonic, and private key. What's does all this mean?

In one wallet, you might have many blockchain addresses. A blockchain address is similar to a bank account. In a public blockchain, the blockchain address, balance, and all the transactions to/from the address are known by everyone. Each blockchain address has a corresponding private key. Anyone with a private key can send digital assets from the blockchain address to another one. Therefore, it is crucial to keep your private keys secure.

Similarly, as a blockchain address has a corresponding private key, each wallet has a corresponding mnemonic. A mnemonic is sometimes called a "seed phrase" and represents a wallet. The mnemonic allows you to create a new blockchain address and corresponding private key in the wallet, or recover a private key for a blockchain address that belongs to your wallet. Never reveal your mnemonic to anybody. Otherwise, you can lose all your funds.

To learn more about how public and private keys work, check out this article: https://www.mycryptopedia.com/public-key-private-key-explained/

Important

Before you can start using your newly created wallet on the testnet, you must charge it (add crypto funds to it).

To charge your wallet, use any public faucet compatible with your blockchain.

1. Getting your API key

This guide assumes you already have a Tatum account. Don't have an account? No worries. Sign up here. It's free.

2. Generating a Bitcoin wallet

The first step is to generate a wallet. Tatum supports many various blockchain protocols and thousands of digital assets. You can use our Tatum JS (our JavaScript SDK) or directly communicate with our REST API.

Let's generate a wallet for Bitcoin first.

// You need to install Javascript library
// https://github.com/tatumio/tatum-js
const {generateWallet, Currency} = require("@tatumio/tatum");

const btcWallet = await generateWallet(Currency.BTC, false);
console.log(btcWallet);

The output will look like this:

{
    "mnemonic": "panel result private alien mail remove shift mandate loyal analyst ghost mutual swear faint road raccoon patient cost kit impact believe fun brown way",
    "xpub": "xpub6FL3wUosaTYs2U4Tf8qk7XexhzHup8UHKhDKKMi72SJpip6QmBjPaeEwCkXmFscMC6B5n3Y6uHPoaxRUKHQRuYXAYCEs9kbhGVf2JXSjomi"
}

3. Creating a Bitcoin address

We can create more than 4 billion addresses from 1 wallet. Each address has its own unique index, so let's create an address with the number 1.

// Replace <<xpub>> with xpub you've got from step 2
const {generateAddressFromXPub, Currency} = require("@tatumio/tatum");

const btcAddress = generateAddressFromXPub(Currency.BTC, false, "<<xpub>>", 1);
console.log(btcAddress);

The output will look like this:

{
    "address": "1HDSRhBkAvvaij7SYmgyYerDPA2zP3Dxjf"
}

So there you have it. We've created a blockchain address for Bitcoin. We can now accept transactions at this address. To send a transaction from the address somewhere else, we need to know the private key to sign the transaction.

4. Creating a private key

Since we created address no. 1 for the Bitcoin wallet, we need to create a private key with the same index from our wallet.

Working with private keys

In this guide, we are using our API to create blockchain wallets and private keys, which is fine for testing and demo purposes.

However, for production use, your private keys and mnemonics should never leave your security perimeter. To correctly and securely generate wallets and work with private keys, we recommend using Tatum CLI **** from the command line or our complex key management system, Tatum KMS.

Here's the call to generate a private key for the address we have created:

// Replace <<mnemonic>> with xpub you've got from step 2
const {generatePrivateKeyFromMnemonic, Currency} = require("@tatumio/tatum");

const btcPrivateKey = await generatePrivateKeyFromMnemonic(Currency.BTC, false, "<<mnemonic>>", 1);
console.log({key: btcPrivateKey});

The output will look like this:

{
    "key":"KwrYonf8pFfyQR87NTn124Ep9zoJsZMBCoVUi7mjMc1eTHDyLyBN"
}

Now, we have a private key to our address and we can send Bitcoin from this address to anyone.

Never disclose your mnemonic or private keys to anyone!

Excellent work, congratulations on your first app! Now let's take a look at Tatum's architecture.

Last updated