encodeUint64(asset_id) doesn't work

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)

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?

I did use this version just 2 minutes ago and still got same error

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

node 14.17.0 and algosdk 1.24.1

i am using node v16.18.1 …

It looks like node v14.10 or after should work as this function was added in v14.10:
https://nodejs.org/api/buffer.html#bufwritebiguint64bevalue-offset

So my guess is that you’re using a framework/toolchain that is somewhat not providing this function.
It looks you are using react, but which toolchain are you using:
create react app, next.js, gatsby, vite
?
Which version?

Maybe posting package.json may help.

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

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

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?