Usage

Installation, quick start, and usage examples for @tetherto/wdk-wallet-tron-gasfree

Installation

To install the wdk-wallet-tron-gasfree package, follow these instructions:

npm install @tetherto/wdk-wallet-tron-gasfree

Quick Start

Importing from wdk-wallet-tron-gasfree

  1. WalletManagerTronGasfree: This is the main class for managing wallets with gas-free capabilities.

  2. WalletAccountTronGasfree: Use this for full access accounts with gas-free features.

  3. WalletAccountReadOnlyTronGasfree: Use this for read-only accounts with gas-free features.

Creating a New Gas-Free Wallet

import WalletManagerTronGasfree, { 
  WalletAccountTronGasfree, 
  WalletAccountReadOnlyTronGasfree 
} from '@tetherto/wdk-wallet-tron-gasfree'

// Use a BIP-39 seed phrase (replace with your own secure phrase)
const seedPhrase = 'your twelve word seed phrase here' // Replace with actual seed generation


// Create wallet manager with Tron RPC provider and gas-free service provider
const wallet = new WalletManagerTronGasfree(seedPhrase, {
  // Tron network configuration
  chainId: '728126428', // Tron chain ID
  provider: 'https://api.trongrid.io', // or any other Tron RPC provider
  // Gas-free service configuration
  gasFreeProvider: 'https://gasfree.provider.url', // Gas-free provider's URL
  gasFreeApiKey: 'your-gasfree-api-key', // Gas-free provider's API key
  gasFreeApiSecret: 'your-gasfree-api-secret', // Gas-free provider's API secret
  serviceProvider: 'T...', // Service provider's address
  verifyingContract: 'T...', // Verifying contract's address
  
  // Optional configuration
  transferMaxFee: 10000000 // Maximum fee in sun (optional)
})

// Get a full access account
const account = await wallet.getAccount(0)

// Convert to a read-only account
const readOnlyAccount = await account.toReadOnlyAccount()

Managing Multiple Accounts

Checking Balances

Owned Account

For accounts where you have the seed phrase and full access:

Read-Only Account

For addresses where you don't have the seed phrase:

Sending Transactions

⚠️ Direct transaction sending using sendTransaction() is not supported in WalletAccountTronGasfree. This is a gasfree implementation that handles transactions through a gasfree provider instead of direct blockchain transactions.

For sending tokens, please use the transfer() method instead.

Token Transfers

Transfer TRC20 tokens and estimate fees using WalletAccountTronGasfree. Ensure connection to TronWeb.

Message Signing and Verification

Sign and verify messages using WalletAccountTronGasfree. Ensure connection to TronWeb.

Fee Management

Retrieve current fee rates using WalletManagerTronGasfree. Ensure connection to TronWeb.

Memory Management

Complete Examples

Complete Gas-Free Wallet Setup

Multi-Account Management

Gas-Free TRC20 Transfer Example

Token Transfer with Fee Limit


Need Help?