I have seen Dapps made up of many contracts but a single ABI that I think needs to be referenced for example in a web3j Javascript file. Is it normal to concatenate the ABIs from separate contracts into a single ABI file? If so, how can this be done?


An ABI is a JSON structure (an array of objects). You can create another json file containing all your ABIs.

For instance

    Contract1: [...ABI Contract1...],
    Contract2: [...ABI Contract1...],
| improve this answer | |
  • Is there a switch which does this in the solidity compiler? If not, is the files which contains all other ABIs simply a concatenation of the individual contract ABIs or is some information stripped out? Is the name of the file important? Should it be named after any particular contract or is it completely arbitrary? – Jeff Apr 11 '18 at 20:17
  • If you're loading the abi yourself in your code, you can choose any filename you want. For better readability, you should use corresponding contract names.. About solc: as far as I know the abi files are created one per contract. If you want everything in one single file, you will have to concat this yourself like sketched in the answer. – ivicaa Apr 11 '18 at 20:34
  • Moreover, I would recommend to look into the truffle frame. It's a huge help with stuff like this. – ivicaa Apr 11 '18 at 20:35
  • I am using Truffle: the compile creates multiple ABIs even if I try shoving multiple contracts into a single dot sol file. A useful switch would indeed be a compile that creates a single ABI. Am I right in assuming that a single ABI is needed or at least useful, since I believe web3j needs an ABI and I am not sure how to provide multiple ABIs if indeed that can even be done. – Jeff Apr 11 '18 at 20:51
  • You can actually let it as is. One file per ABI. That‘s not a problem at all. In your DAPP, you can use truffle-contract to load it. Check their documentation. – ivicaa Apr 11 '18 at 21:30

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.