Search code examples
ethereumtruffle

How does truffle know which contract I'm referring to?


After running truffle migrate, I'm able to run (in a console) contract = await MyContractName.deployed(). I haven't tested on mainnet, but I'm able to run this same code on testnets and truffle knows which contract I'm referring to.

How does it know? There must be other contracts named the same as mine, can someone elaborate how Truffle knows which contract I'm referring to?


Solution

  • Your contract is not defined by the name you provided. It is defined by address of the smart contract which will be stored in the build/contracts/{contract-name}.json by truffle after deploying(migrating).The truffle refers this file for the address when you are querying in your console

    for more information, check this out http://trufflesuite.com/docs/truffle/getting-started/interacting-with-your-contracts.html