This is a very newbie question about deploying contracts with imported dependencies.

I'm using Chainlink's AggregatorV3Interface and SafeMath from openzeppelin.

import "@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";

I've noticed truffle compile spits out the ABI's for both AggregatorV3Interface and SafeMath along with Contract I wrote myself. Why does Truffle do that?

When I deploy my contract, are the imported dependency contracts deployed also?

Or does my Contract reference the AggregatorV3Interface already deployed to mainnet by Chainlink?

Likewise, does my contract just reference the SafeMath contract already deployed by OpenZeppelin? Or does Truffle deploy that too?

I noticed that on Remix, when using SafeMath or AggregatorV3Interface you use import with an absolute URL to Github. So, it was a little confusing as to why Truffle compiles the imported contracts too.

  • 1
    it depends on how you implement it, there are 2 types of libraries Embedded and linked. you can read more about it here. Most of us use embedded, which means the code of the library is included in your byte code when you compile the contract and will be deployed with. medium.com/coinmonks/…
    – Majd TL
    Commented Feb 20, 2021 at 13:46
  • 1
    if you using the latest version of solidity you dont need safe math anymore
    – Majd TL
    Commented Feb 20, 2021 at 13:47

1 Answer 1


Truffle compiles everything, including those imported. The imported SafeMath is included in your contract, and only your contract is distributed. It refers to the deployed contract by setting the deployed contract address as an argument of AggregatorV3Interface.

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.