toronet 0.0.5 copy "toronet: ^0.0.5" to clipboard
toronet: ^0.0.5 copied to clipboard

Toronet is a Dart/Flutter SDK providing seamless integration with blockchain, wallet, payments, KYC, exchange, and balance APIs. It enables developers to build secure, scalable, and feature-rich fina [...]

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:toronet/toronet.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Toronet SDK Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Toronet SDK Comprehensive Demo'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  late ToronetSDK sdk;
  String _result = '';
  Wallet? _wallet;
  Network _currentNetwork = Network.testnet;
  bool _isLoading = false;

  // Test addresses and credentials
  final String testAddress = '0x03c8ef05663bd8e4ad8074d650e4ccd33310cd95';
  final String adminUser = 'admin';
  final String adminPwd = 'adminpwd';

  @override
  void initState() {
    super.initState();
    sdk = ToronetSDK(network: _currentNetwork);
  }

  void _updateResult(String message) {
    setState(() {
      _result = message;
      _isLoading = false;
    });
  }

  void _setLoading(bool loading) {
    setState(() {
      _isLoading = loading;
    });
  }

  // ====================================================================
  // Network Configuration
  // ====================================================================
  Future<void> _switchNetwork(Network network) async {
    _setLoading(true);
    try {
      setState(() {
        _currentNetwork = network;
        sdk = ToronetSDK(network: network);
      });
      _updateResult('Switched to ${network.name} network');
    } catch (e) {
      _updateResult('Error switching network: $e');
    }
  }

  // ====================================================================
  // Wallet Operations
  // ====================================================================
  Future<void> _createWallet() async {
    _setLoading(true);
    try {
      final wallet = await sdk.walletService.createWallet(
        username: 'testuser_${DateTime.now().millisecondsSinceEpoch}',
        password: 'testpassword123',
      );
      setState(() => _wallet = wallet);
      _updateResult(
        'Wallet created!\nAddress: ${wallet.address}\nTNS: ${wallet.tnsName}',
      );
    } catch (e) {
      _updateResult('Error creating wallet: $e');
    }
  }

  Future<void> _importWallet() async {
    _setLoading(true);
    _updateResult(
      'Import wallet requires a private key.\nUse: sdk.walletService.importWalletFromPrivateKey(...)',
    );
  }

  Future<void> _verifyPassword() async {
    if (_wallet == null) {
      _updateResult('Please create a wallet first');
      return;
    }
    _setLoading(true);
    try {
      final isValid = await sdk.walletService.verifyWalletPassword(
        address: _wallet!.address,
        password: 'testpassword123',
      );
      _updateResult('Password verification: ${isValid ? "Valid" : "Invalid"}');
    } catch (e) {
      _updateResult('Error verifying password: $e');
    }
  }

  Future<void> _updatePassword() async {
    if (_wallet == null) {
      _updateResult('Please create a wallet first');
      return;
    }
    _setLoading(true);
    try {
      await sdk.walletService.updateWalletPassword(
        address: _wallet!.address,
        oldPassword: 'testpassword123',
        newPassword: 'newpassword456',
      );
      _updateResult('Password updated successfully');
    } catch (e) {
      _updateResult('Error updating password: $e');
    }
  }

  Future<void> _checkTNSAvailability() async {
    _setLoading(true);
    try {
      final available = await sdk.walletService.isTNSAvailable(
        username: 'testusername',
      );
      _updateResult(
        'TNS "testusername" is ${available ? "available" : "not available"}',
      );
    } catch (e) {
      _updateResult('Error checking TNS: $e');
    }
  }

  // ====================================================================
  // Query Operations
  // ====================================================================
  Future<void> _getExchangeRates() async {
    _setLoading(true);
    try {
      final rates = await sdk.queryService.getExchangeRates();
      _updateResult(
        'Exchange Rates:\n${rates.toString().substring(0, 200)}...',
      );
    } catch (e) {
      _updateResult('Error getting exchange rates: $e');
    }
  }

  Future<void> _getAddressRole() async {
    _setLoading(true);
    try {
      final role = await sdk.queryService.getAddrRole(addr: testAddress);
      _updateResult('Address Role:\n$role');
    } catch (e) {
      _updateResult('Error getting address role: $e');
    }
  }

  Future<void> _getAddressBalance() async {
    _setLoading(true);
    try {
      final balance = await sdk.queryService.getAddrBalance(addr: testAddress);
      _updateResult('Address Balance:\n$balance');
    } catch (e) {
      _updateResult('Error getting address balance: $e');
    }
  }

  Future<void> _getLatestBlocks() async {
    _setLoading(true);
    try {
      final blocks = await sdk.queryService.getBlocks(count: 5);
      _updateResult('Latest Blocks: ${blocks.length} blocks retrieved');
    } catch (e) {
      _updateResult('Error getting blocks: $e');
    }
  }

  Future<void> _getLatestTransactions() async {
    _setLoading(true);
    try {
      final transactions = await sdk.queryService.getTransactions(count: 5);
      _updateResult(
        'Latest Transactions: ${transactions.length} transactions retrieved',
      );
    } catch (e) {
      _updateResult('Error getting transactions: $e');
    }
  }

  Future<void> _getCurrencyTransactions() async {
    _setLoading(true);
    try {
      final nairaTxns = await sdk.queryService.getTransactionsNaira(count: 3);
      final euroTxns = await sdk.queryService.getTransactionsEuro(count: 3);
      final ethTxns = await sdk.queryService.getTransactionsEth(count: 3);
      _updateResult(
        'Currency Transactions:\nNGN: ${nairaTxns.length}\nEUR: ${euroTxns.length}\nETH: ${ethTxns.length}',
      );
    } catch (e) {
      _updateResult('Error getting currency transactions: $e');
    }
  }

  // ====================================================================
  // Currency Operations
  // ====================================================================
  Future<void> _getCurrencyBalance() async {
    _setLoading(true);
    try {
      final dollarBalance = await sdk.currencyService.getCurrencyBalance(
        currency: Currency.dollar,
        address: testAddress,
      );
      final ngnBalance = await sdk.currencyService.getCurrencyBalance(
        currency: Currency.naira,
        address: testAddress,
      );
      _updateResult(
        'Currency Balances:\nUSD: $dollarBalance\nNGN: $ngnBalance',
      );
    } catch (e) {
      _updateResult('Error getting currency balance: $e');
    }
  }

  Future<void> _getCurrencyInfo() async {
    _setLoading(true);
    try {
      final dollarName = await sdk.currencyService.getCurrencyName(
        currency: Currency.dollar,
      );
      final dollarSymbol = await sdk.currencyService.getCurrencySymbol(
        currency: Currency.dollar,
      );
      final fee = await sdk.currencyService.getTransactionFee(
        currency: Currency.dollar,
        amount: '100',
      );
      _updateResult(
        'USD Currency Info:\nName: $dollarName\nSymbol: $dollarSymbol\nFee: $fee',
      );
    } catch (e) {
      _updateResult('Error getting currency info: $e');
    }
  }

  // ====================================================================
  // TNS Operations
  // ====================================================================
  Future<void> _checkTNSStatus() async {
    _setLoading(true);
    try {
      final isSetOn = await sdk.tnsService.isSetOn();
      final isUpdateOn = await sdk.tnsService.isUpdateOn();
      final isDeleteOn = await sdk.tnsService.isDeleteOn();
      _updateResult(
        'TNS Status:\nSet On: $isSetOn\nUpdate On: $isUpdateOn\nDelete On: $isDeleteOn',
      );
    } catch (e) {
      _updateResult('Error checking TNS status: $e');
    }
  }

  Future<void> _getTNSName() async {
    _setLoading(true);
    try {
      final name = await sdk.tnsService.getName(address: testAddress);
      _updateResult('TNS Name for $testAddress:\n$name');
    } catch (e) {
      _updateResult('TNS name not found (expected if not enrolled)');
    }
  }

  // ====================================================================
  // Token Operations
  // ====================================================================
  Future<void> _getTokenInfo() async {
    _setLoading(true);
    try {
      final tokenName = await sdk.tokenService.getTokenName(tokenType: 'toro');
      final tokenSymbol = await sdk.tokenService.getTokenSymbol(
        tokenType: 'toro',
      );
      final decimals = await sdk.tokenService.getTokenDecimal(
        tokenType: 'toro',
      );
      final totalCap = await sdk.tokenService.getTotalCap(tokenType: 'toro');
      _updateResult(
        'TORO Token Info:\nName: $tokenName\nSymbol: $tokenSymbol\nDecimals: $decimals\nTotal Cap: $totalCap',
      );
    } catch (e) {
      _updateResult('Error getting token info: $e');
    }
  }

  Future<void> _getTokenBalance() async {
    _setLoading(true);
    try {
      final balance = await sdk.tokenService.getTokenBalance(
        tokenType: 'toro',
        address: testAddress,
      );
      _updateResult('TORO Token Balance:\n$balance');
    } catch (e) {
      _updateResult('Error getting token balance: $e');
    }
  }

  Future<void> _getTokenFees() async {
    _setLoading(true);
    try {
      final feeFixed = await sdk.tokenService.getTransactionFeeFixed(
        tokenType: 'toro',
      );
      final feePercentage = await sdk.tokenService.getTransactionFeePercentage(
        tokenType: 'toro',
      );
      _updateResult(
        'TORO Token Fees:\nFixed: $feeFixed\nPercentage: $feePercentage',
      );
    } catch (e) {
      _updateResult('Error getting token fees: $e');
    }
  }

  // ====================================================================
  // Role Management
  // ====================================================================
  Future<void> _checkRoles() async {
    _setLoading(true);
    try {
      final isAdmin = await sdk.rolesService.isRole(
        roleType: RoleType.admin,
        address: testAddress,
      );
      final isSuperAdmin = await sdk.rolesService.isRole(
        roleType: RoleType.superadmin,
        address: testAddress,
      );
      final adminCount = await sdk.rolesService.getNumberOfRole(
        roleType: RoleType.admin,
      );
      _updateResult(
        'Role Status:\nIs Admin: $isAdmin\nIs SuperAdmin: $isSuperAdmin\nAdmin Count: $adminCount',
      );
    } catch (e) {
      _updateResult('Error checking roles: $e');
    }
  }

  // ====================================================================
  // Payment Operations
  // ====================================================================
  Future<void> _getBankLists() async {
    _setLoading(true);
    try {
      final usdBanks = await sdk.paymentsService.getBankListUSD();
      final ngnBanks = await sdk.paymentsService.getBankListNGN();
      _updateResult(
        'Bank Lists:\nUSD Banks: ${usdBanks.length}\nNGN Banks: ${ngnBanks.length}',
      );
    } catch (e) {
      _updateResult('Error getting bank lists: $e');
    }
  }

  Future<void> _getPendingTransactions() async {
    _setLoading(true);
    try {
      final pending = await sdk.paymentsService.getPendingTransaction(
        admin: adminUser,
        adminpwd: adminPwd,
      );
      _updateResult('Pending Transactions: ${pending.length}');
    } catch (e) {
      _updateResult('Error getting pending transactions: $e');
    }
  }

  // ====================================================================
  // Product Operations
  // ====================================================================
  Future<void> _getProjectInfo() async {
    _setLoading(true);
    try {
      final projectInfo = await sdk.productsService.getProjectInfo();
      _updateResult('Project Info:\n${projectInfo.keys.join(", ")}');
    } catch (e) {
      _updateResult('Error getting project info: $e');
    }
  }

  // ====================================================================
  // Blockchain Operations
  // ====================================================================
  Future<void> _getBlockchainStatus() async {
    _setLoading(true);
    try {
      final status = await sdk.blockchainService.getBlockchainStatus();
      _updateResult(
        'Blockchain Status:\n${status.toString().substring(0, 200)}...',
      );
    } catch (e) {
      _updateResult('Error getting blockchain status: $e');
    }
  }

  Future<void> _getLatestBlock() async {
    _setLoading(true);
    try {
      final block = await sdk.blockchainService.getLatestBlockData();
      _updateResult('Latest Block:\n${block.toString().substring(0, 200)}...');
    } catch (e) {
      _updateResult('Error getting latest block: $e');
    }
  }

  // ====================================================================
  // Exchange Operations
  // ====================================================================
  Future<void> _getExchangeRatesFromService() async {
    _setLoading(true);
    try {
      final rates = await sdk.exchangeService.getSupportedAssetsExchangeRates();
      _updateResult(
        'Exchange Rates:\n${rates.toString().substring(0, 200)}...',
      );
    } catch (e) {
      _updateResult('Error getting exchange rates: $e');
    }
  }

  // ====================================================================
  // Balance Operations
  // ====================================================================
  Future<void> _getBalance() async {
    _setLoading(true);
    try {
      final balance = await sdk.balanceService.getBalance(address: testAddress);
      _updateResult('Balance for $testAddress:\n$balance');
    } catch (e) {
      _updateResult('Error getting balance: $e');
    }
  }

  // ====================================================================
  // Multi-Chain Bridge Operations
  // ====================================================================

  // Solana Operations
  Future<void> _getSolBalance() async {
    _setLoading(true);
    try {
      final balance = await sdk.solanaService.getSolBalance(
        address: testAddress,
        admin: adminUser,
        adminpwd: adminPwd,
      );
      _updateResult('SOL Balance: $balance');
    } catch (e) {
      _updateResult('Error getting SOL balance: $e');
    }
  }

  Future<void> _bridgeTokenSolana() async {
    _setLoading(true);
    try {
      final result = await sdk.solanaService.bridgeToken(
        from: _wallet?.address ?? testAddress,
        password: 'password',
        contractAddress: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
        tokenName: 'USDC',
        amount: '3',
        admin: adminUser,
        adminpwd: adminPwd,
      );
      _updateResult('Bridge result: $result');
    } catch (e) {
      _updateResult('Error bridging token: $e');
    }
  }

  // Polygon Operations
  Future<void> _getPolygonBalance() async {
    _setLoading(true);
    try {
      final balance = await sdk.polygonService.getBalance(
        address: testAddress,
        admin: adminUser,
        adminpwd: adminPwd,
      );
      _updateResult('Polygon Balance: $balance');
    } catch (e) {
      _updateResult('Error getting Polygon balance: $e');
    }
  }

  Future<void> _bridgeTokenPolygon() async {
    _setLoading(true);
    try {
      final result = await sdk.polygonService.bridgeToken(
        from: _wallet?.address ?? testAddress,
        password: 'password',
        contractAddress: '0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359',
        tokenName: 'USDC',
        amount: '2',
        admin: adminUser,
        adminpwd: adminPwd,
      );
      _updateResult('Bridge result: $result');
    } catch (e) {
      _updateResult('Error bridging token: $e');
    }
  }

  // BSC Operations
  Future<void> _getBscBalance() async {
    _setLoading(true);
    try {
      final balance = await sdk.bscService.getBalance(
        address: testAddress,
        admin: adminUser,
        adminpwd: adminPwd,
      );
      _updateResult('BSC Balance: $balance');
    } catch (e) {
      _updateResult('Error getting BSC balance: $e');
    }
  }

  Future<void> _bridgeTokenBsc() async {
    _setLoading(true);
    try {
      final result = await sdk.bscService.bridgeToken(
        from: _wallet?.address ?? testAddress,
        password: 'password',
        contractAddress: '0x55d398326f99059ff775485246999027b3197955',
        tokenName: 'USDT',
        amount: '2',
        admin: adminUser,
        adminpwd: adminPwd,
      );
      _updateResult('Bridge result: $result');
    } catch (e) {
      _updateResult('Error bridging token: $e');
    }
  }

  // Base Operations
  Future<void> _getBaseBalance() async {
    _setLoading(true);
    try {
      final balance = await sdk.baseService.getBalance(
        address: testAddress,
        admin: adminUser,
        adminpwd: adminPwd,
      );
      _updateResult('Base Balance: $balance');
    } catch (e) {
      _updateResult('Error getting Base balance: $e');
    }
  }

  Future<void> _bridgeTokenBase() async {
    _setLoading(true);
    try {
      final result = await sdk.baseService.bridgeToken(
        from: _wallet?.address ?? testAddress,
        password: 'password',
        contractAddress: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
        tokenName: 'USDC',
        amount: '2',
        admin: adminUser,
        adminpwd: adminPwd,
      );
      _updateResult('Bridge result: $result');
    } catch (e) {
      _updateResult('Error bridging token: $e');
    }
  }

  // Arbitrum Operations
  Future<void> _getArbitrumBalance() async {
    _setLoading(true);
    try {
      final balance = await sdk.arbitrumService.getBalance(
        address: testAddress,
        admin: adminUser,
        adminpwd: adminPwd,
      );
      _updateResult('Arbitrum Balance: $balance');
    } catch (e) {
      _updateResult('Error getting Arbitrum balance: $e');
    }
  }

  Future<void> _bridgeTokenArbitrum() async {
    _setLoading(true);
    try {
      final result = await sdk.arbitrumService.bridgeToken(
        from: _wallet?.address ?? testAddress,
        password: 'password',
        contractAddress: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
        tokenName: 'USDC',
        amount: '2',
        admin: adminUser,
        adminpwd: adminPwd,
      );
      _updateResult('Bridge result: $result');
    } catch (e) {
      _updateResult('Error bridging token: $e');
    }
  }

  // ====================================================================
  // Util Operations
  // ====================================================================
  Future<void> _isAddress() async {
    _setLoading(true);
    try {
      final result = await sdk.utilService.isAddress(address: testAddress);
      _updateResult('isAddress result: $result');
    } catch (e) {
      _updateResult('Error checking address: $e');
    }
  }

  Future<void> _getTransactionCount() async {
    _setLoading(true);
    try {
      final result = await sdk.utilService.getTransactionCount(
        address: testAddress,
      );
      _updateResult('Transaction count: $result');
    } catch (e) {
      _updateResult('Error getting transaction count: $e');
    }
  }

  // ====================================================================
  // Auth Operations
  // ====================================================================
  Future<void> _getAuthStatus() async {
    _setLoading(true);
    try {
      final result = await sdk.authService.getAuthStatus(address: testAddress);
      _updateResult('Auth status: $result');
    } catch (e) {
      _updateResult('Error getting auth status: $e');
    }
  }

  // ====================================================================
  // ETH Operations
  // ====================================================================
  Future<void> _getEthBalance() async {
    _setLoading(true);
    try {
      final balance = await sdk.ethService.getBalance(
        address: testAddress,
        admin: adminUser,
        adminpwd: adminPwd,
      );
      _updateResult('ETH Balance: $balance');
    } catch (e) {
      _updateResult('Error getting ETH balance: $e');
    }
  }

  Future<void> _updateEthProjectReserve() async {
    _setLoading(true);
    try {
      final result = await sdk.ethService.updateProjectReserve(
        ethAddress: testAddress,
        admin: adminUser,
        adminpwd: adminPwd,
      );
      _updateResult('ETH project reserve updated: $result');
    } catch (e) {
      _updateResult('Error updating ETH project reserve: $e');
    }
  }

  // ====================================================================
  // AVAX Reserve Operations
  // ====================================================================
  Future<void> _updateAvaxProjectReserve() async {
    _setLoading(true);
    try {
      final result = await sdk.avaxService.updateProjectReserve(
        avaxAddress: testAddress,
        admin: adminUser,
        adminpwd: adminPwd,
      );
      _updateResult('AVAX project reserve updated: $result');
    } catch (e) {
      _updateResult('Error updating AVAX project reserve: $e');
    }
  }

  // ====================================================================
  // Tron Operations
  // ====================================================================
  Future<void> _getTronBalance() async {
    _setLoading(true);
    try {
      final balance = await sdk.tronService.getBalance(
        address: 'TBjkrvhLoh6v7KBuziZs5fL4NqpbCzgXdf',
        admin: adminUser,
        adminpwd: adminPwd,
      );
      _updateResult('TRX Balance: $balance');
    } catch (e) {
      _updateResult('Error getting TRX balance: $e');
    }
  }

  Future<void> _isValidTronAddress() async {
    _setLoading(true);
    try {
      final result = await sdk.tronService.isValidTronAddress(
        address: 'TBjkrvhLoh6v7KBuziZs5fL4NqpbCzgXdf',
        admin: adminUser,
        adminpwd: adminPwd,
      );
      _updateResult('Valid Tron address: $result');
    } catch (e) {
      _updateResult('Error validating Tron address: $e');
    }
  }

  // ====================================================================
  // Smart Contract Operations
  // ====================================================================
  Future<void> _signMessage() async {
    _setLoading(true);
    try {
      final result = await sdk.contractService.signMessage(
        address: testAddress,
        password: adminPwd,
        message: 'Hello Toronet',
      );
      _updateResult('Signed message: $result');
    } catch (e) {
      _updateResult('Error signing message: $e');
    }
  }

  Future<void> _callContractFunction() async {
    _setLoading(true);
    try {
      final result = await sdk.contractService.callContractFunction(
        address: testAddress,
        password: adminPwd,
        contractAddress: '0x0000000000000000000000000000000000000000',
        functionName: 'balanceOf',
        functionArguments: [testAddress],
        abi: [
          {
            'name': 'balanceOf',
            'type': 'function',
            'inputs': [
              {'name': 'owner', 'type': 'address'},
            ],
            'outputs': [
              {'name': '', 'type': 'uint256'},
            ],
          },
        ],
      );
      _updateResult('Contract function result: $result');
    } catch (e) {
      _updateResult('Error calling contract function: $e');
    }
  }

  // ====================================================================
  // Contract Deployment
  // ====================================================================
  Future<void> _deployContractTestnet() async {
    _setLoading(true);
    try {
      final result = await sdk.deployerService.deployContract(
        owner: testAddress,
        abi: [
          {
            'inputs': <Map<String, dynamic>>[],
            'name': 'getValue',
            'outputs': [
              {'name': '', 'type': 'uint256'},
            ],
            'type': 'function',
          },
        ],
        bytecode: '0x608060405234801561001057600080fd5b50600080fd',
        constructorArgs: [],
      );
      _updateResult('Contract deployed (testnet): $result');
    } catch (e) {
      _updateResult('Error deploying contract: $e');
    }
  }

  // ====================================================================
  // Error Handling Demo
  // ====================================================================
  Future<void> _demoErrorHandling() async {
    _setLoading(true);
    try {
      // This should trigger a validation error
      await sdk.walletService.createWallet(username: '', password: '');
    } on ValidationException catch (e) {
      _updateResult('✓ ValidationException caught:\n${e.message}');
    } on APIException catch (e) {
      _updateResult('✓ APIException caught:\n${e.message}');
    } on ToroSDKException catch (e) {
      _updateResult('✓ ToroSDKException caught:\n${e.message}');
    } catch (e) {
      _updateResult('Unexpected error: $e');
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
        actions: [
          PopupMenuButton<Network>(
            icon: const Icon(Icons.settings),
            onSelected: _switchNetwork,
            itemBuilder:
                (context) => [
                  const PopupMenuItem(
                    value: Network.mainnet,
                    child: Text('Mainnet'),
                  ),
                  const PopupMenuItem(
                    value: Network.testnet,
                    child: Text('Testnet'),
                  ),
                ],
            child: Padding(
              padding: const EdgeInsets.all(8.0),
              child: Text('Network: ${_currentNetwork.name}'),
            ),
          ),
        ],
      ),
      body:
          _isLoading
              ? const Center(child: CircularProgressIndicator())
              : SingleChildScrollView(
                child: Padding(
                  padding: const EdgeInsets.all(16.0),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.stretch,
                    children: [
                      // Network Status
                      Card(
                        child: Padding(
                          padding: const EdgeInsets.all(8.0),
                          child: Text(
                            'Current Network: ${_currentNetwork.name.toUpperCase()}',
                            style: Theme.of(context).textTheme.titleMedium,
                            textAlign: TextAlign.center,
                          ),
                        ),
                      ),
                      const SizedBox(height: 16),

                      // Wallet Operations Section
                      _buildSection(context, 'Wallet Operations', [
                        _buildButton('Create Wallet', _createWallet),
                        _buildButton('Import Wallet', _importWallet),
                        _buildButton('Verify Password', _verifyPassword),
                        _buildButton('Update Password', _updatePassword),
                        _buildButton(
                          'Check TNS Availability',
                          _checkTNSAvailability,
                        ),
                      ]),

                      // Query Operations Section
                      _buildSection(context, 'Query Operations', [
                        _buildButton('Get Exchange Rates', _getExchangeRates),
                        _buildButton('Get Address Role', _getAddressRole),
                        _buildButton('Get Address Balance', _getAddressBalance),
                        _buildButton('Get Latest Blocks', _getLatestBlocks),
                        _buildButton(
                          'Get Latest Transactions',
                          _getLatestTransactions,
                        ),
                        _buildButton(
                          'Get Currency Transactions',
                          _getCurrencyTransactions,
                        ),
                      ]),

                      // Currency Operations Section
                      _buildSection(context, 'Currency Operations', [
                        _buildButton(
                          'Get Currency Balance',
                          _getCurrencyBalance,
                        ),
                        _buildButton('Get Currency Info', _getCurrencyInfo),
                      ]),

                      // TNS Operations Section
                      _buildSection(context, 'TNS Operations', [
                        _buildButton('Check TNS Status', _checkTNSStatus),
                        _buildButton('Get TNS Name', _getTNSName),
                      ]),

                      // Token Operations Section
                      _buildSection(context, 'Token Operations', [
                        _buildButton('Get Token Info', _getTokenInfo),
                        _buildButton('Get Token Balance', _getTokenBalance),
                        _buildButton('Get Token Fees', _getTokenFees),
                      ]),

                      // Role Management Section
                      _buildSection(context, 'Role Management', [
                        _buildButton('Check Roles', _checkRoles),
                      ]),

                      // Payment Operations Section
                      _buildSection(context, 'Payment Operations', [
                        _buildButton('Get Bank Lists', _getBankLists),
                        _buildButton(
                          'Get Pending Transactions',
                          _getPendingTransactions,
                        ),
                      ]),

                      // Product Operations Section
                      _buildSection(context, 'Product Operations', [
                        _buildButton('Get Project Info', _getProjectInfo),
                      ]),

                      // Blockchain Operations Section
                      _buildSection(context, 'Blockchain Operations', [
                        _buildButton(
                          'Get Blockchain Status',
                          _getBlockchainStatus,
                        ),
                        _buildButton('Get Latest Block', _getLatestBlock),
                      ]),

                      // Exchange Operations Section
                      _buildSection(context, 'Exchange Operations', [
                        _buildButton(
                          'Get Exchange Rates',
                          _getExchangeRatesFromService,
                        ),
                      ]),

                      // Balance Operations Section
                      _buildSection(context, 'Balance Operations', [
                        _buildButton('Get Balance', _getBalance),
                      ]),

                      // Solana Operations Section
                      _buildSection(context, 'Solana Operations', [
                        _buildButton('Get SOL Balance', _getSolBalance),
                        _buildButton(
                          'Bridge Token (Solana)',
                          _bridgeTokenSolana,
                        ),
                      ]),

                      // Polygon Operations Section
                      _buildSection(context, 'Polygon Operations', [
                        _buildButton('Get Polygon Balance', _getPolygonBalance),
                        _buildButton(
                          'Bridge Token (Polygon)',
                          _bridgeTokenPolygon,
                        ),
                      ]),

                      // BSC Operations Section
                      _buildSection(context, 'BSC Operations', [
                        _buildButton('Get BSC Balance', _getBscBalance),
                        _buildButton('Bridge Token (BSC)', _bridgeTokenBsc),
                      ]),

                      // Base Operations Section
                      _buildSection(context, 'Base Operations', [
                        _buildButton('Get Base Balance', _getBaseBalance),
                        _buildButton('Bridge Token (Base)', _bridgeTokenBase),
                      ]),

                      // Arbitrum Operations Section
                      _buildSection(context, 'Arbitrum Operations', [
                        _buildButton(
                          'Get Arbitrum Balance',
                          _getArbitrumBalance,
                        ),
                        _buildButton(
                          'Bridge Token (Arbitrum)',
                          _bridgeTokenArbitrum,
                        ),
                      ]),

                      // Util Operations Section
                      _buildSection(context, 'Util Operations', [
                        _buildButton('Is Valid Address', _isAddress),
                        _buildButton(
                          'Get Transaction Count',
                          _getTransactionCount,
                        ),
                      ]),

                      // Auth Operations Section
                      _buildSection(context, 'Auth Operations', [
                        _buildButton('Get Auth Status', _getAuthStatus),
                      ]),

                      // ETH Operations Section
                      _buildSection(context, 'ETH Operations', [
                        _buildButton('Get ETH Balance', _getEthBalance),
                        _buildButton(
                          'Update ETH Project Reserve',
                          _updateEthProjectReserve,
                        ),
                      ]),

                      // AVAX Reserve Operations Section
                      _buildSection(context, 'AVAX Reserve Operations', [
                        _buildButton(
                          'Update AVAX Project Reserve',
                          _updateAvaxProjectReserve,
                        ),
                      ]),

                      // Tron Operations Section
                      _buildSection(context, 'Tron (TRX) Operations', [
                        _buildButton('Get TRX Balance', _getTronBalance),
                        _buildButton(
                          'Validate Tron Address',
                          _isValidTronAddress,
                        ),
                      ]),

                      // Smart Contract Operations Section
                      _buildSection(context, 'Smart Contract Operations', [
                        _buildButton('Sign Message', _signMessage),
                        _buildButton(
                          'Call Contract Function',
                          _callContractFunction,
                        ),
                      ]),

                      // Contract Deployment Section
                      _buildSection(context, 'Contract Deployment', [
                        _buildButton(
                          'Deploy Contract (Testnet)',
                          _deployContractTestnet,
                        ),
                      ]),

                      // Error Handling Section
                      _buildSection(context, 'Error Handling Demo', [
                        _buildButton('Demo Error Handling', _demoErrorHandling),
                      ]),

                      // Result Display
                      const SizedBox(height: 24),
                      Card(
                        color: Colors.grey[100],
                        child: Padding(
                          padding: const EdgeInsets.all(16.0),
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              Text(
                                'Result:',
                                style: Theme.of(context).textTheme.titleMedium,
                              ),
                              const SizedBox(height: 8),
                              Text(
                                _result.isEmpty
                                    ? 'No operation performed yet'
                                    : _result,
                                style: const TextStyle(fontSize: 12),
                              ),
                            ],
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
              ),
    );
  }

  Widget _buildSection(
    BuildContext context,
    String title,
    List<Widget> buttons,
  ) {
    return Card(
      margin: const EdgeInsets.only(bottom: 16),
      child: Padding(
        padding: const EdgeInsets.all(8.0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: [
            Padding(
              padding: const EdgeInsets.all(8.0),
              child: Text(title, style: Theme.of(context).textTheme.titleLarge),
            ),
            ...buttons,
          ],
        ),
      ),
    );
  }

  Widget _buildButton(String label, VoidCallback onPressed) {
    return Padding(
      padding: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 4.0),
      child: ElevatedButton(onPressed: onPressed, child: Text(label)),
    );
  }
}
3
likes
150
points
22
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Toronet is a Dart/Flutter SDK providing seamless integration with blockchain, wallet, payments, KYC, exchange, and balance APIs. It enables developers to build secure, scalable, and feature-rich financial applications with ease.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

dio, equatable, flutter

More

Packages that depend on toronet