Skip to content

dynamic-labs/example-ton-embedded

Repository files navigation

Dynamic WaaS TON Wallet Example

A demo application showcasing Dynamic Wallet-as-a-Service (WaaS) integration with TON blockchain. This example demonstrates how to create embedded TON wallets, send transactions, transfer Jettons, and generate TON Connect proofs.

Dynamic SDK TON

Getting Started

Prerequisites

Installation

npm install

Environment Variables

Create a .env.local file in the root directory:

# Required: Your Dynamic environment ID
NEXT_PUBLIC_DYNAMIC_ENVIRONMENT_ID=your-environment-id

# Optional: Custom Dynamic API base URL
# NEXT_PUBLIC_DYNAMIC_API_BASE_URL=https://app.dynamic.xyz/api/v0

# Recommended: TON Center RPC with API key
# NEXT_PUBLIC_TON_RPC_URL=https://toncenter.com/api/v2/jsonRPC?api_key=YOUR_API_KEY

Note: Without a TON Center API key, you may encounter HTTP 429 rate limit errors. Get a free API key via the @tonapibot Telegram bot. Once obtained, configure it in:

  • Dynamic Dashboard — Add it to your TON chain configuration in the Chains & Networks settings
  • Environment variable — Set NEXT_PUBLIC_TON_RPC_URL above for balance fetching in this app

Running the App

npm run dev

Open http://localhost:3000 in your browser.

Key Implementation Details

Dynamic SDK Setup

The Dynamic SDK is configured with TON wallet connectors in providers.tsx:

import { DynamicContextProvider } from '@dynamic-labs/sdk-react-core';
import { TonWalletConnectors } from '@dynamic-labs/ton';

<DynamicContextProvider
  settings={{
    environmentId: process.env.NEXT_PUBLIC_DYNAMIC_ENVIRONMENT_ID!,
    walletConnectors: [TonWalletConnectors],
  }}
>
  {children}
</DynamicContextProvider>

Creating Embedded Wallets

import { useDynamicWaas } from '@dynamic-labs/sdk-react-core';
import { ChainEnum } from '@dynamic-labs/sdk-api-core';

const { createWalletAccount } = useDynamicWaas();

await createWalletAccount([ChainEnum.Ton]);

Sending TON

import { isTonWallet } from '@dynamic-labs/ton';

if (isTonWallet(primaryWallet)) {
  const txHash = await primaryWallet.sendBalance({
    amount: '0.1',
    toAddress: 'UQ...',
  });
}

Sending Jettons

if (isTonWallet(primaryWallet)) {
  const txHash = await primaryWallet.sendJetton({
    jettonMasterAddress: 'EQ...', // Jetton contract address
    recipientAddress: 'UQ...',
    jettonAmount: BigInt(1000000), // Amount in smallest units
    forwardTonAmount: BigInt(50000000), // 0.05 TON for gas
    forwardPayload: 'optional memo',
  });
}

Generating TON Connect Proof

if (isTonWallet(primaryWallet)) {
  const proof = await primaryWallet.generateTonConnectProof('your-challenge-payload');
  // Send proof to your backend for verification
}

Documentation

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published