I have three smart contracts say a.sol, b.sol and c.sol... Out of these three, first two are independent smart contracts whereas c.sol uses the functions of a.sol and b.sol and thus c.sol requires to "import" the first two smart contracts. "Import" works locally but how to deploy all of them via remix/truffle on testnet such that c.sol can still access the functions of a.sol and b.sol?
Asked
Active
Viewed 3,012 times
2 Answers
2
Does your contract a and b supposed to be standalone contracts that will be used regardless of contract c? ie: user store data in contract a, which will be used by contract c
If so, then you can have contract a and b as variables of contract c like this
a.sol
contract A {
function doSomething() {
...
}
}
c.sol
contract C {
A a;
function setA(address addressOfContractA) {
a = A(address);
}
function makeADoSomething() {
a.doSomething();
}
}

Bhoomtawath Plinsut
- 1,337
- 1
- 16
- 31
0
If your project was created with Truffle, you can set up c.sol
in the following way:
import "./a.sol";
import "./b.sol";
contract c is a, b {
...
}
If this is the structure of your code, you will be able to deploy your Truffle project using truffle migrate
(provided your migrations are set up correctly).

Shane Fontaine
- 2,431
- 3
- 13
- 23
-
This answer only works for as long as the total size does not exceed block size limit. To avoid hitting block size limit, @bhoomtawath-plinsut 's answer works. – Ronak Doshi Jul 21 '21 at 13:04