Token

JavaScript Token Functions

Buy with fiat​

Description​

Returns a url of a widget where the user can buy a Token using a credit / debit card see the Token Checkout integration guidelines for more details about this feature.

Parameters​

NameTypeRequiredDescription

tokenID

String

✔️

The ID of the Token, the widget will collect the data to present the Token from the backend

data

Record<any, any>

Extra data that diffuses to the backend

toWalletAddress

String

The wallet address that the Token will be send to, If the wallet was created by tweed the wallet address will be populated automatically.

amount

String

The default amount of the Token displayed on the widget. The user can modify this value.

Return type​

Promise<string>

Example of usage​

await sdk.token.buyWithFiat({
  tokenId: '1',
  toWalletAddress: '0x123456789',
  amount: '1',
})

Get balance​

Description​

Returns the current balance of tokens in the user's wallet for multiple blockchains

Parameters​

NameTypeRequiredDefaultDescription

blockchainIds

String[]

defaultBlockchainIds

Blockchain ids

Return type​

Promise<{
   [blockchainId: string]: {
      value: string
      tokenMetadata: {
        tokenAddress: string
        tokenDecimals: string
        tokenName: string
        tokenSymbol: string
      }
   }[]
}>

Usage Example​

const balance = await sdk.token.getBalance()
// or
const balance = await sdk.token.getBalance({ blockchainIds: ['ethereum', 'polygon'] })

Response Example​

{
  "ethereum": [
    {
      "value": "0.12",
      "tokenMetadata": {
        "tokenAddress": "0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0",
        "tokenDecimals": "18",
        "tokenName": "Polygon Matic",
        "tokenSymbol": "MATIC"
      }
    }
  ],
  "polygon": []
}

Get transactions​

Description​

Returns a list of token transactions for multiple blockchains

Parameters​

NameTypeRequiredDefaultDescription

blockchainIds

String[]

defaultBlockchainIds

Blockchain ids

Return type​

Promise<{
  [blockchainId: string] : {
    createdAt: string
    value: string
    tokenMetadata: {
      tokenDecimals: string
      tokenName: string
      tokenSymbol: string
    }
    toAddress: string,
    fromAddress: string
    direction: string
    gasUsed: string
    gasLimit: number
    gasPrice: string
    id: string
    status: string
    type: "buy" | "fund" | "receive" | "sell" | "send"
  }[]
}>

Usage Example​

const transactions = await sdk.token.getTransactions()
// or
const transactions = await sdk.token.getTransactions({ blockchainIds: ['ethereum', 'polygon'] })

Response Example​

