Skip to Content
dApps

Transaktionen

Verbinden Sie die Wallet, bevor Sie Anfragen senden. Ersetzen Sie Beispieladressen und Manifest-URLs durch gültige Werte. Verwenden Sie zur Authentifizierung eine vom Server erzeugte, einmalig verwendbare Challenge und prüfen Sie den Nachweis auf Ihrem Server.

Erfahren Sie, wie Sie Transaktionen auf TON senden.


Transaktion senden

TON senden mit der send-Methode und sendTransaction:

const result = await provider.send({ method: 'sendTransaction', id: Date.now().toString(), params: [ JSON.stringify({ valid_until: Math.floor(Date.now() / 1000) + 600, // 10 min validity messages: [ { address: '0:1234...', // Recipient address (raw format) amount: '1000000000', // Amount in nanotons (1 TON = 10^9 nanotons) } ] }) ] }) if ('result' in result) { console.log('Transaction BOC:', result.result) } else { console.error('Transaction failed:', result.error.message) }

Mehrere Nachrichten senden

Der Provider gibt derzeit maximal vier Nachrichten als unterstützt an. Lesen Sie deviceInfo.features für das von der Wallet angegebene Limit, statt es als netzwerkweites Limit zu behandeln:

const result = await provider.send({ method: 'sendTransaction', id: Date.now().toString(), params: [ JSON.stringify({ valid_until: Math.floor(Date.now() / 1000) + 600, messages: [ { address: '0:recipient1...', amount: '500000000', // 0.5 TON }, { address: '0:recipient2...', amount: '300000000', // 0.3 TON } ] }) ] })

Mit Nutzlast senden

Eine Nutzlast für Smart-Contract-Interaktionen einschließen:

import { beginCell } from '@ton/core' // Create a comment cell const comment = beginCell() .storeUint(0, 32) // comment op code .storeStringTail('Hello from dApp!') .endCell() const result = await provider.send({ method: 'sendTransaction', id: Date.now().toString(), params: [ JSON.stringify({ valid_until: Math.floor(Date.now() / 1000) + 600, messages: [ { address: '0:recipient...', amount: '100000000', payload: comment.toBoc().toString('base64'), } ] }) ] })

Mit StateInit senden

Einen Vertrag bereitstellen oder Zustand initialisieren:

const result = await provider.send({ method: 'sendTransaction', id: Date.now().toString(), params: [ JSON.stringify({ valid_until: Math.floor(Date.now() / 1000) + 600, messages: [ { address: '0:contract...', amount: '50000000', stateInit: stateInitBoc.toString('base64'), // Base64 encoded StateInit } ] }) ] })

Transaktion mit dem SDK senden

import { useTonConnectUI } from '@tonconnect/ui-react' function SendButton() { const [tonConnectUI] = useTonConnectUI() const handleSend = async () => { const result = await tonConnectUI.sendTransaction({ validUntil: Math.floor(Date.now() / 1000) + 600, messages: [ { address: 'EQA...', amount: '1000000000', } ] }) console.log('BOC:', result.boc) } return <button onClick={handleSend}>Send 1 TON</button> }

Adressformate

TON verwendet unterschiedliche Adressformate:

import { Address } from '@ton/core' // Raw format (used in provider) const raw = '0:1234567890abcdef...' // User-friendly format (bounceable) const friendly = Address.parse(raw).toString() // e.g., 'EQASdf...' // Non-bounceable format const nonBounceable = Address.parse(raw).toString({ bounceable: false }) // e.g., 'UQASdf...' // Convert from friendly to raw const addr = Address.parse('EQASdf...') const rawAddress = `${addr.workChain}:${addr.hash.toString('hex')}`
Zuletzt aktualisiert am