✉️Fetch Quote
The fetchQuote method retrieves a quote for the specified amount in USD. The quote is used to calculate the corresponding token amount required for the card purchase. It expires in about 30 seconds.
Code Example:
const amount = "150.55"; // Amount in USD
const quote = await service.fetchQuote(amount);
Response:
The fetchQuote
method returns a quote object with the following fields:
id: Unique quote identifier.
token: Name or symbol of the token used to purchase the card. (e.g.,
"USDC"
,"TAO"
)targetCurrency: Currency code for the amount. (e.g.,
"USD"
)amountRequested: Amount of USD the card is being purchased for.
pricePerUnitCurrency: Price of the token per unit USD.
totalPrice: Total token amount needed for purchase.
platformFee: Any additional fees charged by the platform.
expiresIn: Time in milliseconds before the quote expires.
timestamp: Timestamp when the quote was generated.
status: Quote status.
Purchase Card
The purchaseCard
method initiates a virtual card purchase. It performs four main operations:
Approves token spending to the ZebecCard smart contract. (ERC20 tokens only)
Deposits tokens into the user's Zebec vault.
Initiates the card purchase on-chain. (ERC20 tokens only)
Posts transaction data, along with metadata, to the Zebec backend.
The method returns a tuple with responses from each stage of the process.
Code Example
For EVM compatible networks:
const participantId = "JohnChamling";
const firstName = "John";
const lastName = "Chamling";
const emailAddress = "[email protected]";
const mobilePhone = "+91 012345678";
const language = "en-US";
const city = "Bharatpur";
const state = "Bagmati";
const postalCode = "44200";
const countryCode: CountryCode = "NPL";
const address1 = "Shittal street, Bharatpur - 10, Chitwan";
const recipient = Recipient.create(
participantId,
firstName,
lastName,
emailAddress,
mobilePhone,
language,
city,
state,
postalCode,
countryCode,
address1,
);
const amount = "150.55";
const quote = await service.fetchQuote(amount);
const [depositResponse, buyCardResponse, apiResponse] = await service.purchaseCard({
amount,
recipient,
quote,
});
console.log("Deposit Transaction Hash:", depositResponse.hash);
console.log("Purchase Transaction Hash:", buyCardResponse.hash);
console.log("Zebec Server Response:", apiResponse.data);
For Bittensor Network:
const participantId = "JohnChamling";
const firstName = "John";
const lastName = "Chamling";
const emailAddress = "[email protected]";
const mobilePhone = "+91 012345678";
const language = "en-US";
const city = "Bharatpur";
const state = "Bagmati";
const postalCode = "44200";
const countryCode: CountryCode = "NPL";
const address1 = "Shittal street, Bharatpur - 10, Chitwan";
const recipient = Recipient.create(
participantId,
firstName,
lastName,
emailAddress,
mobilePhone,
language,
city,
state,
postalCode,
countryCode,
address1,
);
const amount = "150.55"; // Amount in USD
const quote = await service.fetchQuote(amount);
const [depositResponse, apiResponse] = await service.purchaseCard({
walletAddress: signer.address || "<wallet_address>",
amount,
recipient,
quote,
});
console.log(
`Deposit response: \n BlockHash: ${depositResponse.blockHash} \n TransactionHash: ${depositResponse.txHash}`,
);
console.log("Zebec Server Response:", apiResponse.data);
Last updated