Enable Tokens

Overview

To enable token functionality on certain blockchains, you must create a token enablement transaction. Once enabled, you can use your wallet to engage in token functionality, such as governance or decentralized apps (dApps). BitGo currently supports token enablement for ALGO, HBAR, and SOL.

Token-enablement transactions follow the normal transaction flow, requiring signatures, approvals, and sending, as outlined in Wallets Overview.

Prerequisites

Steps

const BitGoJS = require('bitgo');
const Promise = require('bluebird');

const bitgo = new BitGoJS.BitGo({ env: 'test' });

const coin = 'talgo:KAL-16026733';


// Set your wallet id
const walletId = 'your wallet id';

// Set your wallet passphrase
const walletPassphrase = 'set your wallet passphrase here';

// Set your OTP
const otp = '000000';

// Set your access token
const accessToken = 'insert access token string here';

const address = 'your root address or address of same wallet';

Promise.coroutine(function* () {
  bitgo.authenticateWithAccessToken({ accessToken });

  const wallet = yield bitgo.coin(coin).wallets().get({ id: walletId });

  console.log('Wallet ID:', wallet.id());
  console.log('Root Address:', wallet.coinSpecific().rootAddress);
  console.log('Balance:', wallet.balanceString());
  console.log('Confirmed Balance:', wallet.confirmedBalanceString());
  console.log('Spendable Balance:', wallet.spendableBalanceString());

  const unlock = yield bitgo.unlock({ otp, duration: 3600 });
  if (!unlock) {
    throw new Error('We did not unlock.');
  }
  try {
    const txEnableToken = yield wallet.sendMany({
      type: 'enabletoken',
      recipients: [
        {
          amount: '0',
          address: address,
        },
      ],
      feeRate: 1,
      walletPassphrase,
    });
    console.dir(txEnableToken, { depth: 6 });
  } catch (e) {
    console.error(e);
  }
})().catch((e) => console.error(e));
const BitGo = require("bitgo");
const bitgo = new BitGo.BitGo({
  env: "custom",
  customRootURI: "",
});

// Set your access token
const accessToken = "";

// Set your wallet id
const walletId = "";

// Set your wallet passphrase
const passphrase = "test_wallet_passphrase";

const coin = "thbar";

async function enableToken(walletId) {
  const wallet = await bitgo.coin(coin).wallets().getWallet({ id: walletId });
  const result = await wallet.sendTokenEnablements({
    enableTokens: [{ name: "thbar:usdc" }],
  });
  console.log(JSON.stringify(result, undefined, 2));
  console.log(JSON.stringify(enableTokens, undefined, 2));
}

main().catch((e) => console.error(e));
const BitGo = require('bitgo');
const bitgo = new BitGo.BitGo({
  env: 'custom',
  customRootURI: '',
});

// Set your access token
const accessToken = '';

// Set your wallet id
const walletId = '';

// Set your wallet passphrase
const passphrase = 'test_wallet_passphrase';

const coin = 'tsol';

// Enable tokens for your root wallet
async function main() {
  bitgo.authenticateWithAccessToken({ accessToken });
  const wallet = await bitgo.coin(coin).wallets().get({ id: walletId });

  const enableTokens = await wallet.sendTokenEnablements({
    enableTokens: [
      // provide name of tokens you want to enable
      { name: 'tsol:usdc' },
      { name: 'tsol:usdt' },
    ],
    walletPassphrase: passphrase,
  });

  console.log(JSON.stringify(enableTokens, undefined, 2));
}

main().catch((e) => console.error(e));

Step Result

Once the transaction confirms on chain, you can use your tokens.

{
  "transfer": {
    "id": "64b6e6ae54dbbf0007004719b943a64f",
    "coin": "tsol",
    "wallet": "64b586faf9070d00079036fd748c0f3e",
    "walletType": "hot",
    "txid": "LH6XRYgheXWgBKM169Txi2eWhUtsmumo324wipz7iNwoaFCHjh33pTJo1fF7GE9G9uq5iwWaCuoMvsZNUuNT4GK",
    "type": "send",
    "value": -4083560,
    "valueString": "-4083560",
    "feeString": "4083560",
    "usd": -0.1050699988,
    "usdRate": 25.73,
    "state": "signed"
  }
}

Next

Sign the transaction.