This forum is a read-only archive. Posting, replying and signing in are disabled.

encodeUint64(asset_id) doesn't work

salman.haider

I’m trying to push the assetID to app.Args by encoding it to uint64 but its giving error

console.log(algosdk.encodeUint64(12345))

It was working fine recently but now it giving issues.


uint64.ts:17 Uncaught TypeError: buf.writeBigUInt64BE is not a function
    at Module.encodeUint64 (uint64.ts:17:1)
    at App.tsx:16:1
    at invokePassiveEffectCreate (react-dom.development.js:23487:1)
    at HTMLUnknownElement.callCallback (react-dom.development.js:3945:1)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:3994:1)
    at invokeGuardedCallback (react-dom.development.js:4056:1)
    at flushPassiveEffectsImpl (react-dom.development.js:23574:1)
    at unstable_runWithPriority (scheduler.development.js:468:1)
    at runWithPriority$1 (react-dom.development.js:11276:1)
    at flushPassiveEffects (react-dom.development.js:23447:1)
    at react-dom.development.js:23324:1
    at workLoop (scheduler.development.js:417:1)
    at flushWork (scheduler.development.js:390:1)
    at MessagePort.performWorkUntilDeadline (scheduler.development.js:157:1)
scholtz

i am using algosdk 1.24.1 without any issue…

appArgs.push(algosdk.encodeUint64(123)); works for me well…

you probably installed some dependency which downgraded/changed buffer library?

fabrice

Which version of node JS and algosdk are you using?
Are you using browserify or similar?
You may need to upgrade some of those.

AnishRane

@fabrice I am also facing same issue with algosdk 1.24.1 and node version 18.12.1, getting error on algosdk.encodeUint64() method

scholtz

i suggest to put this into your test cases

  it("encodeUint64", function () {
    expect(Buffer.from(algosdk.encodeUint64(123)).toString("hex")).toBe("000000000000007b");
    expect(Buffer.from(algosdk.encodeUint64(123123123123123)).toString("hex")).toBe("00006ffad60473b3");
  });

if it fails, there is issue with algosdk or some dependencies… if it goes through the issue is somewhere else

fabrice
↩ in reply to AnishRane

Can you show the exact error?
Are you using a framework such as create-react-app, next.js, gatsby, vite…?
Can you try to add the test suggested by @scholtz above?
Can you post your package.json (e.g., in Github gist)?
Can you create a fresh project with only algosdk and an index.js file that just test encodeUint64 and nothing else?