35

I have a contract and a set of mocha tests. I recently switched from using the ethereum client that comes with truffle (the one you get when you run truffle develop) to the ganache-cli. Somehow, in switching back and forth between them, I caused my tests to fail to run, and migrations don't seem to work either. The migrations work when I'm connected to ganache, but not the truffle development client. Here's the full error message.

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

Running migration: 1_initial_migration.js
  Replacing Migrations...
  ... 0x9391ac92dfbf86306e9ed896e7f9d5d45d9d88a072323ca1ef116f242ae0d2be
  Migrations: 0x8cdaf0cd259887258bc13a92c0a6da92698644c0
Saving successful migration to network...
  ... undefined
Error encountered, bailing. Network state unknown. Review successful transactions manually.
Error: Attempting to run transaction which calls a contract function, but recipient address 0x8f0483125fcb9aaaefa9209d8e9d7b9c8b9fb90f is not a contract address
    at Object.InvalidResponse (/home/altair/.nvm/versions/node/v9.6.1/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/errors.js:38:1)
    at /home/altair/.nvm/versions/node/v9.6.1/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/requestmanager.js:86:1
    at /home/altair/.nvm/versions/node/v9.6.1/lib/node_modules/truffle/build/webpack:/~/truffle-migrate/index.js:225:1
    at /home/altair/.nvm/versions/node/v9.6.1/lib/node_modules/truffle/build/webpack:/~/truffle-provider/wrapper.js:134:1
    at XMLHttpRequest.request.onreadystatechange (/home/altair/.nvm/versions/node/v9.6.1/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/httpprovider.js:128:1)
    at XMLHttpRequestEventTarget.dispatchEvent (/home/altair/.nvm/versions/node/v9.6.1/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:64:1)
    at XMLHttpRequest._setReadyState (/home/altair/.nvm/versions/node/v9.6.1/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:354:1)
    at XMLHttpRequest._onHttpResponseEnd (/home/altair/.nvm/versions/node/v9.6.1/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:509:1)
    at IncomingMessage.<anonymous> (/home/altair/.nvm/versions/node/v9.6.1/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:469:1)
    at IncomingMessage.emit (events.js:132:15)
    at endReadableNT (_stream_readable.js:1101:12)
    at process._tickCallback (internal/process/next_tick.js:152:19)

I can find plenty of issues and SE questions for "Error encountered, bailing. Network state unknown. Review successful transactions manually." But the line after that is always different than mine. I can't seem to find any google results for "Attempting to run transaction which calls a contract function, but recipient address" is not a contract address

The message makes sense to me, but how could that not be a contract address?

ETA: I also upgraded from truffle 4.0.5 to truffle 4.1.0, which is probably what caused the problem.

  • If your problem is only appear when you switch from truffle develop and ganache, maybe it is not problem of your code. Did you try to clean and migrate again? – Mavlarn Mar 2 '18 at 3:52
  • 2
    Did you try to clean the builddirectory and then rerun truffle migrate? – ivicaa Mar 2 '18 at 4:34
  • If by "clean" you mean delete the contents of the build directory, that worked! If you write that up as an answer, I'll accept it. But I have follow up questions; How could I have figured that out on my own? Is there a command for that? How did my problem happen in the first place? – Alex Altair Mar 2 '18 at 5:03
39

i´ve just used migrate --reset (without deleting /build) , and worked

  • 2
    This worked for me too. It appears to be necessary after upgrading to a new version of Node/NPM, which necessitates a new install of node modules like Truffle. So Truffle projects created when you were running an older version of Node/NPM need to be 'cleaned out'. – Robert Oschler Mar 31 '18 at 18:00
  • 3
    Also when you quit and reopen Ganache – Paul Berg May 18 '18 at 10:12
31

As provided in comments by Mavlarn and ivicaa above, the answer is to delete the .json files under build/contracts/. Then the next run of truffle migrate no longer fails.

3

One thing that isn't being stated is that the root-cause of the error message:

"Error: Attempting to run transaction which calls a contract function, but recipient address 0x8f0483125fcb9aaaefa9209d8e9d7b9c8b9fb90f is not a contract address"

The address in the contract JSON file does not match the newly migrated contract address. This can be confirmed by looking at the migration output in the CLI. It should tell you what the address of the contract is, you can then search the JSON file to make sure the address is there.

When you do migrate --reset it simply deletes the JSON file and makes a fresh one with the correct address...

  • The kind of answer I like, It is not only to provide a trick to solve the problem but also to understand the root cause ! thanks :) – Adelin Dec 17 '18 at 12:24
1

truffle migrate --network ganache --reset

the .json in the build directory get reset. By Default migrate (alias deploy) will only migrate changed components

0

This can also happen after you, intentionally or accidentally, call selfdestruct(address) on a contract.

0

restart the ganache, then on the terminal, migrate with --reset. So if your file is still 'truffle', type "truffle migrate --reset" Should work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.