2

Here is my code:

$.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
    App.contracts.Adoption.setProvider(App.web3Provider);

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

my question is:

I am using web3, ganache. Adoption.json is generate from command truffle compile. Then I use truffle migrate, truffle deploy this contract to ganache network. But from the code above, I don't need to specific the contract address, WHY? How does web3 know the contract's address?

Another question is, when I want to switch to Ropsten network, why I need a specific contract address?

0

1 Answer 1

1

OK, so I finally figure out what's going on.

in this file Adoption.json, we can see this configuration:

"networks": {
  "5777": {
    "events": {},
    "links": {},
    "address": "0x353a356025b51e07891fb6d3df5d9a89cbd3093b"
  }
},

this configuration will be changed when I try to run truffle migrate, so truffle knows I want to deploy to local network and the address after deployed.

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