WietseWind / xrpl-accountlib

XRPL Account helper: generation, derivation and signing (family seed, mnemonic, passphrase)
MIT License
27 stars 12 forks source link

SetHook issue? #318

Closed etherum123 closed 5 months ago

etherum123 commented 5 months ago

Probably my fault, but I am trying to deploy a hook using your example code with some amendments

import {
  derive,
  utils,
  signAndSubmit,
} from "*****/xrpl-accountlib/dist/index.js"; // require('xrpl-accountlib') after `npm install xrpl-accountlib` in prod.

import * as fs from 'fs';

console.log("Sign & Submit (Custom Definitions)");
console.log();

const wss = 'wss://hooks-testnet-v3.xrpl-labs.com/'
//const http = 'https://s.altnet.rippletest.net:51234/'
const http = 'wss://xahau-test.net'
const account = derive.familySeed("**********")

const networkInfo = await utils.txNetworkAndAccountValues(http, account)

console.log(networkInfo)
console.log()

const tx = {
  Account: "*******************",
  TransactionType: "SetHook",
  Fee: "2000000",
  Sequence: "768926057",
  NetworkID: "21338",
  Hooks: [ { Hook: {
    CreateCode: fs.readFileSync('hooks/hook01.wasm').toString('hex').toUpperCase(),
    Flags: 1,
    HookApiVersion: 0,
    HookNamespace: "54EE4058F44E63CAD2C1A7B67BB356B14476649EDD255D6C8B08D214C289FE2E",
    HookOn: "0000000000000000",
    }
  }],
  }; 
const submitted = await signAndSubmit(tx, wss, account)

console.log(submitted);
console.log();

I run it using: node deploy-hook.mjs And I get this:

node_modules/xrpl-binary-codec-prerelease/dist/types/hash.js:13
            throw new Error(`Invalid Hash length ${this.bytes.byteLength}`);
                  ^

Error: Invalid Hash length 8
    at new Hash (/home/richardc/node_modules/xrpl-binary-codec-prerelease/dist/types/hash.js:13:19)
    at new Hash256 (/home/richardc/node_modules/xrpl-binary-codec-prerelease/dist/types/hash-256.js:11:9)
    at Hash256.from (/home/richardc/node_modules/xrpl-binary-codec-prerelease/dist/types/hash.js:26:20)
    at /home/richardc/node_modules/xrpl-binary-codec-prerelease/dist/types/st-object.js:115:44
    at Array.forEach (<anonymous>)
    at STObject.from (/home/richardc/node_modules/xrpl-binary-codec-prerelease/dist/types/st-object.js:110:16)
    at /home/richardc/node_modules/xrpl-binary-codec-prerelease/dist/types/st-object.js:112:24
    at Array.forEach (<anonymous>)
    at STObject.from (/home/richardc/node_modules/xrpl-binary-codec-prerelease/dist/types/st-object.js:110:16)
    at /home/richardc/node_modules/xrpl-binary-codec-prerelease/dist/types/st-array.js:54:49

Node.js v20.12.2

Is this an issue or my mistake?

WietseWind commented 5 months ago

Thanks for building!!

I see three issues:

Sequence: "768926057",
NetworkID: "21338",

The above two need to be Number

Then the one that actually triggers this error: HookOn needs to be a 64 char long HEX value.

etherum123 commented 5 months ago

Thank you.