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 blockchain wallet, mnemonic, and private key?

Like Bitcoin or Ethereum, major public blockchains are using the terms wallet, mnemonic, and private key. What's all that?

In one wallet, you might have many blockchain addresses. The blockchain address is similar to an account in the bank. In a public blockchain, the blockchain address and balance and all transactions on 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. It's, therefore, crucial to keep your private keys secure.

Similarly, as a blockchain address has a corresponding private key, each wallet has a corresponding mnemonic. Mnemonic is sometimes called "seed phrase", and represents a wallet. Thanks to the mnemonic, you can create a new blockchain address and corresponding private key in the wallet, or recover a private key for a blockchain address which 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/

1. Get 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. Generate a Bitcoin wallet

The first step is to generate a wallet. Tatum supports over 20 blockchains and digital assets. We can use REST API directly, or local libraries for JavaScript.

Let's generate a wallet for Bitcoin first.

Curl
Javascript
Curl
curl --request GET \
--url 'https://api-eu1.tatum.io/v3/bitcoin/wallet' \
--header 'accept: application/json' \
--header 'x-api-key: YOUR_API_KEY' # Use API key from step 1
Javascript
// You need to install Javascript library
// https://github.com/tatumio/tatum-js
const {generateWallet, Currency} = require("@tatumio/tatum");
const btcWallet = 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. Create 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.

Curl
Javascript
Curl
# Replace <<xpub>> with xpub you've got from step 2
curl --request GET \
--url 'https://api-eu1.tatum.io/v3/bitcoin/address/<<xpub>>/1' \
--header 'accept: application/json' \
--header 'x-api-key: YOUR_API_KEY'
Javascript
// 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"
}

We created a blockchain address for the Bitcoin. We can now accept transactions on this address. To send a transaction from my address somewhere else, we need to know the private key we can use to sign the transaction.

4. Create 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.

Curl
Javascript
Curl
# Replace <<mnemonic>> with mnemonic you've got from step 2
curl --request POST \
--url 'https://api-eu1.tatum.io/v3/bitcoin/wallet/priv' \
--header 'Content-Type: application/json' \
--header 'x-api-key: YOUR_API_KEY',
--data-raw '{
"mnemonic": "<<mnemonic>>",
"index": 1
}'
Javascript
// Replace <<mnemonic>> with mnemonic you've got from step 2
const {generatePrivateKeyFromMnemonic, Currency} = require("@tatumio/tatum");
const btcAddress = generatePrivateKeyFromMnemonic(Currency.BTC, false, "<<mnemonic>>", 1);
console.log(btcAddress);

The output will look like this:

{
"key": "L2JL4C4TDsHQejaBm3aw9WyVdVkoL4WfoHUMS11WMpFbWZVKw8yx"
}

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

Never disclose your mnemonic or private keys to anyone!

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