1

In Truffle's documentation, it says DeployedAddresses.sol is how Truffle identifies and stores the addresses of contracts published to the blockchain via truffle migrate.

How does this file work, and what does it look like? If I publish an Adoption contract, how does Truffle know that the word Adoption in truffle console refers to that contract?

2

Good qus. As far as I know. Truffle will store your contract address in build/contacts/[CONTRACT.json] file

Truffle will map contract address under network json object with index.

 "networks": {
    "1": {
      "events": {},
      "links": {},
      "address": "0x77685437e762aaa90d4b6924aa9445c1198013f1"
    }
  },
  "schemaVersion": "1.0.1",
  "updatedAt": "2018-02-16T10:49:18.298Z"
}

If you delete json file, It will create new json file with new contract id.

When you run migrate/console, truffle will refer your [CONTRACT.json] file with corresponding network and address.

| improve this answer | |
  • 1
    How is the network number generated? e.g. You've shown "1" above. But on my local machine network number is "1532795656486" - which seems random. – Mandar Vaze Jul 28 '18 at 17:22
1

Truffle requires you to define Migrations by creating a deployer for the Adoptions contract.

For example migrations/2_deploy_contracts.js

var Adoption = artifacts.require("Adoption");

module.exports = function(deployer) {
  deployer.deploy(Adoption);
};

Building the contract with truffle build also creates an JSON file build/contracts/Adoption.json which contains all required metadata.

DeployedAddresses.sol is created on runtime by truffle when you run tests.

See also: https://github.com/trufflesuite/truffle/issues/471#issuecomment-315166855

| improve this answer | |
  • I knew all this going into asking this question. None of this answered my question unfortunately. – AlwaysQuestioning Feb 17 '18 at 16:56
  • Maybe you need be more specific. ^^ You may also ask truffle support. E.g via Gitter truffleframework.com/support – digitaldonkey Feb 20 '18 at 14:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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