Created
January 12, 2025 16:08
-
-
Save Ekiserrepe/eaa4035c56a01dad3f9287661d35c107 to your computer and use it in GitHub Desktop.
Create Hook
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const xrpl = require('xrpl'); | |
const fs = require('fs'); | |
const crypto = require('crypto'); | |
const { derive, utils, signAndSubmit } = require("xrpl-accountlib"); | |
//Account seed, dont publish your code with your seed | |
const seed = 'your_seed'; | |
const network = "wss://xahau.network"; | |
async function connectAndQuery() { | |
const client = new xrpl.Client('wss://xahau.network'); | |
//const client = new xrpl.Client('wss://xahau-test.net'); | |
const account = derive.familySeed(seed, { algorithm: "secp256k1" }); | |
console.log(`Account: ${JSON.stringify(account)}`); | |
try { | |
await client.connect(); | |
console.log('Connected to Xahau'); | |
const my_wallet = xrpl.Wallet.fromSeed(seed); | |
const networkInfo = await utils.txNetworkAndAccountValues(network, account); | |
const prepared = { | |
"TransactionType": "SetHook", | |
"Account": my_wallet.address, | |
"Flags": 0, | |
"Hooks": [ | |
{ | |
"Hook": { | |
"CreateCode": fs.readFileSync('your_hook.wasm').toString('hex').toUpperCase(), | |
"HookOn": 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFFF7FFFFFBFFFFE', //Generate your HookOn here https://richardah.github.io/xrpl-hookon-calculator/ | |
"HookNamespace": crypto.createHash('sha256').update('your_hook').digest('hex').toUpperCase(), | |
"Flags": 1, | |
"HookApiVersion": 0 | |
} | |
} | |
], | |
...networkInfo.txValues, | |
}; | |
const tx = await signAndSubmit(prepared, network, account); | |
console.log("Info tx:", JSON.stringify(tx, null, 2)); | |
} catch (error) { | |
console.error('Error:', error); | |
} finally { | |
await client.disconnect(); | |
console.log('Disconnected from Xahau'); | |
} | |
} | |
connectAndQuery(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment