Tatum
Search…
How to set up virtual accounts with BTC, LTC, DOGE, and BCH
Create multiple virtual accounts from the same xpub for UTXO blockchains to allow your users to send instant, feeless transactions.
Tatum Virtual Accounts offer unique capabilities to send cryptocurrencies between accounts instantly and without incurring blockchain fees. For each type of blockchain, virtual accounts must be set up in a specific way so that they will integrate and function seamlessly with your app's backend.
In this guide, you will learn how to set up virtual accounts to work with the UTXO blockchains we support:
  • Bitcoin (BTC)
  • LiteCoin (LTC)
  • Doge (DOGE)
  • Bitcoin Cash (BCH)

Generate a wallet

In this guide, we will generate just one blockchain wallet for all of our virtual accounts. All of the virtual accounts within your app must be connected to the same wallet. If virtual accounts are connected to deposit addresses generated from different extended public keys (xpubs) from different wallets, they will not function properly.
In this guide, we will use examples for the Bitcoin blockchain, but the process is the same for all of the other blockchains listed above.
To generate a Bitcoin wallet, use the following API endpoint:
JavaScript
cURL
cURL + KMS
1
// You need to install the Javascript library
2
// https://github.com/tatumio/tatum-js
3
const {generateWallet, Currency} = require("@tatumio/tatum");
4
5
const btcWallet = generateWallet(Currency.BTC, false);
6
console.log(btcWallet);
Copied!
1
curl --request GET \
2
--url 'https://api-eu1.tatum.io/v3/bitcoin/wallet?mnemonic=SOME_STRING_VALUE' \
3
--header 'x-api-key: REPLACE_KEY_VALUE'
Copied!
1
tatum-kms storemanagedwallet BTC --testnet
Copied!
The response will contain the wallet's mnemonic and xpub.
Response
1
{
2
mnemonic: 'north today grit rate brand atom swift act surround stool lumber neither salon solution labor buyer celery coach clarify poet clown next culture melt',
3
xpub: 'tpubDEvtqDzBrGVtGJ3yvSV8khBNFa5FVTFu25YQTKfDQUvSp2zFcQzy1dPgKXKHBzKgygHeefpp4ASmJCi5x9bjiJzbJ9XQczd76NgrS1tzZY1'
4
}
Copied!

Create virtual accounts

Now, you can generate BTC virtual accounts connected to the xpub of the wallet you have just generated. You can generate as many virtual accounts as you want, but they must all be connected to the same xpub in order to function properly.
The reason virtual accounts for UTXO blockchains must be generated from the same xpub, is that UTXO blockchains are capable of performing multiple transactions at once. If the virtual accounts were generated from different xpubs, it would be impossible to keep track of which assets were being sent from which wallet.
Use the following API endpoint to generate BTC virtual accounts. In the "xpub" field, enter the xpub of the wallet you generated in the previous step.
JavaScript
cURL
1
import { Account, Currency, CreateAccount, createAccount } from "@tatumio/tatum";
2
import { config } from "dotenv";
3
4
config();
5
6
const createNewAccount = async () => {
7
const createAccountData: CreateAccount = {
8
currency: Currency.BTC,
9
xpub: wallet.address
10
};
11
const accoun: Account = await createAccount(createAccountData);
12
console.log(accoun);
13
};
14
15
createNewAccount();
Copied!
1
curl --request POST \
2
--url https://api-eu1.tatum.io/v3/ledger/account \
3
--header 'content-type: application/json' \
4
--header 'x-api-key: REPLACE_KEY_VALUE' \
5
--data '{
6
"currency":"BTC",
7
"xpub":"tpubDEvtqDzBrGVtGJ3yvSV8khBNFa5FVTFu25YQTKfDQUvSp2zFcQzy1dPgKXKHBzKgygHeefpp4ASmJCi5x9bjiJzbJ9XQczd76NgrS1tzZY1",
8
"customer":{
9
"accountingCurrency":"USD",
10
"customerCountry":"US",
11
"externalId":"123654",
12
"providerCountry":"US"
13
},
14
"compliant":false,
15
"accountCode":"AC_1011_B",
16
"accountingCurrency":"USD",
17
"accountNumber":"123456"
18
}'
Copied!
Response
1
{
2
currency: 'BTC',
3
active: true,
4
balance: { accountBalance: '0', availableBalance: '0' },
5
frozen: false,
6
xpub: 'tpubDEvtqDzBrGVtGJ3yvSV8khBNFa5FVTFu25YQTKfDQUvSp2zFcQzy1dPgKXKHBzKgygHeefpp4ASmJCi5x9bjiJzbJ9XQczd76NgrS1tzZY1',
7
accountingCurrency: 'USD',
8
id: '61afba85997b887f543fa7f0'
9
}
Copied!

Create deposit addresses

Finally, we create deposit addresses for each virtual account. Again, these deposit addresses MUST be generated from the xpub of the wallet we generated in the first step. If they are not generated from the same xpub, they will not function properly.
Use the following API endpoint to generate deposit addresses for each virtual account:
JavaScript
cURL
1
import { generateDepositAddress, Address } from "@tatumio/tatum";
2
import { config } from "dotenv";
3
4
config();
5
6
const createNewDepositAddress = async () => {
7
const id = account.id;
8
const address: Address = await generateDepositAddress(id);
9
console.log(address);
10
};
11
12
createNewDepositAddress();
Copied!
1
curl --request POST \
2
--url 'https://api-eu1.tatum.io/v3/offchain/account/{id}/address?index=1' \
3
--header 'x-api-key: REPLACE_KEY_VALUE'
Copied!
Response
1
{
2
address: 'mfX9GBTff8mBBskwFPfGjyAGiTi3eS61aN',
3
currency: 'BTC',
4
derivationKey: 0,
5
xpub: 'tpubDEvtqDzBrGVtGJ3yvSV8khBNFa5FVTFu25YQTKfDQUvSp2zFcQzy1dPgKXKHBzKgygHeefpp4ASmJCi5x9bjiJzbJ9XQczd76NgrS1tzZY1'
6
}
Copied!
If you want to generate virtual accounts from different xpubs, you won't be able to perform instant transactions between them. Only virtual accounts generated from the same xpub will be able to perform transactions between one another.
And that's it! Now your virtual accounts should work perfectly and your users can send feeless, instant transactions to each other.