Ethers.js: Cannot redefine property: provider

Created on 24 Mar 2021  ·  3Comments  ·  Source: ethers-io/ethers.js

When I try and create a contract instance of the iearn DAI (yDAI) contract I get this error

 TypeError: Cannot redefine property: provider
    at Function.defineProperty (<anonymous>)
    at Object.defineReadOnly (/Users/nick/Documents/workspaces/tx2uml/node_modules/@ethersproject/properties/src.ts/index.ts:8:12)
    at /Users/nick/Documents/workspaces/tx2uml/node_modules/@ethersproject/contracts/src.ts/index.ts:729:17
    at Array.forEach (<anonymous>)
    at new Contract (/Users/nick/Documents/workspaces/tx2uml/node_modules/@ethersproject/contracts/src.ts/index.ts:720:34)
    at EtherscanClient.getContract (/Users/nick/Documents/workspaces/tx2uml/src/ts/clients/EtherscanClient.ts:68:36)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)

The problem seems to be coming from the provider function. It's ABI segment is

{
    "constant": true,
    "inputs": [],
    "name": "provider",
    "outputs": [
        { "internalType": "enum yDAI.Lender", "name": "", "type": "uint8" }
    ],
    "payable": false,
    "stateMutability": "view",
    "type": "function"
},

If I rename the provider function in the ABI to providerX, I can create an instance of the contract. eg

const abi = response.data.result[0].ABI.replace(
                "provider",
                "providerX"
            )
const ethersContract = new EthersContract(contractAddress, abi)

I'm using Ethers 5.0.32

Thanks
Nick

bug fixed

Most helpful comment

You are correct! I'm not sure what this is happening, but I can reproduce it with your example. I'll add a fix to this in the next few days with the release the includes EIP-2930 support.

Thanks!

All 3 comments

You are correct! I'm not sure what this is happening, but I can reproduce it with your example. I'll add a fix to this in the next few days with the release the includes EIP-2930 support.

Thanks!

This should be fixed in 5.1.0. Try it out and let me know how it goes. :)

(FYI. the problem was properties previously defined using defineReadOnly when the value was null; so the if (blah == null) was implying it was safe to add the property, despite it not being safe because the property was already explicitly frozen at its null value)

Thanks @ricmoo. I can confirm v5.1.0 fixes the issue parsing the iearn DAI (yDAI) contract.

Was this page helpful?
0 / 5 - 0 ratings