Tatum
Search…
How to automatically scan blockchain addresses and set up webhook notifications
Create virtual accounts that update their balances to reflect incoming transactions at blockchain addresses and set up webhook notifications for a variety of blockchain events.

Automatic blockchain address scanning

Tatum's virtual accounts enable a variety of features otherwise unavailable on most blockchains. Their most crucial feature, and the one that opens the doors for all of the rest, is automatic scanning of blockchain addresses for incoming transactions.
Normally, to get the balances of blockchain addresses, you'd have to query each address every time you want to see if any transactions have been received. However, when you connect a virtual account to a blockchain address (or multiple addresses), it automatically detects incoming transactions at every connected address, and updates its balance accordingly.
This enables the other powerful features built-in to Tatum's virtual accounts, including...

Webhook notifications

If you’re building an exchange, marketplace, payment app, or any other kind of fintech solution, you’ll definitely want to be able to notify users about various types of blockchain events. Nobody wants to have to hit “refresh” in their PayPal account to know if they’ve received funds, and your app’s end-users shouldn’t have to either.
Blockchains do not natively support webhook notifications. However, since virtual accounts automatically scan blockchain addresses for incoming transactions, they are the perfect tool for setting up webhook notifications within your app.
In this guide, you'll learn to how to:
  1. 1.
    Create a virtual account
  2. 2.
    Create a blockchain address connected to the account
  3. 3.
    View all addresses connected to a virtual account
  4. 4.
    Set up webhook notifications for the account
  5. 5.
    Test your webhook notifications on testnet

How to automatically scan for incoming transactions

Create a virtual account

First we will create a virtual account to which we will connect a blockchain address (or addresses). To create a virtual account, we must enter the xpub from a blockchain wallet into the body of the API endpoint. This is the first connection between the blockchain and the virtual account.
To create a BTC blockchain wallet, please refer to the following guide:
To create wallets on any other supported blockchain, please refer to the blockchain's respective section in our API documentation.
Every virtual account is of a specific currency, which must be defined when it is created. This currency cannot be changed in the future (i.e. a BTC virtual account can only be connected to BTC addresses and will always be a BTC account).
We are going to set up a virtual account on the Bitcoin blockchain. For more information on how to set up guides on UTXO blockchains, blockchains like XRP, and account-based blockchains, please refer to the respective guides.
Use the following API endpoint to generate a virtual account from the xpub of a Bitcoin wallet.
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 --location --request POST 'https://api-eu1.tatum.io/v3/ledger/account' \
2
--header 'x-api-key: YOUR_API_KEY' \
3
--header 'Content-Type: application/json' \
4
--data-raw '{
5
"currency": "BTC",
6
"xpub": "tpubDE8GQ9vAXpwkp37PCCRUpCoeShpC4WiCcACxh8r3nnKjfRPRqw3w58EgkfNiBy1MaRqX1oAAxwAxauEUG7vWupSh5m15znGy7vE7aE6CWzb"
7
}'
Copied!
The response contains information about your newly generated virtual account.
Response
1
{
2
"currency": "BTC",
3
"active": true,
4
"balance": {
5
"accountBalance": "0",
6
"availableBalance": "0"
7
},
8
"frozen": false,
9
"xpub": "tpubDE8GQ9vAXpwkp37PCCRUpCoeShpC4WiCcACxh8r3nnKjfRPRqw3w58EgkfNiBy1MaRqX1oAAxwAxauEUG7vWupSh5m15znGy7vE7aE6CWzb",
10
"accountingCurrency": "EUR",
11
"id": "5fb7bdf6e96d9ab593e191a5"
12
}
Copied!
Virtual accounts can also be assigned to customers in Tatum. The customer inside Tatum is an entity containing information about your application's user, such as the customer's country of residence, accounting currency, etc.
To create a customer, you simply need to include an externalId field when creating a virtual account. This is an identifier of the user in your external system. More details are available in the API Reference.

Generate a blockchain address and connect it to the virtual account

Now that you've created a virtual account, you must synchronize it with the blockchain. Until you do, there is no blockchain address connected to the account, only a blockchain wallet from which addresses will be chosen.
Use the create new deposit address endpoint to generate an address for the 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 --location --request POST 'https://api-eu1.tatum.io/v3/offchain/account/5fb7bdf6e96d9ab593e191a5/address' \
2
--header 'x-api-key: YOUR_API_KEY'
Copied!
The response will contain the blockchain address you have just generated.
Response
1
{
2
"xpub": "tpubDE8GQ9vAXpwkp37PCCRUpCoeShpC4WiCcACxh8r3nnKjfRPRqw3w58EgkfNiBy1MaRqX1oAAxwAxauEUG7vWupSh5m15znGy7vE7aE6CWzb",
3
"derivationKey": 1,
4
"address": "mgSXLa5sJHvBpYTKZ62aW9z2YWQNTJ59Zm",
5
"currency": "BTC"
6
}
Copied!
Any incoming blockchain transaction to this address will be automatically synchronized to the virtual account.

View a list of blockchain addresses connected to an account