{
  "tezosGhost": [
    {
      "createdAt": "2023-06-29T07:48:00Z",
      "value": "3.0",
      "tokenMetadata": {
        "tokenAddress": "KT1AfUy48JvqVvtcXKxBDy1guDTJSWd1n8Uv",
        "tokenDecimals": "18",
        "tokenName": "Kolibri USD",
        "tokenSymbol": "kUSD"
      },
      "nonce": "16941458",
      "direction": "incoming",
      "toAddress": "tz1NpGHrD9qNZNnXWTyVYkPgq3DvdhC7hDho",
      "fromAddress": "tz1Vr7wLtVvpCdmLTTNPgt8rP9vjmFxRMSWg",
      "gasUsed": "3219",
      "id": "opaoXY13tkcrYeok4BmXRAFGTffCD5RyyWhWrB9kubR1aduPPC3",
      "gasPrice": "0",
      "status": "completed",
      "type": "receive"
    },
    {
      "createdAt": "2023-06-29T07:47:41Z",
      "value": "3.0",
      "tokenMetadata": {
        "tokenAddress": "KT1H9hKtcqcMHuCoaisu8Qy7wutoUPFELcLm",
        "tokenDecimals": "6",
        "tokenName": "Tether USD",
        "tokenSymbol": "USDT"
      },
      "gas": "3619",
      "nonce": "16941457",
      "direction": "incoming",
      "toAddress": "tz1NpGHrD9qNZNnXWTyVYkPgq3DvdhC7hDho",
      "fromAddress": "tz1Vr7wLtVvpCdmLTTNPgt8rP9vjmFxRMSWg",
      "gasUsed": "3619",
      "id": "oovjQ5YiHaD3Tsw7ukF9qYzsB1iSm6PWooDUPXh13FeMkja1Sm4",
      "gasPrice": "0",
      "status": "completed",
      "type": "receive"
    }
  ],
  "ethereumSepolia": [
    {
      "fromAddress": "0x3a27c671c01be1b8ba8fd0be94e8cfe5f77fc67b",
      "toAddress": "0x2f42ee19146b55f624ebd9ea66d3919ba13eec8b",
      "value": "1.0",
      "tokenAddress": "0xe15501dd8857a885defe240147ea3b1c998855be",
      "gasUsed": "52155",
      "gasPrice": "4926498365",
      "direction": "incoming",
      "createdAt": "2023-06-28T08:17:58Z",
      "tokenMetadata": {
        "tokenSymbol": "TW",
        "tokenName": "Tweed",
        "tokenDecimals": "18",
        "tokenAddress": "0xe15501dd8857a885defe240147ea3b1c998855be"
      },
      "id": "0x01e3183570f73a714cdc876916e6d83d8246b8aa0ad8da7975f5bc258822c4bc",
      "nonce": "1",
      "status": "completed",
      "type": "send"
    },
    {
      "fromAddress": "0x0000000000000000000000000000000000000000",
      "toAddress": "0x3a27c671c01be1b8ba8fd0be94e8cfe5f77fc67b",
      "value": "2000000.0",
      "tokenAddress": "0xe15501dd8857a885defe240147ea3b1c998855be",
      "gasUsed": "37081",
      "gasPrice": "15684032508",
      "direction": "incoming",
      "createdAt": "2023-06-28T08:17:58Z",
      "tokenMetadata": {
        "tokenSymbol": "TW",
        "tokenName": "Tweed",
        "tokenDecimals": "18",
        "tokenAddress": "0xe15501dd8857a885defe240147ea3b1c998855be"
      },
      "id": "0xd07bbacb39570e8442207a3a8dcd4392294ec9ba37d089e67206ee5a9e58f084",
      "nonce": "10",
      "status": "completed",
      "type": "receive"
    },
    {
      "fromAddress": "0x0000000000000000000000000000000000000000",
      "toAddress": "0x3a27c671c01be1b8ba8fd0be94e8cfe5f77fc67b",
      "value": "0.0000000002",
      "tokenAddress": "0xe15501dd8857a885defe240147ea3b1c998855be",
      "gasUsed": "71221",
      "gasPrice": "13720111665",
      "direction": "incoming",
      "createdAt": "2023-06-28T08:17:58Z",
      "tokenMetadata": {
        "tokenSymbol": "TW",
        "tokenName": "Tweed",
        "tokenDecimals": "18",
        "tokenAddress": "0xe15501dd8857a885defe240147ea3b1c998855be"
      },
      "id": "0x29b1be7296483450ef8e437911e1900832ca10ec88caeb5c05d15f3fd60b0769",
      "nonce": "9",
      "status": "completed",
      "type": "receive"
    }
  ]
}

Send to user​

Description​

Sends a token to another user on the platform by its user ID. The user will get a Sign Transaction widget to approve the transaction.

Parameters​

NameTypeRequiredDefaultDescription

blockchainId

String

✔️

Blockchain

value

String

✔️

value of crypto

tokenAddress

String

✔️

The contract address of the token

userId

String

✔️

Id of user to send crypto to

Return type​

Promise<string>

Usage Example​

await sdk.token.sendToUser({
  blockchainId: 'ethereum',
  value: '1.2',
  tokenAddress: '0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0',
  userId: '1',
})

Send to wallet​

Description​

Sends a token to other wallet by its wallet address. The user will get a Sign Transaction widget to approve the transaction.

Parameters​

NameTypeRequiredDefaultDescription

blockchainId

String

✔️

Blockchain

value

String

✔️

value of crypto

tokenAddress

String

✔️

The contract address of the token

walletAddress

String

✔️

Address of wallet to send crypto to

Return type​

Promise<string>

Usage Example​

await sdk.token.sendToWallet({
  blockchainId: 'ethereum',
  value: '1.2',
  tokenAddress: '0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0',
  walletAddress: '0x15b895d74582daea01be8e5be264243d8c9d7bb1',
})

Last updated