Successfully implemented comprehensive smart contract parameter decoding with human-readable display in the MongoTron event monitoring system. The system now displays full details of smart contract function calls, including all addresses and parameters in an easy-to-understand format.
// DecodeSmartContract decodes smart contract call data
func (p *TronParser) DecodeSmartContract(contract *core.Transaction_Contract) *DecodedCallFeatures:
- Returns complete decoded call information
- Extracts method signature and name
- Identifies all addresses in parameters
- Decodes amounts and other parameters
- Returns nil for non-smart-contract transactions
// Store decoded smart contract info in event data
if decoded := m.parser.DecodeSmartContract(contract); decoded != nil {
event.EventData["smartContract"] = map[string]interface{}{
"methodSignature": decoded.MethodSignature,
"methodName": decoded.MethodName,
"addresses": decoded.Addresses,
"parameters": decoded.Parameters,
}
}Benefits:
- All events now include smart contract decoding
- Data stored in structured format
- Available via API and WebSocket
- No breaking changes to existing API
def display_smart_contract_info(self, smart_contract: dict):
"""Display decoded smart contract information in human-readable format"""Features:
- Recognizes TRC20 functions (transfer, transferFrom, approve, etc.)
- Converts hex addresses to base58 (T... format)
- Formats token amounts with proper decimals
- Shows operation-specific information
- Displays both hex and readable addresses
- Transaction events now show decoded smart contract info
- Clear visual sections with emoji indicators
- Function-specific formatting
- Full address conversion (hex → base58)
| Function | Signature | Display |
|---|---|---|
transfer(address,uint256) |
a9059cbb |
💸 TOKEN TRANSFER |
transferFrom(address,address,uint256) |
23b872dd |
💸 TOKEN TRANSFER (Approved) |
approve(address,uint256) |
095ea7b3 |
✅ TOKEN APPROVAL |
balanceOf(address) |
70a08231 |
💰 BALANCE QUERY |
allowance(address,address) |
dd62ed3e |
🔍 ALLOWANCE QUERY |
| Generic/Unknown | (any) | 📋 PARAMETERS (with addresses) |
================================================================================
EVENT #1
================================================================================
TX Hash: 6f2cc36e9105a389ec688b89168d8d6f5bb92367...
Block: 61115147
Type: TriggerSmartContract
Success: True
--------------------------------------------------------------------------------
BASIC TRANSACTION:
--------------------------------------------------------------------------------
From (hex): 41a977d20898ed9198d7977864876f6b92e9d53df1
From: TRRGjkNwoA32ynkQ2UvcHS6vx7vNyh8zCA
To (hex): 41eca9bc828a3005b9a3b909f2cc5c2a54794de05f
To: TXYZopYRdj2D9XRtbG411XZZ3kM5VkAeBf
--------------------------------------------------------------------------------
🔍 SMART CONTRACT DECODED:
--------------------------------------------------------------------------------
Function: transfer(address,uint256)
Signature: 0xa9059cbb
💸 TOKEN TRANSFER:
To (hex): 4190517a46c051dbe39eaf2418befe71694a570521
To: TP8HurAGMeJpx3SXLdK3mV31rEFe7TqUBQ
Amount: 1.100000 tokens
Amount (raw): 1100000
-
Transaction Layer:
- From: TRRGjkNwoA32ynkQ2UvcHS6vx7vNyh8zCA (sender wallet)
- To: TXYZopYRdj2D9XRtbG411XZZ3kM5VkAeBf (USDT contract)
-
Smart Contract Layer (NEW!):
- Function: transfer(address,uint256)
- Recipient: TP8HurAGMeJpx3SXLdK3mV31rEFe7TqUBQ
- Amount: 1.1 USDT
Key Insight: The recipient address (TP8...) was inside the function parameters, not in the transaction fields! This is exactly what was missing before.
Events now include smartContract in the data:
{
"eventId": "evt_...",
"type": "TriggerSmartContract",
"data": {
"from": "41a977d20898ed9198d7977864876f6b92e9d53df1",
"to": "41eca9bc828a3005b9a3b909f2cc5c2a54794de05f",
"eventData": {
"smartContract": {
"methodName": "transfer(address,uint256)",
"methodSignature": "a9059cbb",
"addresses": [
"4190517a46c051dbe39eaf2418befe71694a570521"
],
"amount": "1100000",
"parameters": {
"to": "4190517a46c051dbe39eaf2418befe71694a570521",
"amount": "1100000"
}
}
}
}
}-
internal/blockchain/parser/tron_parser.go
- Added:
DecodeSmartContract()method (lines 30-62) - Purpose: Return decoded smart contract information
- Added:
-
internal/blockchain/monitor/address_monitor.go
- Modified:
extractEvent()function (lines ~340-360) - Added: Smart contract decoding and storage in event data
- Modified:
- event_monitor.py
- Added:
display_smart_contract_info()function (~120 lines) - Modified:
display_event()to call smart contract display - Modified:
display_transaction_event()to show decoded info
- Added:
-
SMART_CONTRACT_DECODING_MONITOR.md (NEW)
- Complete guide to the feature
- Examples and usage instructions
- Technical details and extension guide
-
test_smart_contract_display.py (NEW)
- Test script to demonstrate the feature
- Fetches recent events and displays decoded info
✅ Backend: Successfully decoding smart contract calls
- Method signatures identified correctly
- Addresses extracted from parameters
- Amounts decoded properly
- Data stored in events
✅ Frontend: Human-readable display working
- Function names displayed clearly
- Addresses shown in both hex and base58
- Amounts formatted with decimals
- Clear visual sections
✅ Integration: Complete end-to-end flow
- Events captured with decoded data
- WebSocket delivers complete information
- Monitor displays everything correctly
curl -s http://localhost:8080/api/v1/events?limit=1 | jq '.events[0].data.eventData.smartContract'Output:
{
"addresses": ["41c5945cb070af231b0fc7e752ef846d923ed5cb50"],
"amount": "10000000",
"methodName": "transfer(address,uint256)",
"methodSignature": "a9059cbb",
"parameters": {
"amount": "10000000",
"to": "41c5945cb070af231b0fc7e752ef846d923ed5cb50"
}
}source .venv/bin/activate
python test_smart_contract_display.pyResult: ✅ All events display with decoded smart contract information
-
Complete Visibility: See all addresses involved in a transaction
- Transaction-level addresses (from/to)
- Parameter-level addresses (recipients, spenders, etc.)
-
Human-Readable Format: Everything in T... format
- No need to manually convert hex addresses
- Clear operation descriptions
-
Amount Clarity: Token amounts with proper decimals
- Raw amounts: 1100000
- Formatted: 1.100000 tokens
-
Context Understanding: Know what function was called
- Transfer vs TransferFrom vs Approve
- Clear operation labels with emojis
-
Complete Data: Full event structure preserved
- Raw data still available in JSON
- Decoded data added as enhancement
-
Easy Integration: Standard API response
- No breaking changes
- Additional fields optional to use
-
Debugging: Clear visibility into contract calls
- See method signatures
- Inspect all parameters
- Verify address extraction
-
Extensibility: Easy to add new functions
- Add signature to abi_decoder.go
- Add decoder function
- Add display format to monitor
- Minimal overhead: Simple byte parsing
- Already running: ABI decoder was implemented previously
- No additional API calls: Decoding happens during event extraction
- Memory efficient: Only stores decoded data, not raw calldata
-
Additional Contract Types
- TRC721 (NFT transfers)
- TRC1155 (Multi-token)
- DEX-specific functions (swap, addLiquidity)
- Staking contracts
-
Event Log Decoding
- Decode emitted events (Transfer events from logs)
- Extract indexed topics
- Parse event data fields
-
Enhanced Amount Formatting
- Auto-detect token decimals
- Display token symbols (USDT, USDC, etc.)
- Show USD values if available
-
Query Support
- Filter by function name
- Search by parameter values
- Find transactions with specific addresses in parameters
✅ Backend: Smart contract decoding integrated into event extraction ✅ Frontend: Human-readable display with address conversion ✅ Testing: Verified with real transactions ✅ Documentation: Complete guides created ✅ Production: Deployed and actively processing events
The system now provides complete visibility into smart contract interactions, solving the original issue where addresses in function parameters were not detected. Every USDT transfer, approval, or other TRC20 operation is now fully decoded and displayed in an easy-to-understand format.
# Start monitoring
source .venv/bin/activate
# Watch all events with smart contract decoding
python event_monitor.py
# Watch specific address
python event_monitor.py --address THpjvxomBhvZUodJ3FHFY1szQxAidxejy8
# Test the display
python test_smart_contract_display.pyEvery smart contract interaction will now show:
- 📝 Function name and signature
- 💸 Operation type (Transfer, Approval, etc.)
- 👤 All addresses (hex + readable)
- 💰 Token amounts (formatted)
- 📋 All parameters
Result: Complete transparency into blockchain smart contract activity! 🎉