Facing Error When Calling initFhevm() in Web Extension

Hi Team,

I’m currently working on a web extension where I need to access the fhevmInstance. However, I’m encountering an error while calling the initFhevm() function. Below are the error logs I’m facing:


Error Logs

  1. Primary Error Log

Copy code

index.html:6896 TypeError#1: Cannot read properties of undefined (reading 'instantiate')
  1. Stack Trace

Copy code

at B (eval at <anonymous> (eval at makeEvaluate (chrome-extension://ljfoeinjpaedjfecbmggjgodbgkmjkjk/snaps/index.html:6368:27)), <anonymous>:1:253033)
at _Q (eval at <anonymous> (eval at makeEvaluate (chrome-extension://ljfoeinjpaedjfecbmggjgodbgkmjkjk/snaps/index.html:6368:27)), <anonymous>:1:253359)
at AE (eval at <anonymous> (eval at makeEvaluate (chrome-extension://ljfoeinjpaedjfecbmggjgodbgkmjkjk/snaps/index.html:6368:27)), <anonymous>:1:253457)
at Q (eval at <anonymous> (eval at makeEvaluate (chrome-extension://ljfoeinjpaedjfecbmggjgodbgkmjkjk/snaps/index.html:6368:27)), <anonymous>:1:3500910)
at E (eval at <anonymous> (eval at makeEvaluate (chrome-extension://ljfoeinjpaedjfecbmggjgodbgkmjkjk/snaps/index.html:6368:27)), <anonymous>:1:3501017)
at gE (eval at <anonymous> (eval at makeEvaluate (chrome-extension://ljfoeinjpaedjfecbmggjgodbgkmjkjk/snaps/index.html:6368:27)), <anonymous>:1:3501215)
at chrome-extension://ljfoeinjpaedjfecbmggjgodbgkmjkjk/snaps/bundle.js:9:46693
at l.executeInSnapContext (chrome-extension://ljfoeinjpaedjfecbmggjgodbgkmjkjk/snaps/bundle.js:9:51180)
at chrome-extension://ljfoeinjpaedjfecbmggjgodbgkmjkjk/snaps/bundle.js:9:46665
at Object.snapRpc (chrome-extension://ljfoeinjpaedjfecbmggjgodbgkmjkjk/snaps/bundle.js:9:51887)

Environment Details

  • Extension Framework: Chrome Extension
  • Error Context: Occurs when invoking initFhevm()
  • Browser: Chrome
  • Relevant Libraries:
    • fhevm-related package
    • ethers.js

Using fhevmjs in an extension will be very tricky because fhevmjs is using WASM and webworkers. I don’t think it will be doable out of the box, especially if you’re using Metamask snaps. You can try to use our bundled version which is working totally fine in a website and maybe could work in a extension Build a web application | fhEVM