Trufffle / Ganache Migration not Updating Contract Methods in Broweser

Hey, I’ve changed some function names in my smart contract while building the kitty factor dapp, my index.js trying to call the instance function as bellow -
instance.methods.createMembershipGen0(dnaStr).send();

This function createMembershipGen0 used to be called something else in my contract, now when I migrate all my files, even using --reset, the contracts that get deployed still somehow have the old function names only in the browser.

I confirm this by checking the console.log of the instance in my browser console. When I scroll down to the available methods I only see the old function names being available. So when click on the html button to try to create the asset, I get an error
“TypeError: instance.methods.createMembershipGen0 is not a function”

I can however, call this function directly in my truffle console, so it seems the contracts are migrating properly there. Somehow when I try calling it in the browser, it is only seeing the old data, I am trying this with Brave, chrome, firefox, as well as loading the live server both through vscodes live server as well as trying it the python way - I am getting the same result of seeing the old contract methods every which way.

I am remembering to update the contractAddress variable in my index.js file whenever I migrate.

I’ve tried re-installing truffle, launching new workspaces in Ganache as well.
edit - I downloaded my repo on a different machine and tried with a fresh setup there and getting the same result. I also tried now copying the latest version of my contract file to a new file with a new contract name and migrating it separately.

any idea what could be the issue?

var web3 = new Web3(Web3.givenProvider);
var instance;
var user;
var dnaStr = "457896541299";
var contractAddress = '0xd3b43A98c7cEd48eB13b7D9E044049e90F37a00c';
var contractOwner;



// when the page loads..
$(document).ready(function () {
    window.ethereum.enable().then(function (accounts) {

        instance = new web3.eth.Contract(abi, contractAddress, { from: accounts[0] });
        
        instance.methods.owner().call().then(test => {
            contractOwner = test;
        });

        user = accounts[0];
        // user = ethereum.selectedAddress;

        console.log("Stage One Cleared...");
        console.log(instance);
        // displayNfts();

        instance.events.Birth().on('data', function (event) {
            console.log(event);
            let owner = event.returnValues.owner;
            let membershipId = event.returnValues.membershipId;
            let mumId = event.returnValues.mumId;
            let dadId = event.returnValues.dadId;
            let genes = event.returnValues.genes;

            $("#membershipCreation").css("display", "block");
            $("#membershipCreation").text("owner:" + owner
                + " membershipId:" + membershipId
                + " mumId:" + mumId 
                + " dadId:" + dadId 
                + " genes:" + genes 
            )
        }) 

    })
})

async function createMembership() {
    var dnaStr = getDna();
    let res;
    try {
      res = instance.methods.createMembershipGen0(dnaStr).send();
    } catch (err) {
        console.log(err);
    }
}
1 Like

Hey @spaceleafio, hope you are well.

What about the abi? did you also update it?

Carlos Z

@thecil - thanks so much that is exactly what I was missing. I managed to get this far into the project without ever updating that file once since inception somehow, I guess I need to do a little more reading on the abi to have more understanding.

My project is working correctly now after updating abi.js with the new json files of my contract that appears in the build folder, thanks again.

1 Like