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

Transaction function of contract with provider having rejected _networkPromise gives: TypeError: Cannot redefine property: _network #854

Closed
zemse opened this issue May 28, 2020 · 3 comments
Labels
bug Verified to be an issue. fixed/complete This Bug is fixed or Enhancement is complete and published.

Comments

@zemse
Copy link
Collaborator

zemse commented May 28, 2020

Way to reproduce the error:

const ethers = require('ethers'); // v5
const provider = new ethers.providers.JsonRpcProvider('http://localhost:7545');

provider._networkPromise.then(console.log).catch(console.log);

const contractDeployerWallet = new ethers.Wallet(
  'privatekey',
  provider
);

let contract = new ethers.Contract(
  '0xc4cfb05119Ea1F59fb5a8F949288801491D00110',
  require('./static/contracts/PlasmaManager_PlasmaManager.json').abi,
  contractDeployerWallet
);

// turn on the ganache and get the contract deployed (with a known wallet 
//   so you can input the contract address above) using separate script

setTimeout(() => {
  contract.functions
    .submitBunchHeader()
    .then(console.log);
}, 8000);

A CI test was failing because the ganache process and a node js process when simultaneously to start up, sometimes ganache takes bit more time to get started.

Error stack:

(node:17760) UnhandledPromiseRejectionWarning: TypeError: Cannot redefine property: _network
    at Function.defineProperty (<anonymous>)
    at Object.defineReadOnly (/Users/sohamzemse/soham/kmpards/ESNCoreProjects/kami/node_modules/@ethersproject/properties/lib/index.js:43:12)
    at JsonRpcProvider.<anonymous> (/Users/sohamzemse/soham/kmpards/ESNCoreProjects/kami/node_modules/@ethersproject/providers/lib/base-provider.js:287:38)
    at step (/Users/sohamzemse/soham/kmpards/ESNCoreProjects/kami/node_modules/@ethersproject/providers/lib/base-provider.js:46:23)
    at Object.next (/Users/sohamzemse/soham/kmpards/ESNCoreProjects/kami/node_modules/@ethersproject/providers/lib/base-provider.js:27:53)
    at fulfilled (/Users/sohamzemse/soham/kmpards/ESNCoreProjects/kami/node_modules/@ethersproject/providers/lib/base-provider.js:18:58)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:17760) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:17760) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

However if a call function is called before the transaction function, then it doesn't error.

setTimeout(async () => {
  await contract.functions.name();

  contract.functions
    .submitBunchHeader()
    .then(console.log);
}, 8000);

Sorry if this title is does not best describe the issue. I think I had written a better one in my previous attempt to write this issue and my MB went out of battery just before submitting :"(

@ricmoo ricmoo added investigate Under investigation and may be a bug. bug Verified to be an issue. on-deck This Enhancement or Bug is currently being worked on. and removed investigate Under investigation and may be a bug. labels May 29, 2020
@ricmoo
Copy link
Member

ricmoo commented May 29, 2020

Just seeing the error made me realize a case I don't check for. I'll get a fix for this up soon.

@ricmoo
Copy link
Member

ricmoo commented May 30, 2020

This should be fixed now in 5.0.0-beta.189. Please try it out and let me know if you still have any problems. :)

@ricmoo ricmoo added fixed/complete This Bug is fixed or Enhancement is complete and published. and removed on-deck This Enhancement or Bug is currently being worked on. labels May 30, 2020
@zemse
Copy link
Collaborator Author

zemse commented May 30, 2020

Thank you! It's working as expected now

@zemse zemse closed this as completed May 30, 2020
michaeltout pushed a commit to michaeltout/ethers.js that referenced this issue Aug 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified to be an issue. fixed/complete This Bug is fixed or Enhancement is complete and published.
Projects
None yet
Development

No branches or pull requests

2 participants