HomeGuidesRecipesAPI ReferenceChangelog
Log In
Guides
These docs are for v2.0.4. Click to read the latest docs for v2.1.7.

Token Preferences Service

Reference page for the Token Preferences Service Interface

Interface

interface ITokenPreferenceService {
  getUserTokenPreference(): Promise<GetUserTokenPreferenceResponse>
  updateUserTokenPreference(params: UpdateUserTokenPreferencesRequest): Promise<UpdateUserTokenPreferencesResponse>;
}

Structures used

Union types, Literal Types and Enums

type TokenPreferencePolygon = {
  currency: Currency;
  chain: Chain.POLYGON;
  token: PolygonToken;
};

type TokenPreferenceCelo = {
  currency: Currency;
  chain: Chain.CELO;
  token: CeloToken;
};

type TokenPreferenceOptimism = {
  currency: Currency;
  chain: Chain.OPTIMISM;
  token: OptimismToken;
};

type TokenPreferenceMainnet = {
  currency: Currency;
  chain: Chain.MAINNET;
  token: MainnetToken;
};

type TokenPreferenceArbitrum = {
  currency: Currency;
  chain: Chain.ARBITRUM;
  token: ArbitrumToken;
};

type TokenPreference =
  | TokenPreferencePolygon
  | TokenPreferenceCelo
  | TokenPreferenceOptimism
  | TokenPreferenceMainnet
  | TokenPreferenceArbitrum

type GetUserTokenPreferenceResponse = TokenPreference[]

UpdateUserTokenPreferencesRequest

Field NameType
preferencesTokenPreference[]

Service Methods

getUserTokenPreference

getUserTokenPreference(): Promise<GetUserTokenPreferenceResponse>
Overview

This method returns token preferences for each currency for a particular user.

Usage
Typescript
import getunblockSDK, { AuthenticationMethod } from "@getunblock/sdk";

(async () => {
  // setup SDK
  const sdk = getunblockSDK({
    apiKey:
      "API-Key [Some merchant Key]", // Key generated at the moment the merchant was created in getunblock system
    prod: false, // If true Production environment will be used otherwise Sandbox will be used instead
  });
  
  await sdk.auth.authenticateWithSiwe({
    message: "[Generated SIWE message]*",
    signature: "[Generated SIWE signature]*",
  });
  // * more info at https://docs.getunblock.com/docs/unblocker
  
  // SDK API call example
  const result = await sdk.tokenPreference.getUserTokenPreference();
})();
Javascript
const getunblockSDK = require("@getunblock/sdk").default;
const { AuthenticationMethod } = require("@getunblock/sdk"); 

(async () => {
  // setup SDK
  const sdk = getunblockSDK({
    apiKey:
      "API-Key [Some merchant Key]", // Key generated at the moment the merchant was created in getunblock system
    prod: false, // If true Production environment will be used otherwise Sandbox will be used instead
  });
  
  await sdk.auth.authenticateWithSiwe({    
    message: "[Generated SIWE message]*",
    signature: "[Generated SIWE signature]*",
  });
  // * more info at https://docs.getunblock.com/docs/unblocker
  
  // SDK API call example
  const result = await sdk.tokenPreference.getUserTokenPreference();
})();

updateUserTokenPreference

updateUserTokenPreference(params: UpdateUserTokenPreferencesRequest): Promise<UpdateUserTokenPreferencesResponse>
Overview

This method allows to change the token preferences by giving a currency and a token for a particular user

Usage
Typescript
import getunblockSDK, { AuthenticationMethod, Currency, OptimismToken, Chain } from "@getunblock/sdk";

(async () => {
  // setup SDK
  const sdk = getunblockSDK({
    apiKey:
      "API-Key [Some merchant Key]", // Key generated at the moment the merchant was created in getunblock system
    prod: false, // If true Production environment will be used otherwise Sandbox will be used instead
  });
  
  await sdk.auth.authenticateWithSiwe({    
    message: "[Generated SIWE message]*",
    signature: "[Generated SIWE signature]*",
  });
  // * more info at https://docs.getunblock.com/docs/unblocker
  
  // SDK API call example
  const result = await sdk.tokenPreference.updateUserTokenPreference({
    preferences: [
      {
        currency: Currency.EUR,
        chain: Chain.OPTIMISM,
        token: OptimismToken.USDC
      }
    ]
  });
})();
Javascript
const getunblockSDK = require("@getunblock/sdk").default;
const { AuthenticationMethod, Currency, Chain, OptimismToken } = require("@getunblock/sdk"); 

(async () => {
  // setup SDK
  const sdk = getunblockSDK({
    apiKey:
      "API-Key [Some merchant Key]", // Key generated at the moment the merchant was created in getunblock system
    prod: false, // If true Production environment will be used otherwise Sandbox will be used instead
  });
  
  await sdk.auth.authenticateWithSiwe({    
    message: "[Generated SIWE message]*",
    signature: "[Generated SIWE signature]*",
  });
  // * more info at https://docs.getunblock.com/docs/unblocker
  
  // SDK API call example
  const result = await sdk.tokenPreference.updateUserTokenPreference({
    preferences: [
      {
        currency: Currency.EUR,
        chain: Chain.OPTIMISM,
        token: OptimismToken.USDC
      }
    ]
  });
})();