TON Connect for Vue
Recommended SDK for Vue Apps is a UI Vue SDK. It is a Vue component that provides a high-level way to interact with TON Connect.
Implementation
Installation
To start integrating TON Connect into your DApp, you need to install the @townsquarelabs/ui-vue
package. You can use npm or yarn for this purpose:
- npm
- Yarn
- pnpm
npm i @townsquarelabs/ui-vue
yarn add @townsquarelabs/ui-vue
pnpm add @townsquarelabs/ui-vue
TON Connect Initiation
Add TonConnectUIProvider to the root of the app. You can specify UI options using props.
All TonConnect UI hooks calls and <TonConnectButton />
component must be placed inside <TonConnectUIProvider>
.
<template>
<TonConnectUIProvider :options="options">
<!-- Your app -->
</TonConnectUIProvider>
</template>
<script>
import { TonConnectUIProvider } from '@townsquarelabs/ui-vue';
export default {
components: {
TonConnectUIProvider
},
setup(){
const options = {
manifestUrl:"https://<YOUR_APP_URL>/tonconnect-manifest.json",
};
return {
options
}
}
}
</script>
Connect to the Wallet
TonConnect Button is universal UI component for initializing connection. After wallet is connected it transforms to a wallet menu. It is recommended to place it in the top right corner of your app.
<template>
<header>
<span>My App with Vue UI</span>
<TonConnectButton/>
</header>
</template>
<script>
import { TonConnectButton } from '@townsquarelabs/ui-vue';
export default {
components: {
TonConnectButton
}
}
</script>
You can add class
and :style
props to the button as well. Note that you cannot pass child to the TonConnectButton.
<TonConnectButton class="my-button-class" :style="{ float: 'right' }"/>
Redirects
If you want to redirect the user to a specific page after wallet connection, you can use useTonConnectUI
hook and customize your return strategy.
Telegram Mini Apps
If you want to redirect the user to a Telegram Mini App after wallet connection, you can customize the TonConnectUIProvider
element:
<template>
<TonConnectUIProvider :options="options">
<!-- Your app -->
</TonConnectUIProvider>
</template>
<script>
import { TonConnectUIProvider } from '@townsquarelabs/ui-vue';
export default {
components: {
TonConnectUIProvider,
},
setup() {
const options = {
actionsConfiguration: { twaReturnUrl: 'https://t.me/<YOUR_APP_NAME>' },
};
return {
options,
};
},
};
</script>