Skip to content

Latest commit

 

History

History
236 lines (173 loc) · 18 KB

File metadata and controls

236 lines (173 loc) · 18 KB

Token

(token)

Overview

Available Operations

tokenPrice

Retrieves the price of a token in USD.

Example Usage

import { CompassApiSDK } from "@compass-labs/api-sdk";

const compassApiSDK = new CompassApiSDK({
  apiKeyAuth: "<YOUR_API_KEY_HERE>",
});

async function run() {
  const result = await compassApiSDK.token.tokenPrice({
    token: "USDC",
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { CompassApiSDKCore } from "@compass-labs/api-sdk/core.js";
import { tokenTokenPrice } from "@compass-labs/api-sdk/funcs/tokenTokenPrice.js";

// Use `CompassApiSDKCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const compassApiSDK = new CompassApiSDKCore({
  apiKeyAuth: "<YOUR_API_KEY_HERE>",
});

async function run() {
  const res = await tokenTokenPrice(compassApiSDK, {
    token: "USDC",
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("tokenTokenPrice failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
request operations.V1TokenPriceRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<components.TokenPriceResponse>

Errors

Error Type Status Code Content Type
errors.HTTPValidationError 422 application/json
errors.APIError 4XX, 5XX */*

tokenBalance

Returns the balance of a specific ERC20 token for a given user address.

Example Usage

import { CompassApiSDK } from "@compass-labs/api-sdk";

const compassApiSDK = new CompassApiSDK({
  apiKeyAuth: "<YOUR_API_KEY_HERE>",
});

async function run() {
  const result = await compassApiSDK.token.tokenBalance({});

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { CompassApiSDKCore } from "@compass-labs/api-sdk/core.js";
import { tokenTokenBalance } from "@compass-labs/api-sdk/funcs/tokenTokenBalance.js";

// Use `CompassApiSDKCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const compassApiSDK = new CompassApiSDKCore({
  apiKeyAuth: "<YOUR_API_KEY_HERE>",
});

async function run() {
  const res = await tokenTokenBalance(compassApiSDK, {});
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("tokenTokenBalance failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
request operations.V1TokenBalanceRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<components.TokenBalanceResponse>

Errors

Error Type Status Code Content Type
errors.HTTPValidationError 422 application/json
errors.APIError 4XX, 5XX */*

tokenTransfer

Sends native ETH or ERC20 tokens from the sender's address to another address.

Example Usage

import { CompassApiSDK } from "@compass-labs/api-sdk";

const compassApiSDK = new CompassApiSDK({
  apiKeyAuth: "<YOUR_API_KEY_HERE>",
});

async function run() {
  const result = await compassApiSDK.token.tokenTransfer({
    to: "0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc44",
    token: "USDC",
    amount: 1.5,
    chain: "ethereum",
    sender: "0x29F20a192328eF1aD35e1564aBFf4Be9C5ce5f7B",
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { CompassApiSDKCore } from "@compass-labs/api-sdk/core.js";
import { tokenTokenTransfer } from "@compass-labs/api-sdk/funcs/tokenTokenTransfer.js";

// Use `CompassApiSDKCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const compassApiSDK = new CompassApiSDKCore({
  apiKeyAuth: "<YOUR_API_KEY_HERE>",
});

async function run() {
  const res = await tokenTokenTransfer(compassApiSDK, {
    to: "0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc44",
    token: "USDC",
    amount: 1.5,
    chain: "ethereum",
    sender: "0x29F20a192328eF1aD35e1564aBFf4Be9C5ce5f7B",
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("tokenTokenTransfer failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
request components.TokenTransferRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<components.TransactionResponse>

Errors

Error Type Status Code Content Type
errors.HTTPValidationError 422 application/json
errors.APIError 4XX, 5XX */*