I have written a few smart contracts and I have deployed them locally. I have written an js file, app.js, that uses these smart contracts and 'does stuff', and it all works wonderfully locally, with Ganache and Metamask.
Next, my coworker deployed these contracts to the Ropsten network.
I then assumed I would simply have to switch the network in Metamask, restart my app, an the app.js file would then work with the contracts I have deployed on Ropsten. Unfortunately, this is not the case.
Error: Contract has not been deployed to detected network (network/artifact mismatch) is what the console of the browser shows.
I am accessing the contracts this way:
$.getJSON('SomeCoin.json', function (data) {
var CoinArtifact = data;
App.contracts.Coin = TruffleContract(CoinArtifact);
App.contracts.Coin.setProvider(App.web3Provider);
});
Is there anything wrong with this code?
Or is is a problem that I didn't deploy the contracts myself, since I my Coin.json file does not contain a 'networks' entry for Ropsten?
How do I access the contracts correctly without having to re-deploy them myself?
You just need to make an instance of the contract with the address of the contract that your coworker deployed App.contracts.Coin.at(contract_address).then((instance) => { your logic }