Can I use inherited contract in artifacts.require() statement?

0 votes

Suppose I have 2 contracts A and B and I inherit B from A and add some code in contract B, when I use the artifacts.require() statement, should I include both the contracts or including only B will be enough?

Will the following code be fine to use A and B?

var B = artifacts.require("B");


module.exports = function(deployer) {
    deployer.deploy(B);
};
Jul 27, 2018 in Blockchain by slayer
• 29,050 points
28 views

1 answer to this question.

0 votes

Yes, this code will work just fine. When you inherit a contract, only one contract will be created during deployment. So when you inherit a contract then the child contract will have the contents of the parent contact. Look at this example and understanding how you can implement it:

pragma solidity ^0.4.18;


contract A {
  uint256 public balance;


  function() public payable {
    balance = msg.value;
  }
}


contract B is A {
  uint256 i;
  A a;


  function B(address _a) public {
    a = A(_a);
  }


  function receiveForParent() public payable {
    a.transfer(msg.value);
  }


  function getParentBalance() public constant returns (uint256) {
    return a.balance();
  }
}
answered Jul 27, 2018 by digger
• 27,620 points

Related Questions In Blockchain

+1 vote
2 answers

Can I include real world data in a smart contract? If so, how?

You cant access/embed real world data using ...READ MORE

answered Jul 17, 2018 in Blockchain by sapan
45 views
0 votes
1 answer
0 votes
1 answer

Can i use HTTP GET to call external service in Hyperledger Composer?

Right now, the Hyperledger Composer supports only ...READ MORE

answered Jul 16, 2018 in Blockchain by slayer
• 29,050 points
35 views
0 votes
1 answer
0 votes
1 answer

Invalid Batch or signature in Savtooth

This will solve your problem import org.apache.commons.codec.binary.Hex; Transaction txn ...READ MORE

answered Aug 1, 2018 in Blockchain by digger
• 27,620 points
55 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
105 views
0 votes
1 answer

How i can use nodejs to watch transactions in bitcoin network?

you can use  const Socket = require('blockchain.info/Socket'); const mySocket ...READ MORE

answered Jul 9, 2018 in Blockchain by digger
• 27,620 points
34 views
0 votes
1 answer

How can i copy block aspects in hyperledger fabric?

There are three ways you can do ...READ MORE

answered Jul 6, 2018 in Blockchain by digger
• 27,620 points
29 views