Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error while loading supertoken from serverside functions #1768

Closed
luisalrp opened this issue Jan 3, 2024 · 2 comments
Closed

Error while loading supertoken from serverside functions #1768

luisalrp opened this issue Jan 3, 2024 · 2 comments
Assignees
Labels
Type: Bug Something isn't working

Comments

@luisalrp
Copy link

luisalrp commented Jan 3, 2024

Describe the bug:
Not possible to load a supertoken from serverside functions like nextjs 14 server components or cloudflare workers.

Environment (please complete the following information):

  • Device: Macbook Pro Intel
  • OS: OSX
  • Network/Connection: Ethernet
  • Project Type: Nextjs 14 with server functions.
  • Package version: ^0.6.12
  • TypeScript/Javascript: Typescript
  • Blockchain interfacing library: ethers.js
  • Provider: I tried plenty... Infura, Alchemy, Custom RPC endpoint
  • Chain: Goerli
  • If running in node:
    • Node version: v18.19.0
    • Framework: n/a
  • else, running in browser:
    • Browser chrome
    • Front-end Framework: Nextjs 14.

Steps To Reproduce:
Steps to reproduce the behavior:

  1. Clone the PoC
  2. cp env.example env.local and modify the environment variables if needed.
  3. run the PoC with 'pnpm dev'
  4. Enter the dapp using the browser, connect the wallet and click on "get flow rate" button.
  5. Open developer tools and watch the console output.
  6. Go to terminal and see the error.

Expected behavior:
I expected the same behavior as client side, since the code is the same. It should retrieve the flowrate and set it into the serverside label.

Actual behavior:
Client side function works ok, but server side function prompts the following error in the terminal:

Error getting flow info SFError: SuperToken Initialization Error: There was an error initializing the SuperToken
Caused by: {
  "name": "Error",
  "code": "CALL_EXCEPTION",
  "message": "missing revert data in call exception; Transaction reverted without a reason string [ See: https://links.ethers.org/v5-errors-CALL_EXCEPTION ] (data="0x", transaction={"to":"0x8aE68021f6170E5a766bE613cEA0d75236ECCa9a","data":"0x95d89b41","accessList":null}, error={"reason":"missing response","code":"SERVER_ERROR","requestBody":"{\\"method\\":\\"eth_call\\",\\"params\\":[{\\"to\\":\\"0x8ae68021f6170e5a766be613cea0d75236ecca9a\\",\\"data\\":\\"0x95d89b41\\"},\\"latest\\"],\\"id\\":43,\\"jsonrpc\\":\\"2.0\\"}","requestMethod":"POST","serverError":{},"url":"https://goerli.gateway.tenderly.co"}, code=CALL_EXCEPTION, version=providers/5.7.2)"

Screenshots/Code Snippets:
If applicable, attach screenshots and/or copy code snippets where the problem is occurring to further help explain your problem.

Additional context:
It is virtually imposible to load a supertoken from serverside functions like nextjs 14 ones or cloudflare workers. I don't know why. I've found after so many hours tracking the issue that it was an ethers issue and they implemented a new method to create an ethers StaticJsonRpcProvider.

Screenshot from ethers documentation.
image

From my point of view Superfluid Framework is a great tool that abstracts most of complexity, but there are some edge cases like this that so many checks like the ones when loading a supertoken are in conflict with ethers 5.7.2 utilization from serverside.

I hope it helps and superfluid adoption increases.

Best,
Luis Alberto

@luisalrp luisalrp added the Type: Bug Something isn't working label Jan 3, 2024
@luisalrp
Copy link
Author

luisalrp commented Jan 9, 2024

I followed a different path for hunting the issue.

Create de Superfluid Framework using the StaticJsonRpcProvider to avoid the previous errors I had about getting network:

const sf = await Framework.create({
      chainId: chainId,
      provider: new ethers.providers.StaticJsonRpcProvider(process.env.RPCPROVIDER_URL, 'goerli'), // -> Crea un options interno que solo tiene "url"
    });

Then, create an instance of a Supertoken by hand:

superToken = await SuperToken.create({
          address: _supertoken,
          config: sf.settings.config,
          provider: sf.settings.provider,
          chainId: sf.settings.chainId,
          networkName: sf.settings.networkName,
      });

If we debug inside that code, then you get to:

const tokenSymbol = await superToken
            .connect(options.provider)
            .symbol();

StaticJsonRpcProvider do a send (ethers) y and then a getURL (ethers). The code inside the getURL:

if (options.skipFetchSetup !== true) { // -> Not exists, it just exists the "url"
  request.mode = "cors"; // no-cors, cors, same-origin
  request.cache = "no-cache"; //default, no-cache, reload, force-cache, only-if-cached
  request.credentials = "same-origin"; // include, same-origin, omit
  request.redirect = "follow"; // manual,follow, error
  request.referrer = "client"; // no-referrer, *client
}

Finally, it calls for the creation of a new URL (Node process internal). In the line:
const href = bindingUrl.parse(input, base); // input is the referrer, "client"
When href is empty -> "Referrer 'client' is not a valid URL." (it doesn't even make the RPC call)"

@youssefea
Copy link

@philipandersson this can be closed. It is most likely an error on ethers side.

I assisted @luisalrp with his project yesterday, and he is moving away from the SDK all together.

@luisalrp luisalrp closed this as not planned Won't fix, can't repro, duplicate, stale Jan 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants