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.

Filter by
Sorted by
Tagged with
0
votes
0answers
23 views

Polymorphism in Solidity

I understand that Solidity supports contract polymorphism, but what pattern would one use to create abstract data types for use in derived contracts? Motivating example: Say I have an abstract Storage ...
0
votes
1answer
14 views

Read and write private variable from child contract

I have a contract MyContract is ERC721. MyContract needs to concatenate a string with an existing token URI using this function: string(abi.encodePacked(_tokenURIs[_tokenId], _URI)); Problem is all ...
4
votes
1answer
127 views

Underhanded Solidity: Exploiting multiple inheritance

In an article by Steve Marx (on Medium.com), the author argues against using inheritance in solidity not only because of harder readability of a Smart Contract, but also because it can be exploited in ...
1
vote
1answer
24 views

Multiple inheritance name collisions

I am trying to understand how multiple inheritance in Solidity works with this snippet of code. where contract C inherits from A,B with each having function foo. pragma solidity ^0.6.0; contract A {...
0
votes
2answers
148 views

Trying to reference function from parent contract - Member “xxx” not found or not visible after argument-dependent lookup in address

I am trying to make a parent contract which deploys a child-contract for each unique caller (which does not inherit from parent contract, but calls one of the parent's functions). I have looked up ...
0
votes
1answer
44 views

Can a contract be inherited?

Just a random thought and a question. Can a smart contract written in solidity be inherited and if so, How?
1
vote
1answer
153 views

Value of msg.sender in call to inherited external function

I found this in the official solidity docs. The values of all members of msg, including msg.sender and msg.value can change for every external function call. This includes calls to library ...
0
votes
2answers
62 views

How to disable a function from a parent contract?

Say I have this contract: contract Foo { uint256 public foo; function setFoo(uint256 _foo) public { foo = _foo; } function setFooToZero() public { foo = 0; } } ...
0
votes
1answer
32 views

Cannot call functions from another deployed contract that inherits yet another contract

I am just trying this using Remix editor. I am able to call functions from another deployed contract(plain as simple) but when that another deployed contract inherits yet another contract, Now the ...
0
votes
0answers
24 views

Trustless contract upgrades using inheritance

I've been struggling to find a solution to the problem of upgradeability that maximizes trustlessness while also putting minimal burden on users. I really wanted to use signed messages to validate ...
0
votes
1answer
42 views

openzeppelin mint sequence

// openzeppelin v5 contract ERC721Full is ERC721, ERC721Enumerable, ERC721Metadata { constructor (string memory name, string memory symbol) public ERC721Metadata(name, symbol) { // solhint-...
0
votes
1answer
50 views

Multiple Inheritance at particular contract address

I'm attempting to have 4 different contracts sharing the same data fields. The reasoning behind having 4 instead of 1, is that the different functionality can be broken down so that it is cleaner, ...
0
votes
1answer
22 views

linking the CoreContract and the ERC20 token contract

What is the standard way of making the link between our CoreContract and the ERC20Token contract used by the Core Contract? Are people used to use inheritance like: MyCoreContract is MyERC20Contract { ...
0
votes
1answer
11 views

How to restrict call to inherited public function

I'm using OpenZeppelin library for my project and I need to override some functions for business logic. But my concern is with given example, // contract from library contract A { function ...
1
vote
2answers
151 views

How can I check if a specific contract's address inherits from a interface or contract?

I have a special contract with few extra functions. In the transfer wei function I want to send it to the special method or if receiver doesn't have it (because is a wallet or doesn't inherit from my ...
0
votes
1answer
37 views

Import and polymorphism is one contract or more?

If I have this contract: contract HelloWorld{ ... } and this one import "./HelloWorld.sol"; contract HelloUniverse is HelloWorld{ ... } and I deploy it, will it create 2 different contract and 2 ...
0
votes
1answer
100 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
57 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
69 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
95 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. ...
1
vote
1answer
128 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
102 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 ...
5
votes
1answer
131 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
55 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
30 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
33 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
65 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
75 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
78 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 ...
2
votes
2answers
201 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
20 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
61 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
132 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
46 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
255 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 ...
0
votes
1answer
229 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
251 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 { ...
4
votes
1answer
201 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
64 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
103 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
1k views

Gas estimation failed in Remix

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 compiler message is so ...
1
vote
1answer
77 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
85 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
39 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
55 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
1answer
231 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
1answer
251 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
665 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
615 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 { ...
5
votes
1answer
1k 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/...