Tatum
Search…
How to withdraw assets from virtual accounts with gas pump wallets
This guide describes how to withdraw assets from virtual accounts connected to gas pump wallets. We will cover the whole flow of the user journey - gas pump wallet generation, virtual account creation, and withdrawal from the gas pump wallet to the blockchain address with correct virtual account balance updates.

Wallet generation

The first step is to create a gas pump wallet for every user. You can choose which ERC-* standards you want to support in the wallet - native assets like ETH or BSC are supported by default. In this example, we will support the native currency (MATIC) on Polygon and any ERC-20 tokens running on the Polygon network.
Request
Response
1
curl --location --request POST 'https://api-eu1.tatum.io/v3/blockchain/sc/custodial' \
2
--header 'Content-Type: application/json' \
3
--header 'x-api-key: YOUR_API_KEY' \
4
--data-raw '{
5
"enableFungibleTokens": true,
6
"enableNonFungibleTokens": false,
7
"enableSemiFungibleTokens": false,
8
"enableBatchTransactions": true,
9
"chain": "MATIC",
10
"fromPrivateKey": "0x37b091fc4ce46a56da643f021254612551dbe0944679a6e09cb5724d3085c9ab"
11
}'
Copied!
1
{
2
"txId": "0x2979a3d30f812b0d9ebcc66d01b620d3779380c38e8770a82fa4ea4f2dfa8f69"
3
}
Copied!
The response is the transaction hash. From this hash, we can find the address of the contract - our gas pump address.

Virtual account creation

Now, for every user, we need to create a virtual account. Since we have decided to support MATIC and USDC for every user, we need to create 2 virtual accounts - MATIC and USDC. These accounts do not have xpubs because we will manually assign the address to them later.
Request
Response
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": "MATIC"
6
}'
7
8
curl --location --request POST 'https://api-eu1.tatum.io/v3/ledger/account' \
9
--header 'x-api-key: YOUR_API_KEY' \
10
--header 'Content-Type: application/json' \
11
--data-raw '{
12
"currency": "USDC_MATIC"
13
}'
Copied!
1
{
2
"currency": "MATIC",
3
"active": true,
4
"balance": {
5
"accountBalance": "0",
6
"availableBalance": "0"
7
},
8
"frozen": false,
9
"accountingCurrency": "EUR",
10
"id": "5fb7bdf6e96d9ab593e191a5"
11
}
12
13
{
14
"currency": "USDC_MATIC",
15
"active": true,
16
"balance": {
17
"accountBalance": "0",
18
"availableBalance": "0"
19
},
20
"frozen": false,
21
"accountingCurrency": "EUR",
22
"id": "5fb7bdf6e96d9ab593e191a6"
23
}
Copied!
Once an account has been created, we need to assign the gas pump address to it. This process enables automatic incoming transaction synchronization for the specified address and currency.
Request
Response
1
curl --location --request POST 'https://api-eu1.tatum.io/v3/offchain/account/5fb7bdf6e96d9ab593e191a5/address/0x8Fca331d13E518059191Dde43765ea77C6C98336' \
2
--header 'x-api-key: YOUR_API_KEY'
Copied!
1
{
2
"address": "0x8Fca331d13E518059191Dde43765ea77C6C98336",
3
"currency": "MATIC"
4
}
Copied!
The result is a blockchain address that has been connected to a virtual account. Any incoming blockchain transaction to this address will be automatically detected and the account balance will be updated.

Withdraw assets from the account

The following 3 steps are necessary to withdraw assets from a virtual account and send them to the blockchain:
    1.
    Create a withdrawal request to the virtual account - it will debit the withdrawn balance from the virtual account
    2.
    Perform a transfer of the assets from the gas pump address - this will result in the blockchain transaction.
    3.
    Mark the withdrawal from the 1st step as completed.
Let's withdraw 1 USDC from an account to the blockchain.

Perform a withdrawal

To make the virtual account balance in sync, you need to perform a withdrawal operation from that account.
Request
Response
1
curl --location --request POST 'https://api-eu1.tatum.io/v3/offchain/withdrawal' \
2
--header 'x-api-key: YOUR_API_KEY' \
3
--header 'Content-Type: application/json' \
4
--data-raw '{
5
"senderAccountId":"5fb7bdf6e96d9ab593e191a6",
6
"address":"0x42952e30fB119e0683607Ef6D5A7E8A97dBB7314",
7
"amount":"1"
8
}'
Copied!
1
{
2
"reference": "5e6be8e9e6aa436299950c41",
3
"id": "5e68c66581f2ee32bc354087"
4
}
Copied!
The result is the virtual account transaction reference and the ID of the withdrawal. The account balance has been debited with 1 USDC and the transaction is visible in the list of the transactions for the virtual account. We still haven't done anything on the blockchain.

Perform a blockchain transaction

Now it's time to move the assets to another address. You don't have to send any MATIC there to pay for gas. You only need to specify which assets should be sent, how much of them, and where to send them.
Request
Response
1
curl --location --request POST 'https://api-eu1.tatum.io/v3/blockchain/sc/custodial/transfer' \
2
--header 'Content-Type: application/json' \
3
--header 'x-api-key: YOUR_API_KEY' \
4
--data-raw '{
5
"chain": "MATIC",
6
"contractType": 0,
7
"amount": "1",
8
"tokenAddress": "0x2791bca1f2de4661ed88a30c99a7a9449aa84174",
9
"custodialAddress": "0x8Fca331d13E518059191Dde43765ea77C6C98336",
10
"recipient": "0x42952e30fB119e0683607Ef6D5A7E8A97dBB7314",
11
"fromPrivateKey": "0x37b091fc4ce46a56da643f021254612551dbe0944679a6e09cb5724d3085c9ab"
12
}'
Copied!
1
{
2
"txId": "0xa1bdc0008b6cce138cec38336a3cbbf1117cc56bcfe0004e14d6789a9d099b72"
3
}
Copied!
The response is the transaction hash. As you can see, we have to enter the address of the token we want to transfer (tokenAddress 0x2791bca1f2de4661ed88a30c99a7a9449aa84174). The contractType attribute is very important, as it tells the wallet which kind of a token it is transferring - 0 for ERC-20 assets.

Complete or cancel the withdrawal

Once the transaction is successful, you need to mark the withdrawal as completed. If the transaction fails and you want to refund the assets to the virtual account, you need to cancel the original withdrawal request.
That's it. 5 simple steps to connect your gas pump wallets to virtual accounts and keep them synced.
Last modified 1mo ago