SDKs

This documentation covers the usage of the DeFi API, focusing on their main API classes.

Configuration

Before using any of the APIs, you need to set up the configuration:

import { Configuration } from '@blockdaemon/blockdaemon-defi-api-typescript-fetch';

export const apiConfig = new Configuration({
  basePath: "https://svc.blockdaemon.com/defi",
  headers: {
    authorization: `Bearer ${process.env.BLOCKDAEMON_API_KEY}`,
  },
});

Make sure to set your Blockdaemon API key in the .env file.

ExchangeApi

The ExchangeApi provides endpoints for exchanging assets.

Instantiation

import { ExchangeApi } from '@blockdaemon/blockdaemon-defi-api-typescript-fetch';

const exchangeAPI = new ExchangeApi(apiConfig);

Methods

getRoutes

Provides a list of possible routes for Asset Exchange, detailing each route's steps, tokens, and amounts.

async getRoutes(requestParameters: GetRoutesRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<RoutesResponse>
  • requestParameters: An object of type GetRoutesRequest containing the necessary parameters for the route request.
  • initOverrides: Optional parameter to override initialization.

Returns a Promise that resolves to a RoutesResponse object.

getRoutesRaw

Similar to getRoutes, but returns the raw API response.

async getRoutesRaw(requestParameters: GetRoutesRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<RoutesResponse>>

AccountApi

The AccountApi provides endpoints for interactions with accounts, particularly for managing ERC20 token approvals.

Instantiation

import { AccountApi } from '@blockdaemon/blockdaemon-defi-api-typescript-fetch';

const accountAPI = new AccountApi(apiConfig);

Methods

deleteTokenApproval

Deletes an ERC20 token approval. (Beta)

async deleteTokenApproval(requestParameters: DeleteTokenApprovalRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<TokenApprovalResponse>

getTokenApproval

Lists ERC20 token approvals by Account address and Token address or symbol for a given Chain.

async getTokenApproval(requestParameters: GetTokenApprovalRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<TokenApprovalData>

modifyTokenApproval

Creates or modifies an ERC20 token approval.

async modifyTokenApproval(requestParameters: ModifyTokenApprovalRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<TokenApprovalResponse>

Each method also has a corresponding *Raw method that returns the raw API response.

StatusApi

The StatusApi provides endpoints for retrieving transaction statuses.

Instantiation

import { StatusApi } from '@blockdaemon/blockdaemon-defi-api-typescript-fetch';

const statusAPI = new StatusApi(apiConfig);

Methods

getStatus

Retrieves the status of a transaction using its transaction ID.

async getStatus(requestParameters: GetStatusRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<StatusResponse>
  • requestParameters: An object of type GetStatusRequest containing the necessary parameters for the status request.
  • initOverrides: Optional parameter to override initialization.

Returns a Promise that resolves to a StatusResponse object.

getStatusRaw

Similar to getStatus, but returns the raw API response.

async getStatusRaw(requestParameters: GetStatusRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<StatusResponse>>

ChainsApi

The ChainsApi provides endpoints for fetching information about supported blockchain networks.

Instantiation

import { ChainsApi } from '@blockdaemon/blockdaemon-defi-api-typescript-fetch';

const api = new ChainsApi(apiConfig);

Methods

getChains

Get supported chains return metadata about each supported blockchain network.

async getChains(requestParameters?: GetChainsRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<Chains>

Example usage:

const chainsParameters: GetChainsRequest = {
  chainName: "polygon",
};

const chains = await api.getChains(chainsParameters);

getChainsRaw

Similar to getChains, but returns the raw API response.

async getChainsRaw(requestParameters: GetChainsRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<Chains>>

PriceApi

The PriceApi provides endpoints for fetching price information for tokens.

Instantiation

import { PriceApi } from '@blockdaemon/blockdaemon-defi-api-typescript-fetch';

const api = new PriceApi(apiConfig);

Methods

getPrice

Get the price for one or more specific tokens on a specified chain.

async getPrice(requestParameters: GetPriceRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<TokenPrices>

Example usage:

const request: PriceRequest = {
  chainID: "1",
  tokens: [
    "0x0000000000000000000000000000000000000000",
    "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
  ],
  currency: "USD" as CurrencyCode,
};

const prices = await api.getPrice({ priceRequest: request });

getPriceRaw

Similar to getPrice, but returns the raw API response.

async getPriceRaw(requestParameters: GetPriceRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<TokenPrices>>

TokensApi

The TokensApi provides endpoints for fetching information about tokens.

Instantiation

import { TokensApi } from '@blockdaemon/blockdaemon-defi-api-typescript-fetch';

const api = new TokensApi(apiConfig);

Methods

getTokenTags

Get list of token tags.

async getTokenTags(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<Tags>

Example usage:

const tags = await api.getTokenTags();
console.log(JSON.stringify(tags, null, 2));

getTokens

Get list of tokens with metadata.

async getTokens(requestParameters?: GetTokensRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<TokenList>

Example usage:

const tokensParameters: GetTokensRequest = {
  tagLimit: ["stablecoin"],
  chainID: "1",
};

const tokens = await api.getTokens(tokensParameters);

getTokenTagsRaw and getTokensRaw

Similar to their counterparts, but return the raw API response.

async getTokenTagsRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<Tags>>

async getTokensRaw(requestParameters: GetTokensRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<TokenList>>

Additional Information

Please refer to the SDK's type definitions for more details on specific request and response types. The API also includes endpoints for other operations related to chains, tokens, prices, integrations, and lending/borrowing, which are not covered in this documentation.

This SDK is based on the following API tags:

  • account: API endpoints for interactions with accounts
  • chains: API endpoints for fetching information about blockchains
  • exchange: API endpoints for exchanging assets
  • tokens: API endpoints for fetching information about tokens
  • status: Operations related to transaction statuses
  • price: Operations related to fetching asset prices
  • integrations: Operations related to fetching integration details
  • lend-borrow: Operations related to lending and borrowing

You can also check https://github.com/Blockdaemon/defi-api-examples for examples.