It is possible to work with only one blockchain address connected to the account, but you can also connect as many addresses as you want. The virtual account's balance will reflect the sum of all connected blockchain addresses.
Your app's users will most likely want to be able to see all of the addresses connected to their account. You can view all a list of them using the off-chain method Get all deposit addresses.
JavaScript
cURL
1
import { getDepositAddressesForAccount } from '@tatumio/tatum';
2
/**
3
* Get all deposit addresses generated for account.
4
* @param id - account ID
5
* @returns addresses detail - -
6
https://apidoc.tatum.io/tag/Blockchain-addresses/#operation/getAllDepositAddresses
7
*/
8
const addresses = getDepositAddressesForAccount ("5fb7bdf6e96d9ab593e191a5");
Copied!
1
curl --location --request GET 'https://api-eu1.tatum.io/v3/offchain/account/5fb7bdf6e96d9ab593e191a5/address' \
2
--header 'x-api-key: YOUR_API_KEY'
Copied!
The response will contain a list of all deposit addresses connected to the virtual account.
Response
1
[
2
{
3
"xpub": "tpubDE8GQ9vAXpwkp37PCCRUpCoeShpC4WiCcACxh8r3nnKjfRPRqw3w58EgkfNiBy1MaRqX1oAAxwAxauEUG7vWupSh5m15znGy7vE7aE6CWzb",
4
"derivationKey": 1,
5
"address": "mgSXLa5sJHvBpYTKZ62aW9z2YWQNTJ59Zm",
6
"currency": "BTC"
7
}
8
]
Copied!

How to set up webhook notifications

Now that we've created a virtual account and connected a blockchain address to it, we can set up webhook notifications for the address with just one more API call.
In Tatum virtual accounts, webhook notifications work as subscriptions to the accounts. When you set up a subscription, the account specified in the id field will be monitored for the blockchain event specified in the type field.
To set up webhook notifications for incoming blockchain transactions, use the following API call:
JavaScript
cURL
1
import { createNewSubscription, CreateSubscription, SubscriptionType } from '@tatumio/tatum'
2
3
export const createAccountIncomingBlockchainTransactionSubscription = async () => {
4
const data: CreateSubscription = {
5
"type": SubscriptionType.ACCOUNT_INCOMING_BLOCKCHAIN_TRANSACTION,
6
"attr": {
7
"id": "61eed3362a90644ef54a5018",
8
"url": "https://webhook.site/"
9
}
10
}
11
return await createNewSubscription(data)
12
}
Copied!
1
curl --request POST \
2
--url https://api-eu1.tatum.io/v3/subscription \
3
--header 'content-type: application/json' \
4
--header 'x-api-key: REPLACE_KEY_VALUE' \
5
--data '{
6
"type":"ACCOUNT_INCOMING_BLOCKCHAIN_TRANSACTION",
7
"attr":{
8
"id":"5e6be8e9e6aa436299950c41",
9
"url":"https://webhook.tatum.io/account"
10
}
11
}'
Copied!
The required parameters are for an incoming transactions subscription are:
  • type - the type of subscription you are creating
  • id - the ID of the virtual account or customer for which you are creating the subscription
  • url - the URL of the webhook listener you are using

Types of subscriptions:

  • Incoming transactions: ACCOUNT_INCOMING_BLOCKCHAIN_TRANSACTION
  • Pending transactions: ACCOUNT_PENDING_BLOCKCHAIN_TRANSACTION
  • Customer trade matches (in exchanges): CUSTOMER_TRADE_MATCH, CUSTOMER_PARTIAL_TRADE_MATCH
  • Transactions in specific blocks (outgoing): TRANSACTION_IN_THE_BLOCK
  • Tatum KMS completed/failed transactions: KMS_COMPLETED_TX , KMS_FAILED_TX
  • Outgoing transactions in the whole account: OFFCHAIN_WITHDRAWAL
  • Account balances above a certain limit: ACCOUNT_BALANCE_LIMIT
  • Transaction history reports: TRANSACTION_HISTORY_REPORT
Different types of subscriptions have different required parameters. For a full list of each type with example API endpoint bodies, please refer to our API documentation.

How to test your webhook notifications

To help you get the hang of how webhooks work with virtual accounts, we'd suggest giving it a try on a blockchain testnet (as you should with anything in blockchain development).
Once you've followed the above steps, you can test out your webhook notifications as follows:
  1. 1.
    Send some crypto from a testnet faucet on your blockchain of choice to the blockchain address connected to your virtual account (e.g. 0.001 BTC).
  2. 2.
    Check the blockchain address (either in the blockchain's explorer or using a get account balance endpoint in Tatum) to confirm that the transaction has arrived. This could take a little bit of time, so we'd suggest waiting a few minutes, then trying again in another 5 minutes if it hasn't arrived yet.
  3. 3.
    Check your virtual account's balance using this endpoint.
  4. 4.
    Now, check your webhook listener (the URL you entered when creating the subscription) to confirm that the webhook has correctly been sent.

And that's it!

You've successfully created a virtual account, connected a blockchain address to it, and set up webhook notifications. Now, anytime you send a funds to the blockchain address, it will be synced and visible in the account, and you will receive a webhook notification about the transaction.