Truffle – How to Import a 3rd Party Contract ABI in Solidity and Truffle

dappsgo-ethereumsoliditytruffle

I'm using Truffle to compile my contracts. I'd like to create an instance of a contract compiled and deployed previously by someone else so that I can interact with it.

Can this be done without recompiling their entire contract? I assume I would just need the ABI, which I can grab from etherscan.

tl;dr how do I take an ABI from etherscan and then, in solidity, instantiate an instance of it at a particular deployed address?

Best Answer

as of Truffle v5.1.52, you can import ABI JSON files directly from Solidity if they are in your contracts/ folder.

import "./Uniswap.abi.json";

Under the hood, truffle uses https://github.com/gnidan/abi-to-sol