trufflesuite / truffle-migrate

On-chain migrations management
17 stars 17 forks source link

Contract deploy error: nonce too low #29

Closed RobinJayaswal closed 6 years ago

RobinJayaswal commented 6 years ago

Command+Errors:

$ truffle migrate --network live --reset
Using network 'live'.

Running migration: 1_initial_migration.js
  Deploying Migrations...
  ... 0x....
  Migrations: 0x...
Saving successful migration to network...
  ... 0x....
Saving artifacts...
Running migration: 2_deploy_contracts.js
  Deploying MyContract...
Error encountered, bailing. Network state unknown. Review successful transactions manually.
nonce too low

Cannot find much about this online. Is there a way I can manually specify a higher nonce for migrate?

Info: Connecting to Infura Node, Truffle v4.1.7, Node v9.5.0

RobinJayaswal commented 6 years ago

I tried running again (without reset). This time it got one step further then encountered same issue:

$ truffle migrate --network live
Using network 'live'.

Running migration: 2_deploy_contracts.js
  Deploying MyContract...
  ... 0x...
  MyContract: 0x...
Saving successful migration to network...
Error encountered, bailing. Network state unknown. Review successful transactions manually.
nonce too low
cgewecke commented 6 years ago

Hi @RobinJayaswal, sorry for the delay responding. This issue is being tracked at truffle 763. It's caused by Infura running a load-balancer in front of their nodes and the transactions intermittently falling out of sync as a result.

Some options:

Closing as duplicate.

j10sanders commented 6 years ago

Hi, I also have this issue. @cgewecke, I don't understand your solution. Are you suggesting adding that code to the migration file?

cgewecke commented 6 years ago

@j10sanders Yes - I'm suggesting that you create time delays between deployments. The idea is to wait for a few blocks to pass before attempting another transaction so that infura's architecture has time to sync everything up. I just sketched that code in - not sure it works / have not tried this strategy myself, sorry. If you try it could you report your findings back?

Tangentially, truffle has a bug with the latest version of the HDWalletProvider (0.0.5) that causes it to hang at the very end of a migration. You can ctrl-c out of the command and everything will be fine - should be fixed in a patch release scheduled for tomorrow.

eepstein commented 6 years ago

did HDWalletProvider get patched? npm shows 0.0.5 as the current release

cgewecke commented 6 years ago

@eepstein The problem is at Truffle - HDWalletProvider 0.0.5 opens interval polling using eth-block-tracker and truffle needs to close that on command exit.

Are you seeing migrations hang with Truffle v4.1.13? If so could you try making sure your HDWallet providers are wrapped in a function in truffle.js as shown in the docs here?

eepstein commented 6 years ago

I've just kept thing on 0.0.3 while waiting for the fixes. Things mostly work at this point.

(Thanks for the quick reply.)

cgewecke commented 6 years ago

Yes @eepstein 0.0.3 should be fine. The upgrade was triggered by security warnings from npm audit about sub-dependencies we felt we had to address because module is a wallet.

jlindberg-oss commented 5 years ago

@cgewecke the workaround in https://github.com/trufflesuite/truffle-migrate/issues/29#issuecomment-389649903 didn't work work for me. I still got

Saving successful migration to network...
Error encountered, bailing. Network state unknown. Review successful transactions manually.
nonce too low

I think because this is internal to deployer.deploy so the setTimeout was not helping

For anyone else finding this issue and still stuck on it, this workaround in truffle.js worked for me: https://ethereum.stackexchange.com/questions/44349/truffle-infura-on-mainnet-nonce-too-low-error