Discussions

Ask a Question
Back to All

RESET hook namespace data

Hi while testing peggy example I tried to RESET the hook namespace data

https://xrpl-hooks.readme.io/docs/sethook-transaction#namespace-reset

Is there a quick way to do this task inside the online hook ide tool filled with examples I am testing currently
or maybe do I have to create a small project outside here that sends the right "SetHook" txn using Richard's xrpl-hooks lib

below is the code I wrote online but it doesn't work, probably for "xrpl-accountlib" not supporting hooks.

thank you.


// reset-nshook.js
// RESET HOOK NAMESPACE 

//  from modified trust-user.js 



import lib from "https://esm.sh/xrpl-accountlib?bundle";
import { XrplClient } from "https://esm.sh/xrpl-client?bundle";
import keypairs from "https://esm.sh/ripple-keypairs?bundle";

/**
 * @input {Account.secret} hook_secret Hook Account
 */

const { hook_secret} = process.env

const hook_keypair = lib.derive.familySeed(hook_secret);
const hook_account = keypairs.deriveAddress(hook_keypair.keypair.publicKey);

const client = new XrplClient('wss://hooks-testnet-v2.xrpl-labs.com');

const main = async () => {
    const { account_data } = await client.send({ command: 'account_info', 'account': hook_account });

    if (!account_data) {
        console.log('Account not found.');
        client.close();
        return;
    }

    const tx = {
        TransactionType: "SetHook",
        Account: hook_account,
        Fee: "2000000",
        Sequence: account_data.Sequence,
        //Flags: 262144,
        Hooks:
        [        
            {                        
                Hook: {                
//  absent                  CreateCode: fs.readFileSync('accept.wasm').toString('hex').toUpperCase(),
//  absent                   HookOn: '0000000000000000',
                    HookNamespace: "2F8A0C01F668BCA73EC51C0D8DA77D419582347055E99D5D04FCF73B47BEBCED",
//  absent                   HookApiVersion: 0,
                    Flags:2 // hsfOVERRIDE: 1,    hsfNSDELETE: 2,
                }
            }
        ]        
    };

    //!!!! lib.sign()  doesn't handle "SetHook"
    const { signedTransaction } = lib.sign(tx, hook_keypair); 

    const submit = await client.send({ command: 'submit', 'tx_blob': signedTransaction });
    console.log(submit);

    console.log('Shutting down...');
    client.close();
};

main();