Tutorials and Examples
Basic Wallet Operations
Create a Wallet
This tutorial demonstrates how to create a new wallet using the
TMAWalletClient.
import { TMAWalletClient } from '@tmawallet/sdk'; (async () => { const tmaWallet = new TMAWalletClient('your_project_public_token'); await tmaWallet.init(); if (!tmaWallet.isBundleExists) { await tmaWallet.createBundle(); } console.log('Wallet address:', tmaWallet.walletAddress); })();Restore a Wallet
This tutorial shows how to restore a wallet by retrieving an existing bundle from Telegram's cloud storage.
import { TMAWalletClient } from '@tmawallet/sdk'; (async () => { const tmaWallet = new TMAWalletClient('your_project_public_token'); await tmaWallet.init(); if (tmaWallet.isBundleExists) { console.log('Restored wallet address:', tmaWallet.walletAddress); } else { console.log('No existing wallet found.'); } })();Make a Transaction
Example of using TMAWallet to sign a transaction on the Ethereum blockchain.
import { TMAWalletClient } from '@tmawallet/sdk'; import { ethers } from 'ethers'; (async () => { const tmaWallet = new TMAWalletClient('your_project_public_token'); await tmaWallet.init(); if (tmaWallet.isBundleExists) { const wallet = new ethers.Wallet(tmaWallet.privateKey); const provider = ethers.getDefaultProvider('ropsten'); const signer = wallet.connect(provider); const tx = { to: 'recipient_address', value: ethers.utils.parseEther('0.01'), gasLimit: 21000, }; const transactionResponse = await signer.sendTransaction(tx); console.log('Transaction Hash:', transactionResponse.hash); } else { console.log('No wallet found to make a transaction.'); } })();
Telegram Cloud Integration
Using TelegramCloudStorage: Learn how to store and retrieve data using
TelegramCloudStoragefor wallet management.
Advanced Usage
Managing Bundles: A detailed guide on using
ClientBundleControllerandWalletBundleControllerto create, retrieve, and clear bundles.Handling User Sessions: Best practices for managing sessions and key security across different user devices.
Session Persistence: Use Telegram's cloud storage to persist session data, ensuring that users can access their wallets across devices.
Key Security: Avoid storing sensitive keys locally. Instead, leverage MPC and TelegramCloudStorage to manage keys securely.
Session Expiry: Implement session expiry mechanisms to ensure that inactive sessions are securely terminated, reducing the risk of unauthorized access.
Last updated