Deposit

TanX offers various SDKs in different languages to facilitate seamless deposits to its platform. This document outlines the deposit process through the JavaScript (JS) SDK. For additional SDK options, refer to the SDK Reference

Please visit tanX website and create an account using your wallet before proceeding with the below steps.

Deposit Process

1. Install the NPM Package

npm i @tanx-libs/tanx-connector

2. Create an Instance

import { Client } from '@tanx-libs/tanx-connector';

// Create an instance with either testnet or mainnet
const client = new Client();
// or
const client = new Client('testnet'); // default is mainnet

Deposit Options

Two primary deposit methods are supported:

1. Ethereum Deposit

1.1 Using ETH Private Key and RPC URL

To deposit using an Ethereum private key and RPC URL, follow these steps:

  1. Set up an RPC provider URL pointing to an Ethereum node.

  2. Use the ETH private key corresponding to the sender's Ethereum address.

  3. Specify the network (testnet or mainnet), coin symbol, and amount.

  4. Execute the deposit transaction.

const res = await client.depositFromEthereumNetwork(
  process.env.RPC_PROVIDER as string, // Replace with your RPC URL.
  privateKey, // Your ETH private key.
  'testnet', // Network: 'testnet' or 'mainnet'.
  'eth', // Coin symbol.
  0.00001, // Amount to deposit.
);

1.2 Using Custom Provider and Signer

Alternatively, you can use a custom provider and signer:

  1. Create a JSON-RPC provider instance.

  2. Generate a signer with the private key and provider.

  3. Execute the deposit transaction.

import { Wallet, ethers } from 'ethers';

const provider = new ethers.providers.JsonRpcProvider(process.env.RPC_PROVIDER);
const signer = new Wallet(privateKey, provider);

const depositRes = await client.depositFromEthereumNetworkWithStarkKey(
  signer,
  provider,
  `0x${stark_public_key}`,
  0.0000001,
  'eth',
);

2. Cross-Chain Deposit

There are two protocols to make a deposit on the Cross-chain: one is EVM (Ethereum-supported chain) and the other is Starknet deposit.

2.1 EVM Cross-Chain Deposit

Supported EVM cross-chain networks - 'POLYGON' | 'OPTIMISM' | 'ARBITRUM' | 'LINEA' | 'SCROLL' | 'MODE'

2.1.1 Using ETH Private Key and RPC URL

To initiate a cross-chain deposit:

  1. Set up an RPC provider URL pointing to an Ethereum node.

  2. Use the ETH private key corresponding to the sender's Ethereum address.

  3. Specify the target network (e.g., 'POLYGON', 'OPTIMISM', etc.), the coin symbol, and the amount to deposit.

  4. Submit the transaction to execute the cross-chain deposit.

const depositRes = await client.crossChainDeposit(
  process.env.RPC_PROVIDER as string, // Replace with your RPC URL.
  privateKey, // Your ETH private key.
  'usdt', // Coin symbol.
  1, // Amount to deposit.
  'SCROLL', // Network to deposit into.
  // Optional: Gas limit and gas price.
  {
    gasLimit: '',
    gasPrice: '',
  },
);

2.1.2 Using Custom Provider and Signer

Alternatively, you can use a custom provider and signer:

  1. Create a JSON-RPC provider instance.

  2. Generate a signer with the private key and provider.

  3. Specify the network (testnet or mainnet), coin symbol, and amount.

  4. Execute the deposit transaction.

const provider = new ethers.providers.JsonRpcProvider(process.env.RPC_PROVIDER);
const signer = new Wallet(privateKey, provider);

const depositPolygonRes = await client.crossChainDepositWithSigner(
  signer,
  provider,
  'usdc', // Coin symbol.
  0.00001, // Amount to deposit.
  'SCROLL', // Network to deposit into.
  // Optional: Gas limit and gas price.
  {
    gasLimit: '',
    gasPrice: '',
  },
);

2.2 Starknet Cross-Chain Deposit

Currently, Starknet deposits are only supported on the tanX mainnet.

2.2.1 Using Starknet Private Key and RPC URL

To initiate a cross-chain deposit:

  1. Set up an RPC provider URL pointing to an Starknet.

  2. Use the Starknet private key corresponding to the sender's starknet address.

  3. Specify the coin symbol, and amount.

  4. Submit the transaction to execute the starknet deposit.

 const depositRes = await client.starknetDeposit(
    '14', // Enter the amount you want to deposit.
    'usdc', // Enter the coin symbol.
    process.env.STARKNET_RPC_PROVIDER as string, // Replace your RPC URL based on your destination network.
    starknetPublicKey as string,  // Your starknet public address.
    starknetPrivateKey as string,  // Your starknet private key.
 );

2.2.2 Using Custom Provider and Signer

Alternatively, you can use a custom provider and signer:

  1. Create a JSON-RPC provider instance.

  2. Generate a signer with the private key and provider.

  3. Specify the coin symbol, and amount.

  4. Execute the deposit transaction.

// Note: Please use starknet.js version 5.14.1.
import { Account, RpcProvider } from 'starknet'

// Replace your RPC URL based on your destination network.
const provider = new RpcProvider({ nodeUrl: rpcURL  })
const account = new Account(
  provider,
  userStarknetPublicAddress,
  userStarknetPrivateKey,
)

const depositRes = await client.starknetDepositWithStarknetSigner(
  '14', // Enter the amount you want to deposit.
  'usdc', // Enter the coin symbol.
   starknetPublicKey as string,  // Your starknet public address.
   account, // The account created above.
   provider, // The provider created above.
);

List Deposits

To retrieve the deposit history, you can utilise the following code snippet:

const depositsList = await client.listDeposits({
  network: 'ETHEREUM', // Specify the network for which you want to list the deposit history. Allowed networks include 'ETHEREUM', 'POLYGON', 'OPTIMISM', 'ARBITRUM', 'LINEA', 'SCROLL', 'STARKNET', and 'MODE'.
  page: 2, // This is an optional field
  limit: 1, // This is an optional field
})

For additional information, please refer to the SDK Reference.

Last updated