Topup with asset

The following tutorial demonstrates how to use Taxi HTTP JSON APIs to retrieve a topup tx.

Let's say, for example, that you want to transfer your USDt funds to somebody but you don't have any LBTC to pay for network fees.

You can check if Taxi supports paying for network fees in exchange for a USDt service fee.

const axios = require('axios');
const taxiBaseUrl = 'https://stage-api.liquid.taxi';
const usdt = 'f3d1ec678811398cd2ae277cbe3849c6f6dbd72c74bc542f7c4b11ff0e820958';
const fetchAssets = async () => {
const { data, status } = await axios.get(`${taxiBaseUrl}/v1/assets`);
if (status !== 200) {
throw new Error(data.message);
}
const assets = data.assets.map(details => details.assetHash);
if (assets.length === 0) {
throw new Error('Taxi list of supported assets is empty');
}
return assets;
}
const assetSupportedByTaxi = async (target) => {
const assets = await fetchAssets();
return assets.find(a => a === target) !== undefined;
}
async function main() {
try {
// Retrieve the list of supported assets.
if (!await assetSupportedByTaxi(usdt)) {
throw new Error('Taxi does not support usdt as topup service fee');
}
}
}
main();

To request a topup you need to specify the service fee asset, an approximate estimation of the size of your tx (take into account that Taxi always adds 1 input, 1 output and the fee output to it) and the sats/vByte ratio expressed in mSats/vB (1 sats/vB = 1000 mSats/vB).

const fetchTopupWithAsset = async (targetAsset) => {
const { data, status } = await axios.post(`${taxiBaseUrl}/v1/asset/topup`, {
assetHash: targetAsset,
estimatedTxSize: 300,
millisatPerByte: 100,
});
if (status !== 200) {
throw new Error(data.message);
}
return data;
};
async function main() {
try {
const topup = await fetchTopupWithAsset(usdt);
console.log('Topup details:', topup);
} catch (e) {
console.error(e);
}
}
main();

The response object returned by the HTTP JSON endpoint is like the following:

{
"topup": {
"topupId": "f4ee76e8-54cd-491d-a222-e403dcb782e3",
"partial": "cHNldP8BAgQCAAAAAQQBAQEFAQIBBgEDAfsEAgAAAAABAXoLOwF9vzTZzwI3IUrwZoc0t+fnZi1/QlEKJE/0FPSN4hgJCIfe700nDa6FmnSiuJt0PSWEd5eX9T0pQTzsohxNh9MDkUdU+BZ4RqNoalpDyEk32Of3jRO79NjewEgoRVBXG4kWAB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OuhXwDAby31cWb9k+db1j3nnuFMohyBvNEJkz20ql/w1W4HlLGbyB8RsgAqyb4IetZJaeuNyzfVYdAiWjwoEC6Q4nQHKFgBoGvatTjykX8jVZCy7DkS4E8su6TG7qxmmR43eLFWxGabh8Yde/H0X8E3yK0Z09uC1iy6yJ0HJqoLJFBWiL4TikZRrd6fxEk44o3GmJWxq/itD2jg4VbvjxXt87VIVKbDiQmbti4riqFjgCXh3yFPbRRyb3BLYvCnyWEFL05PlZ2QjeIUqwROqXxEIk6FTWPb0T1X5Cvua+9fb+Fv6+LTJGt7EbEKtvNaRi0s8OwiFv03frTGnqwbADsRvomdngCqlmPf2Dn3J1L1SEwA8TkcufmeF0uoVL4VUQqsCy7bjoMqInX5WtN/DFUJeBCrYOBoIg6XxGUkJ//u84Dq/kAAQMIwNinAAAAAAABBBYAFKF+8PBQSpfwOMOpLq2rnDs62bKHB/wEcHNldAIgWAmCDv8RS3wvVLx0LNfb9sZJOL58J67SjDkRiGfs0fMH/ARwc2V0CAQAAAAAAAEDCPQBAAAAAAAAAQQAB/wEcHNldAIgSZqBhUX2uuOfwDtjfypOHmTlkMrBvDpvbXGqRENlTBQH/ARwc2V0CAQAAAAAAA=="
},
"expiry": "1663770843",
"assetHash": "f3d1ec678811398cd2ae277cbe3849c6f6dbd72c74bc542f7c4b11ff0e820958",
"assetAmount": "11000000",
"inBlindingData": [
{
"asset": "144c654344aa716d6f3abcc1ca90e5641e4e2a7f633bc09fe3baf64585819a49",
"value": "500",
"assetBlinder": "OEcE1xA/okJ75IGI6XA3ABt4MgmuKdUxxPwVoPboElo=",
"valueBlinder": "Qs0a8O3cGFHCzjtzCSQnn8oFYobJBKd4RatS2oKyHJ8="
}
]
}
  • topup.topupId is the id of the topup that Taxi uses internally to uniquely identify it.
  • topup.partial is the pset created by Taxi to which you can add inputs and outputs to transfer your funds. The tx contains exactly 1 LBTC input and 2 outputs. The input is entirely spent by the fee output. The maximum final tx size, or the number of inputs and outputs you can add to it, depends on the fee amount and the sats/vByte ratio you passed in the request. The second output is the service fee, that you must pay with your funds.
  • expiry is the unix timestamp of the expiration date for the topup. After that date, if Taxi doesn't see the topup tx included in blockchain, it takes care of creating another tx and transfer the same input to one of its addresses. Any later attempt to broadcast the topup tx fails because Taxi's input has already been spent.
  • assetHash is the service fee asset, exactly the one passed in the request object.
  • assetAmount is the service fee amount that you must pay with your own funds.
  • inBlindingData is the list of unblinded data of the confidential inputs added by Taxi to the topup tx (always 1 tx input, therefore 1 entry). Includes the unblinded asset, value and relative blinders. Note that the blinders are encoded in base64 standard encoding instead of "normal" hex encoding, just because this is the standard format for the representation of raw bytes in HTTP JSON objects.

The complete version of the tutorial with instructions to run a live demo can be found on Github.