Handy_4ndy's profile banner
Handy_4ndy's profile picture

Handy_4ndy

@Handy_4ndy

February 13
Founder / Developer
Manchester
4 min read
HandyHooks
1

Spam Prevention Hook

Updated

Spam Prevention imageSpam Prevention image

Introducing the Spam Prevention Hook

While scrolling through X recently, I came across an engaging discussion sparked by @dazzlingxrpl, who posed the question of whether Xahau Hooks could serve as a proving ground for smart contracts before their integration into the XRPL.

Inspired by Mayukha’s thoughtful reply, my naturally impulsive nature kicked in, prompting me to explore how current XRP Ledger challenges could be tackled with smart contracts today while preventing issues that could emerge on Xahau tomorrow.

The InspirationThe Inspiration

Although Hooks may not seamlessly transition to the XRPL’s smart contract framework, the concepts behind this example provide valuable insights into future possibilities. I’m excited about smart features and contracts coming to the XRPL, and I extend my gratitude to Mayukha for her pivotal role in integrating these advancements into rippled, opening up a new realm of programmable potential.

This Hook addresses two key issues: spam transactions and unwanted parameters.

Addressing Key Issues

  • Spam/Dust Transactions: Active participants in the ecosystem are all too familiar with this nuisance. Tiny transactions (e.g., 0.000012 XAH with memos) sent to accounts incur network fees, burden infrastructure, and raise compliance concerns.
  • Hook Parameters: Although not yet a feature of the XRPL, limiting Hook parameters could benefit users, particularly newcomers hesitant to engage with smart contracts without thorough research.

The Spam Prevention Hook empowers you to manage these issues by activating or deactivating features that automatically reject incoming payments below 1 XAH, block Hook parameters, and filter memo fields.

Getting Started

Create Testnet credentials via Bithomp’s Xahau Explorer:

We’ll use XRPLWin’s dashboards (live on Testnet and Mainnet) to install the Hook from a hash and configure settings with the Raw JSON Transaction Sender. For Mainnet, simply swap the Hook hash.

  • Testnet: B7D5ECD3DA42CF90A689BD659617436565C4D5E0ED2E0865737E35387EC9855A
  • Mainnet: 277A521F154C34C81B99CE6CE0F000DBC284673C07CC7B37D4056A64BCB2F07D

Installation

  1. Sign into your Testnet account on Developer Tools (top-right corner).
  2. Select "Install from Hook Hash," paste the Testnet hash, and submit. This opens the Raw JSON Transaction Sender.

XRPLWin’s Hook Hash InstallerXRPLWin’s Hook Hash Installer

  1. Submit the following transaction to set the Hook, triggering it on Invoke and Payment transactions:
{
    "TransactionType": "SetHook",
    "Flags": 0,
    "Hooks": [
        {
            "Hook": {
                "HookHash": "B7D5ECD3DA42CF90A689BD659617436565C4D5E0ED2E0865737E35387EC9855A",
                "Flags": 1,
                "HookOn": "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFFFFFFFFFBFFFFE",
                "HookNamespace": "4FF9961269BF7630D32E15276569C94470174A5DA79FA567C0F62251AA9A36B9"
            }
        }
    ]
}

Note: HookOn settings can be checked here.

Configuration

Use the Raw JSON Transaction Sender to toggle settings with Invoke transactions. Parameters are hex-encoded:

  • Parameter Names: MIN (4D494E), PAR (504152), MEM (4D454D)
  • Parameter Values: 01 (Activate), 00 (Deactivate)

Activate Minimum Amount (Reject < 1 XAH)

{
    "TransactionType": "Invoke",
    "HookParameters": [
        {
            "HookParameter": {
                "HookParameterName": "4D494E",
                "HookParameterValue": "01"
            }
        }
    ]
}

Activating the minimum amount will prevent any incoming transactions below 1 XAH. To change this threshold, edit the code and compile to WASM.

Activate Minimum AmountActivate Minimum Amount

Activate Parameter Block

{
    "TransactionType": "Invoke",
    "HookParameters": [
        {
            "HookParameter": {
                "HookParameterName": "504152",
                "HookParameterValue": "01"
            }
        }
    ]
}

Activating the parameter block will prevent any incoming payment transactions that contain Hook parameters. You can still invoke Hook parameters to disable this setting.

Activate Parameter BlockingActivate Parameter Blocking

Activate Memo Block

{
    "TransactionType": "Invoke",
    "HookParameters": [
        {
            "HookParameter": {
                "HookParameterName": "4D454D",
                "HookParameterValue": "01"
            }
        }
    ]
}

Activating the memo block will automatically reject any incoming payment transaction that contains memo data.

Activate Memo BlockActivate Memo Block

Verification

Test the Hook by activating the MIN setting and then sending a transaction below 1 XAH (e.g., 0.000012 XAH), which should be rejected. Check your namespace at https://xahau-testnet.xrplwin.com/account/YOUR_rADDRESS_HERE/namespaces and troubleshoot if needed.

Source Code

The original source code is available on GitHub as part of the HandyHooks collection. To change the minimum amount you are willing to receive, adjust the defined MIN_AMOUNT_VALUE on line 38 to your desired value.

Latest Progress on XRPL Smart Contract Amendments

XahauHooksXRP LedgerSmart ContractsSpam Prevention