ethers.js icon indicating copy to clipboard operation
ethers.js copied to clipboard

EthersV6: Maximum call stack size exceeded

Open zemse opened this issue 2 years ago • 3 comments

Ethers Beta Version

6.0.0-beta.9

Describe the Problem

When trying to create a Contract object, an error occurs if ABI generated by solidity compiler is passed.

I've noted that this issue is not observed if human readable ABI is used ["function getValue() view returns (string)"].

Code Snippet

import { Contract } from "ethers";

const abi = [
  {
    inputs: [],
    name: "getValue",
    outputs: [{ internalType: "string", name: "", type: "string" }],
    stateMutability: "view",
    type: "function",
  },
];

const contract = new Contract(
  "0x0000000000000000000000000000000000000000",
  abi
); // this line causes the issue

Errors

% node contract.js  
file:///Users/sohamzemse/Workspace/ethers-v6/node_modules/@ethersproject/abi/lib/fragments.js:650
        switch (obj.type) {
                    ^

RangeError: Maximum call stack size exceeded
    at Function.fromObject (file:///Users/sohamzemse/Workspace/ethers-v6/node_modules/@ethersproject/abi/lib/fragments.js:650:21)
    at Function.fromObject (file:///Users/sohamzemse/Workspace/ethers-v6/node_modules/@ethersproject/abi/lib/fragments.js:654:54)
    at Function.fromObject (file:///Users/sohamzemse/Workspace/ethers-v6/node_modules/@ethersproject/abi/lib/fragments.js:654:54)
    at Function.fromObject (file:///Users/sohamzemse/Workspace/ethers-v6/node_modules/@ethersproject/abi/lib/fragments.js:654:54)
    at Function.fromObject (file:///Users/sohamzemse/Workspace/ethers-v6/node_modules/@ethersproject/abi/lib/fragments.js:654:54)
    at Function.fromObject (file:///Users/sohamzemse/Workspace/ethers-v6/node_modules/@ethersproject/abi/lib/fragments.js:654:54)
    at Function.fromObject (file:///Users/sohamzemse/Workspace/ethers-v6/node_modules/@ethersproject/abi/lib/fragments.js:654:54)
    at Function.fromObject (file:///Users/sohamzemse/Workspace/ethers-v6/node_modules/@ethersproject/abi/lib/fragments.js:654:54)
    at Function.fromObject (file:///Users/sohamzemse/Workspace/ethers-v6/node_modules/@ethersproject/abi/lib/fragments.js:654:54)
    at Function.fromObject (file:///Users/sohamzemse/Workspace/ethers-v6/node_modules/@ethersproject/abi/lib/fragments.js:654:54)

Environment

node.js

Environment (Other)

No response

zemse avatar Jun 02 '22 19:06 zemse

Thanks! I’ll look into this right away. :)

ricmoo avatar Jun 02 '22 19:06 ricmoo

The problem is in interface initialization.

ConstructorFragment.fromObject()
ErrorFragment.fromObject()
EventFragment.fromObject()
FunctionFragment.fromObject()
StructFragment.fromObject()

is not implemented. And it causes endless recursion because of extending basic Fragment class. @ricmoo without this it is impossible to test further

farwayer avatar Sep 15 '22 21:09 farwayer

@farwayer oh yes. I think this may be fixed in the latest GitHub version? I’ll double check shortly. I’m working on some v6 provider stuff right now, but will check that next.

ricmoo avatar Sep 16 '22 04:09 ricmoo

This should be fixed now. Let me know if you still have any issues.

Thanks! :)

ricmoo avatar Dec 30 '22 22:12 ricmoo