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,370 points
645 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
• 26,740 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 18, 2018 in Blockchain by sapan
1,216 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,370 points
586 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,472 views
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
• 26,740 points
1,039 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
1,947 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
• 26,740 points
1,310 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
• 26,740 points
809 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP