Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [inheritance]

Inheritance in this stackexchange refers to parent child contract relationship where the child contract is considered to be a type of the parent contract and hence implement the parent contract functions. This is same like inheritance in OOP in generic programming except for the fact that in this community its used in a contract oriented programming domain.

0
votes
1answer
15 views

Interface overriding

I have two contracts. One of them inherits another. Inside the parent contract I have the interface interface Token { function transfer(address to, uint256 value) external returns (bool); } I ...
0
votes
1answer
25 views

Who is “from” in case of inheritance in solidity?

I have the following code: // Test.sol pragma solidity ^0.5.2; import "./TestBase.sol"; contract Test is TestBase{ string[] name ; constructor() public payable { name.push("sheep"); ...
0
votes
1answer
15 views

Import a contract hosted on a testnet from it's address

I have a smart contract that imports another, and I'm wondering how to deploy them to a testnet. Right now, one contract imports the other locally; import "./firstContract.sol" contract ...
1
vote
2answers
67 views

Inheritence in Solidity

I want to implement my contract in much better way and want to use the inheritence. I wrote the code and i face one problem that i want to access the mapping variable of Contract A in the Contract B. ...
0
votes
1answer
26 views

question regarding linearization of inheritance

If I have the following inheritance: pragma solidity ^0.4.24; interface A { function foo(uint256 _x) external pure returns(uint256); } contract B1 is A { function foo(uint256 _x) public ...
1
vote
1answer
34 views

Solidity inheritance can't read parent's value correctly

I found a strange error in my contract and tried to resolve it, but it's so unreasonable. contract parentContract { uint num = 1; function setNum(uint _n) public returns(uint) { num ...
3
votes
1answer
17 views

In Solidity, how does the slot assignation work for storage variables when there's inheritance?

In a simple solidity contract, without inheritance, storage variables get assigned sequentially starting from slot 0. But in case of inheritance, the inherited variables appear before or afterwards?
1
vote
1answer
38 views

Solidity Syntax question

What happens if a function is being passed before { into another function? Like DetailedERC20(_name, _symbol, TOKEN_DECIMALS) in this example: function MyToken(Registry _registry, string _name, ...
0
votes
1answer
21 views

Why is it that my first original contract containing the setters and gettters are not showing up when I hit deploy?

pragma solidity ^0.4.24; contract Bank{ uint private value; constructor(uint amount) public{ value = amount; } function deposit(uint amount) public{ value += amount; ...
1
vote
2answers
19 views

Is it possible to have an optional property or method in an interface?

I currently can't deploy any contract which doesn't adhere 100% to the specified interface(s). Is there a way to mark some properties or methods as optional and, if not, is this a planned feature?
0
votes
1answer
37 views

Contract Using An Interface Is Not Compiling

I am learning Solidity and I am using Remix to experiment and enhance my learning. I am currently trying to create a simple contract that uses an Interface. pragma solidity ^0.4.19; contract ...
0
votes
1answer
52 views

on a way of copying code that involves “super” keyword for supporting inheritance

I wonder the exact mechanism of copying code that involves "super" keyword for supporting inheritance in Solidity. Below is an example code that elaborates my question. contract C { function ...
1
vote
1answer
26 views

Contract Inheritence

Let's suppose we created two contracts: Contract A and Contract B. Contract A is inherit by Zeppelin's standard token ERC20 where as Contract B is inherit by contract A. Will contract B be ...
1
vote
2answers
41 views

Is library use inherited?

When a base class uses a library, do derived classes also use the same library? For example: contract A { using SafeMath for uint256; ... } contract B is A { //is code here using ...
1
vote
1answer
13 views

Do over-ridden functions affect dependent parent functions?

Imagine a ParentContract with functions a() and b(), where b() calls a() contract ParentContract{ function a() {...} function b() { a() } } Now, I have a Child contract that ...
0
votes
1answer
34 views

Diamond inheritence problem [duplicate]

interface I { } contract A is I { } contract B is A { } contract C is A { } contract D is B, C { } What would happen in this situation? How is this kind of diamond inheritance resolved in ...
0
votes
1answer
34 views

Should Solidity interfaces always specify return types?

I've seen interfaces in which the function definitions specify a return type, ie: (from openZepplin's IERC721.sol) function balanceOf(address owner) public view returns (uint256 balance); and ...
2
votes
1answer
24 views

Solidity inheritance

Do contracts have to implement the methods they inherit from interfaces, likewise, do they have to implement methods from abstract contracts?
7
votes
3answers
180 views

Composition Over Inheritance - Gas Efficiency

In OOP languages, composition over inheritance is a well-known best practice. Solidity is an OOP language too but there is also the gas efficiency issue. Question is, in Solidity, how do composition ...
-1
votes
1answer
88 views

How can contracts share a whitelist?

I have a token, let's call it TokenA, that inherits from Open Zeppelin Whitelist.sol. TokenB and TokenC both inherit from TokenA and they each have some additional functions. I want all three Tokens ...
2
votes
1answer
88 views

msg.sender is Null in Base Constructor

When I create the child class object and try to access value of msg.sender from parent class it always comes 0. Can anyone please help me in this? Below is the sample code: contract Test1 is Test2 { ...
2
votes
1answer
62 views

Call parent class modifier possible?

I want to do the following: contract Base { bool public active; modifier canSetMetadata() { require(active == false); _; } } contract BaseWithMetadataControl is Base { ...
2
votes
1answer
43 views

What order is code copied for inheritance?

The Solidity documentation says it supports inheritance by copying code, but is unclear about where the code is copied to. I am building a genesis block for a Quorum-based chain, starting from the ...
2
votes
1answer
62 views

A Solidity Linearization Puzzle

I was playing in remix just to concretize my understanding of Solidity linearization, and got a result I didn't expect and can't rationalize. Why does AC_BA.go() return 3? (Please scroll to the ...
2
votes
2answers
399 views

Gas Estimation Failed in Remix

Found my own problem. Can't really use the transfer function as it is written. It assumes the owner uses it. So made a new function for the "minting" function for the faucet to use. Not sure why the ...
1
vote
1answer
38 views

If I import Ownable and MyClass inherits from it, do I need to migrate the Ownable at all?

I'm a bit confused about migrations. I've just been told to use 1_migration.js file per contract, except maybe in the case of imports. I am going to change these migrations back to one per migration, ...
1
vote
1answer
41 views

Multiple inherintance: solidity docs example explanation

I found this example on the docs: pragma solidity ^0.4.22; contract owned { constructor() { owner = msg.sender; } address owner; } // Use `is` to derive from another contract. Derived // ...
1
vote
0answers
19 views

Deploy many instances of configured base contracts or track multiple agreements on one contract?

I am playing around with solidity, truffle, and node and i was wondering if I am trying to make a game that allows players to browse a list of games and join the ones they want. Would it be best to ...
0
votes
1answer
45 views

Solidity - Calling parent payable not possible?

I'm trying to inherit and override a parent's payable function (and adding some modifier and logic) but so far seem unable to do so. My first intuitive try was something like this: contract foo { ...
0
votes
0answers
31 views

Getter function calls not working from inside deployed contract and inherited getter function calls?

I have deployed the following code in a remix IDE, but when I try to call functions such as Name, Symbol, Accounts, BalanceOf, OwnerOf, TotalSupply etc... I am given the following ERROR error: ...
0
votes
1answer
108 views

Solidity: Contract Inheritance and upgrade [duplicate]

This might have been answered somewhere else, but I couldn't find a 100% satisfying answer. I have the following contracts: Contract One {} Contract Two is One{} Contract Three is Two {} All the ...
0
votes
0answers
79 views

Re-deployment(Upgradeable Contracts) and Inheritance Design Pattern

I am trying to design architecture along with implementation of smart contracts. I have two main problems actually, they both can be found conceptual. To make it more understandable, I will not go ...
0
votes
1answer
155 views

Solidity smart contract inherited function output failed

I'm trying to inherit a function from the parent contract into child contract and its working fine in remix JavaScript VM. I did the following steps: Deployed the parent contract in remix JavaScript ...
0
votes
1answer
242 views

Solidity more than one if statements evaluation failed

I'm trying to evaluate more than one if statements but after a certain number of if statements remix throws an error: error: Failed to decode output: TypeError: Cannot read property 'length' of ...
1
vote
2answers
273 views

Contract inheritance

I really hope this is not a dumb question. I am trying to call the constructors of the inherited contracts in a structure like this: contract A{ uint a; constructor (uint _a) public { ...
2
votes
1answer
557 views

Providing base contracts' constructor arguments

I'm a bit puzzled about multiple inheritance and providing arguments for different constructors. Solidity documentation has long explanations about this (http://solidity.readthedocs.io/en/develop/...
1
vote
1answer
115 views

Help with inheritance and Truffle tests

I have two contracts that both inherit from OpenZeppelin's Whitelist. After deploying both contracts, I use an instance of the first contract to add a "trusted" address to the whitelist. Since both ...
2
votes
1answer
57 views

possible to implement abstract base function with property in derived contract?

Is there any way to have an abstract base contract with an abstract function which gets implemented in a derived contract by a property (and not a function)? e.g. the following attempts failed: ...
3
votes
1answer
354 views

Multiple inheritance and order of chaining of multiple base constructors [duplicate]

I am trying to understand the order of invocation of base class constructors in the presence of multiple inheritance. As far as I can tell, the order appears under-specified in the Solidity ...
9
votes
2answers
670 views

Solidity and multiple inheritance

I'm attempting to understand how solidity resolves multiple inheritance. As explained in the docs, Solidity uses C3 linearization. The relation between my classes is displayed on the image below: I ...
0
votes
0answers
184 views

Deploying OpenZepplin Crowdsale solidity contract

I have a constract which inherits "TimedCrowdsale, MintedCrowdsale" from OpenZepplin. I can successfully deploy this contract onto my local Ganache, but I receive the following error when I attempt to ...
1
vote
1answer
175 views

Does “this” keyword changes msg.sender on inherited methods invocations?

Take this scenario: Contract A { function whoIsSender() public returns (address){ return (msg.sender); } } Contract B is A { function withThis() public returns (address){ return ...
3
votes
1answer
926 views

Difference between library-using-for and contract-is

I am using two different ways to get the same result and wondering what the real difference is. Both options (library, using, for and contract, is)deliver just an extended code from a file. Method no ...
0
votes
1answer
131 views

Solidity: Not able to call super function in trufffle test may be because of modifier defined

When I am testing my class with truffle test ./test/testinheritance.js I am getting an error. "Error: VM Exception while processing transaction: revert". It seems to be error related to the ...
0
votes
1answer
180 views

C++ (or generally OOP) inheritance in Solidity

In Solidity, when one does inheritance, the two contracts share state. Some pseudocode, contract A { uint myVar = 1 setVar() {myVar = 3} } contract B is A { myVar = 2 } If I deploy A, A.myVar = 1. ...
1
vote
2answers
217 views

Trying to reference mortal.sol in standard ethereum library

I am trying to reference mortal.sol in the standard ethereum library. I have deployed mortal.sol under my main test account. However I get the error source not found. What I tried was: import "https:/...
1
vote
2answers
146 views

Solidity, is it possible to deploy a smart contract that prevents other smart contracts from inheriting from it?

I am new to Ethereum and I was wondering if it is possible to deploy a smart contract such that other smart contracts are not able to inherit from it. In other words once a smart contract is deployed ...
4
votes
3answers
3k views

Interface Function

I understand that the following function is used to link the ico contract to the token. Appreciate if someone could explain how to use the function, and exactly how it works. Thank you. /** * @title ...
1
vote
1answer
612 views

TypeError: Definition of base has to precede definition of derived contract

In my DAPP I have 3 contracts where I want to do something like this. pragma solidity ^0.4.13; import "./z2.sol"; contract z1 { uint example; function z1 (){ example = 33;} function ...
0
votes
1answer
125 views

Getting ABI interface using solc offline

Suppose I have an inheritance contract (xyz.sol) with three contracts A, B and C such that C is B, I am trying to compile using solc offline in node console. Upon compiling, I have three separate ...