Skip to main content

JavaScript Snippet (Copy-Paste Ready)

Add this directly to your token card or details component.
<div id="txshield-badge" style="font-weight: bold; margin-left: 8px;"></div>

<script>
async function renderTxShieldBadge(tokenAddress, chainId = 1) {
  try {
    const res = await fetch('[https://api.txshield.xyz/api/honeypot/honeypot-checks](https://api.txshield.xyz/api/honeypot/honeypot-checks)', {
      method: 'POST',
      headers: { 
        'Content-Type': 'application/json'
        // 'X-TxShield-Key': 'YOUR_API_KEY' // Recommended for production
      },
      body: JSON.stringify({ tokenAddress, chainId })
    });
    
    const data = await res.json();
    const badge = document.getElementById('txshield-badge');
    
    // Fallback if API fails or returns error
    if (data.success === false && typeof data.riskScore === 'undefined') {
      badge.innerHTML = '<span style="color:gray">TxShield unavailable</span>';
      return;
    }

    // Render badge based on risk score
    if (data.riskScore <= 20) {
      badge.innerHTML = '<span style="color:#16A34A">✅ TxShield Verified</span>';
    } else if (data.riskScore <= 60) {
      badge.innerHTML = '<span style="color:#F59E0B">⚠️ TxShield Caution</span>';
    } else {
      badge.innerHTML = '<span style="color:#DC2626">❌ TxShield High Risk</span>';
    }
    
  } catch (error) {
    console.error('TxShield badge failed to load:', error);
  }
}

// Usage on page load
renderTxShieldBadge('0xTokenAddressHere', 1);
</script>
Ready in 30 seconds.
Reach out to @txshield_ or partnerships@txshield.xyz for deeper integration.