Getting Started
Learn how to detect, connect, and interact with TON using OneKey’s provider.
OneKey implements the TON Connect 2.0 protocol, ensuring compatibility with all TON dApps.
Provider Detection
// Detect OneKey TON provider
const provider = window.$onekey?.tonconnect
if (!provider) {
throw new Error('OneKey TON provider not detected')
}
// Check device and wallet info
console.log('Device:', provider.deviceInfo)
console.log('Wallet:', provider.walletInfo)
console.log('Protocol Version:', provider.protocolVersion) // 2Connect Wallet
// Basic connection
const connectEvent = await provider.connect()
if (connectEvent.event === 'connect') {
const addressItem = connectEvent.payload.items.find(
item => item.name === 'ton_addr'
)
console.log('Connected:', addressItem.address)
} else {
console.error('Connection failed:', connectEvent.payload.message)
}Connect with Manifest
For production apps, provide a manifest URL:
const connectRequest = {
manifestUrl: 'https://yourapp.com/tonconnect-manifest.json',
items: [
{ name: 'ton_addr' },
{ name: 'ton_proof', payload: 'your-challenge-string' }
]
}
const connectEvent = await provider.connect(2, connectRequest)
if (connectEvent.event === 'connect') {
const addressItem = connectEvent.payload.items.find(i => i.name === 'ton_addr')
const proofItem = connectEvent.payload.items.find(i => i.name === 'ton_proof')
console.log('Address:', addressItem.address)
console.log('Proof:', proofItem?.proof)
}App Manifest Format
Create tonconnect-manifest.json in your app root:
{
"url": "https://yourapp.com",
"name": "Your App Name",
"iconUrl": "https://yourapp.com/icon.png",
"termsOfUseUrl": "https://yourapp.com/terms",
"privacyPolicyUrl": "https://yourapp.com/privacy"
}Restore Connection
Restore a previous session:
const connectEvent = await provider.restoreConnection()
if (connectEvent.event === 'connect') {
console.log('Session restored')
}Disconnect
await provider.disconnect()Event Handling
provider.listen((event) => {
console.log('Wallet event:', event)
})
// Or use specific event listeners
provider.on('accountChanged', (address) => {
if (address) {
console.log('Account changed:', address)
} else {
console.log('Disconnected')
}
})
provider.on('disconnect', () => {
console.log('Wallet disconnected')
})Using with TON Connect SDK
For React applications, use the official TON Connect SDK:
npm install @tonconnect/ui-reactimport { TonConnectUIProvider, TonConnectButton } from '@tonconnect/ui-react'
function App() {
return (
<TonConnectUIProvider manifestUrl="https://yourapp.com/tonconnect-manifest.json">
<TonConnectButton />
<YourApp />
</TonConnectUIProvider>
)
}OneKey is automatically detected by TON Connect SDK.
Last updated on