I'm developing an end-to-end test that triggers truffle migrate and then needs to make contract addresses available to functions in the test.

How can I make truffle migrate return deployed contract addresses? It would not be ideal to parse the stdout from truffle migrate.

2 Answers 2


you should be able to get the addresses from the jsonABI files ( the artifacts ) generated by truffle. Truffle saves each version in the json files in the networks property. Each version is represented with a number. However i couldn't tell how this number is computed and how you could make it match, so this answer is unfortunately incomplete.

Whilst another user with deeper knowledge about that comes with a complete answer that might be a bit helpful so you can start digging around that

  • You're right -- if the JSON file is called Contract.json, the value is available via .networks.{network_id}.address. Thanks very much!
    – Peteris
    Mar 30, 2018 at 16:21

You might want to try it like this.

contract('MyContract", function(accounts) {

  var myContract;

  beforeEach(function() {
    return MyContract.new()
    .then(function(instance) {
       myContract = instance;

  it('should be owned', function() { 

This way, each test will start with a newly initialised test contract and your tests won't interfere with deployed (migrated) contracts. In my opinion, this is preferable versus MyContract.deployed() which would give you the address you are looking for.

Hope it helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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