The first time i tried the pet shop tutorial of Truffle, it worked without problem.

The problem:
The second time today I don't get a metamask pop-up to confirm an adoption. It goes straight to "success". In Ganache I can see a contract call, but it says "value 0".

I checked:
Ganache server, port & metamask. All in order. I can even send ether from one account to the other through meta mask.

I also did migrate --reset.

I have no idea what the problem is. I get no console log errors.


enter image description here


enter image description here



App = {
  web3Provider: null,
  contracts: {},

  init: function() {
    // Load pets.
    $.getJSON('../pets.json', function(data) {
      var petsRow = $('#petsRow');
      var petTemplate = $('#petTemplate');

      for (i = 0; i < data.length; i ++) {
        petTemplate.find('img').attr('src', data[i].picture);
        petTemplate.find('.btn-adopt').attr('data-id', data[i].id);


    return App.initWeb3();

  initWeb3: function() {
    // Is there an injected web3 instance?
    if (typeof web3 !== 'undefined') {
      // App.web3Provider = web3.currentProvider;
      App.web3Provider = new Web3.providers.HttpProvider('http://localhost:7545');
    } else {
      // If no injected web3 instance is detected, fall back to Ganache
      App.web3Provider = new Web3.providers.HttpProvider('http://localhost:7545');
    web3 = new Web3(App.web3Provider);

    return App.initContract();

  initContract: function() {
    $.getJSON('Adoption.json', function(data) {
      // Get the necessary contract artifact file and instantiate it with truffle-contract
      var AdoptionArtifact = data;
      App.contracts.Adoption = TruffleContract(AdoptionArtifact);

      // Set the provider for our contract

      // Use our contract to retrieve and mark the adopted pets
      return App.markAdopted();
    return App.bindEvents();

  bindEvents: function() {
    $(document).on('click', '.btn-adopt', App.handleAdopt);

  markAdopted: function(adopters, account) {
    var adoptionInstance;

    App.contracts.Adoption.deployed().then(function(instance) {
      adoptionInstance = instance;

      return adoptionInstance.getAdopters.call();
    }).then(function(adopters) {
      for (i = 0; i < adopters.length; i++) {
        if (adopters[i] !== '0x0000000000000000000000000000000000000000') {
          $('.panel-pet').eq(i).find('button').text('Success').attr('disabled', true);
    }).catch(function(err) {

  handleAdopt: function(event) {

    var petId = parseInt($(event.target).data('id'));

    var adoptionInstance;
    web3.eth.getAccounts(function(error, accounts) {
      if (error) {

      var account = accounts[0];

      App.contracts.Adoption.deployed().then(function(instance) {
        adoptionInstance = instance;

        // Execute adopt as a transaction by sending account
        return adoptionInstance.adopt(petId, {from: account});
      }).then(function(result) {
        return App.markAdopted();
      }).catch(function(err) {

$(function() {
  $(window).load(function() {


1 Answer 1


I've had this bug for 3 days, and after trying many things I found out the method to restore your Metamask functionality without fail:

  1. First of all, make sure you don't have any other node than Ganache running in the background, no private node, no other Geth.
  2. Go to the directory of your truffle project and delete the build directory of that directory.
  3. Open a fresh Ganache instance and in your terminal truffle migrate --reset --compile-all in your truffle project directory.
  4. In your browser open Metamask, switch your network to the Main Ethereum Network and then switch back to your private network where your Ganache is running.
  5. Then just to be safe completely quit and restart the browser, open your Metamask with your password, check if you are still on your private network, and everything should be fixed!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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