6

I am working on a few projects using truffle, as you know truffle compiles and migrates contracts to various ethereum networks e.g. MyContract.sol produces MyContract.json which contains a reference to the address of that contract on that network along with the abi.

One of the problems we are having is how to share these generated build files between the team of devs that work on the project.

Has anyone had any experience with this problem and what's the best solution?

The main problems:

  • If we commit the build files into the source control, they contain elements which are specific to the users local machine e.g. sourcePath & absolutePath

  • If we dont commit them then we must either manually update the abi json files to point to the correct contract address

I feel like maybe we are miss understand what the correct process to use when using truffle between teams greater than a few people on a common project

All help appreciated

2
  • The abi from the contract.json file will probably be unrelated to the user's machine or any kind of network configuration it has. so sharing that alongside the deployed contract address should be sufficient to work between teams with web3 directly but not truffle. Commented Mar 30, 2018 at 10:38
  • Ye agreed, the problem is that truffle generated build files which also have machine specific data in. Some form of transformation may be needed.
    – Jimbob1987
    Commented Mar 31, 2018 at 14:44

1 Answer 1

4

I don't know if there is a real answer for that, but I use this solution: I change the migration file and I write the ABI and its address after the deploy

var fs = require('fs');
var MyContract = artifacts.require('./MyContract.sol');
var fileContent = require('../build/contracts/MyContract.json');

module.exports = function(deployer) {
  deployer.deploy(MyContract).then(() => {
    var contractConfiguration = {
        abi: fileContent.abi,
        address: MyContract.address
    };

    fs.writeFileSync('contractConfiguration/MyContract.json', JSON.stringify(contractConfiguration), { flag: 'w' });
  });
};

In my case I use it to have my contract information always updated for UI purpose. So the UI will read the information inside the contractConfiguration folder and will always have the updated address and ABI.

3
  • I like this idea but would need to expand the function so to keep the address for each network e.g. ropsten, rinkeby, mainet. I'll give it ago and see if it helps. Ideally it would be good if truffle output two files, one with the addresses and ABI and another with any user specific details like sourcePath & absolutePath, ideally specified to different folders via config.
    – Jimbob1987
    Commented Mar 31, 2018 at 14:48
  • Well, truffle doesn't do it by itself. So just expand the above script as you wish. You can use your configuration and load the output directories, support multiple networks and so on.
    – qbsp
    Commented Mar 31, 2018 at 16:06
  • There's truffle-artifactor that it appears that does something similar.
    – Ismael
    Commented Apr 1, 2018 at 4:34

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.