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
2 answers
26 views

Why do we need interfaces in solidity?

Let's say contractA has a special function. And made an interface that contains the special function without implementation. To use the function in the other contractB, we can use the interface but ...
0 votes
1 answer
22 views

How Linearization is possible in first block of code but not in the second block of code?

First block of code // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/ERC721.sol"; ...
1 vote
0 answers
20 views

`transferOwnership` is not a function

I am following the challenges from the speedrunEthereum and right now I am stuck on challenge 2 and not getting why the transferOwnership is not a function since I am also inheriting the Ownable from ...
1 vote
1 answer
20 views

modifiers overriding simple question with inheritance

just wanting to be sure of this. If I have a contract that inherits from another contract and overrides a function of that contract with NonReentrant modifier on it. Will that NonReentrant modifier ...
  • 11
2 votes
1 answer
18 views

What is the practical purpose of interface contracts?

I wanted to make sure I understood the purpose of interface contracts. I understand that they are contracts with unimplemented functions, but wanted to make sure I understood all the ways programmers ...
  • 93
0 votes
1 answer
24 views

Multiple inheritance in Solidity

I have a contract C that is Ownable so I can use ownerOnly on its admin functions. Recently, I added some functionality that I'm going to start using in other projects. I refactored the functionality ...
1 vote
1 answer
31 views

Does the compiler ignore internal functions that are never called?

On inheriting a contract that contains some internal functions that are never used in the child contract. eg. contract Parent { function _someInternalFunction() internal{ } } contract Child ...
3 votes
1 answer
122 views

How does Solidity implement C3 linearization?

The solidity documentation does not offer a lot of insights into their implementation of the C3 linearization to resolve methods in a multiple inheritance scenario. There it states that You have to ...
  • 219
0 votes
1 answer
23 views

Create contract with contract

I want to create a contract that can create contract itself I find something like this pragma solidity ^0.5.0; contract DaughterContract { string public name; uint public age; constructor( ...
0 votes
0 answers
20 views

Solidity cast address to a different class

What's the expected behavior if I cast an address A to a wrong class CA? For example, BAYC (https://etherscan.io/address/0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d#code) is an IERC721Enumerable. What ...
0 votes
0 answers
25 views

Why did super keep choosing one parent method?

So, I'm experimenting meta transaction contract. I'm using Openzeppelin's MinimalForwarder. The contract that become the forwardee is this contract: // SPDX-License-Identifier: GPL-3.0 // Storage.sol ...
1 vote
0 answers
111 views

Interface overriding giving error. Overriding public state variable return types differ

I am trying to import interface in it's contract and overriding function. But 1 mapping is giving error. Error: Overriding public state variable return types differ. Interface: interface ...
1 vote
2 answers
129 views

What is the preferred Inheritance for ERC20 token and why?

I tried to deploy both ERC20 contracts with burn functionality over the remix and both seems to work fine, I am confused if one way should be preferred over the other. Since, openzeppelin contract ...
0 votes
1 answer
71 views

Solidity: calling a imported contract's function without inheritance, Calling a imported contract interface and passing its implemented contract add

This is the error I'm getting, I'm trying to implement ERC20's _transfer function without inheritance, calling its Interface IERC20 and passing the ERC20 deployed contracts address and then calling ...
0 votes
1 answer
117 views

How to import Openzep ERC20: Identifier not found

Can I get someone's perspective on why I'm unable to find the ERC20 contract I've npm install @openzeppelin/contracts. After import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; I get a ...
  • 107
0 votes
0 answers
35 views

Solidity call function priority in inheretence

going through openzeppelin implementation of ERC721, tracking how the flow works. I stumbled on one strange behaviour and asking somebody to explain if possible. I am calling _mint function of Base ...
  • 11
0 votes
0 answers
11 views

Multiple Inheritance Issue: TypeError: Linearization of inheritance graph impossible [duplicate]

what could be the quick solution for this? I am trying to rearranging contracts and trying re ordering of smart contracts
1 vote
1 answer
191 views

Is there a way to override or skip calling a parent's constructor?

Is there a way to override or skip calling a parent's constructor? For example, I have the following: contract Ape { constructor() { // Initialise some stuff in Ape constructor } } contract ...
  • 327
0 votes
2 answers
27 views

How can I inherit contact on github?

there is a contract on github. I need to inherit it/ So how can I do it? Using import isn't available how I unnderstand.. https://github.com/Uniswap/v2-periphery/blob/master/contracts/interfaces/...
  • 89
1 vote
1 answer
65 views

In Contract D, why does calling function bar first call C, then B, and finally A?

// SPDX-License-Identifier: MIT pragma solidity ^0.8.10; /* Inheritance tree A / \ B C \ / D */ contract A { // This is called an event. You can emit events from your function // ...
1 vote
2 answers
268 views

Why does OpenZeppelin import interfaces to its own contracts?

I've noticed that all OpenZeppelin's token contracts import their interfaces into them. Why does OpenZeppelin import and inherit its own contract interface to the contract? Does importing a contract'...
  • 392
0 votes
0 answers
69 views

How to instantiate functions of other smart contracts to write and read data from the same contract on Solidity?

I'm trying to understand inheritance, interfaces and the call of functions from other smart contracts in Solidity. So I did this example; there is a MyInterface interface in which is declare a struct ...
  • 1
0 votes
1 answer
42 views

Array type of an array or contracts?

If I have a contract named LockedOffer, and in another contract that inherits from LockedOffer I declare an array LockedOffer[] public offers, what type is the array? I'm assuming it's an address ...
0 votes
1 answer
45 views

Is it acceptable to inherit data types from two different contracts (logic and storage?)

I am using a data separation pattern, keeping my data in a contract and the business logic in a separate contract that calls the storage one to add/update/delete records. In order to send the Data ...
0 votes
1 answer
152 views

When should I use inheritance or new operator?

I have some trouble to understand the difference between inherit and an instance created from a contract using new operator. I did understand that I can access an external function from contractA to ...
  • 15
0 votes
1 answer
125 views

How to call a base function from a derived object and not alter the variable assignments in the Base contract and other Derived objects

Our base function: pragma solidity ^0.8.0; import "hardhat/console.sol"; import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; contract Token is ERC20{ address private ...
1 vote
1 answer
1k views

How can multiple contracts exist in a single file?

Consider the following file contract A { } contract B{ } contract C{ } Is a file like that valid? Can a .sol file contain multiple contracts as above? If yes, which contract would the deploy address ...
  • 357
0 votes
1 answer
158 views

Are the order of contract names inside override important?

Are the order of contract names inside override important? For example, in contract Z, is function foo() override(X, Y) {... } same as function foo() override(Y, X) {... }? Or do they convey a ...
0 votes
0 answers
69 views

What is the right way to put import statement when trying to import contract or library files to current contract which is inheriting other contract?

I'm confused where to put import statement when trying to import contract files or library files and use it at current contract which is inheriting other contract. It was the long words, so here is ...
  • 191
0 votes
1 answer
108 views

Structs on inheritance

Can an inherited contract have access to his parent's struct variables? I'm trying the code from below but I can't access the struct defined on ContractA, so I don't know if it's not possible at all ...
  • 379
2 votes
1 answer
832 views

Is there any way to access a private variable in a parent from the child inheriting from it?

Let's say I'm building an ERC1155 contract, and I incorporate OpenZeppelin's ERC1155Supply. That, at least as of the current master, has the following: mapping(uint256 => uint256) private ...
0 votes
1 answer
390 views

Solidity: How to inherit a struct to create a new struct?

Is there a way to inherit a previously defined struct while defining a new struct (similar to the classes in C++)? I'm looking for something like this: struct Person { bytes32 name; uint256 ...
0 votes
0 answers
20 views

Common mapping for multiple children classes

How to have common mapping for objects of multiple children classes of the same base class? I am trying to make a marketplace sort of system using solidity. I have a base contract Store that will ...
0 votes
1 answer
61 views

How to setup solidity inheritance?

Im trying to create a flow where contract A holds an address and all calls from contract B and contract C need to pass a simple msg.sender == systemAddress check. All the while I need to be able to ...
  • 11
2 votes
1 answer
572 views

"Super" keyword with same function in multiple inheritance contracts?

I'm having some doubts when extending the same contract function in different classes, with super keyword. Would function _preValidate (in Contract B) check both conditions of contracts A1 & A2, ...
  • 745
0 votes
1 answer
137 views

Call 2 functions from 2 separate contracts in one transaction

Pretty standard question here I think but as a newbie I am having trouble getting my head around this in a clear way. I am experimenting with a simple forward auction using a couple of contracts and a ...
0 votes
1 answer
55 views

Minting parent tokens from child contract

Is it possible to mint ERC20 tokens that are created in a parent contract, from a child contract? If so how is it implemented? Thank you in advance!
  • 87
1 vote
1 answer
225 views

Shadowing Inherited State Variables

I was editing and trying out the code from https://solidity-by-example.org/shadowing-inherited-state-variables and got the following output. pragma solidity >=0.8.0 <0.9.0; //SPDX-License-...
2 votes
0 answers
416 views

Contract location and inheritance with private variables

When inheriting from a contract, all functions of the parent are accessible in the deployed child's contract's namespace (contract address) Yet when a parent's function is called they read/write from ...
  • 353
0 votes
1 answer
151 views

Adding additional mutable variables in an ERC-20 Token Smart Contract (Extending ERC-20)

I am having a question considering inheritance/extending of ERC-20 Token Smart Contracts. I would like to add additional mutable variables to an ERC-20 token before the deployment on the Ethereum ...
1 vote
1 answer
1k views

How can I change the logic of _safeMint method in a child contract of ER721?

I was fiddling with OpenZeppelin ERC721 contract and created my own contract inheriting from the ERC721.sol. I tried to change the _safeMint method, so I copied it from the parent contract and this ...
0 votes
1 answer
924 views

Inheritance, Imports and Remix

This is the LSP3Account contract: https://github.com/lukso-network/standards-implementations/blob/master/contracts/Accounts/LSP3Account.sol I want to create a contract on Remix that inherits from it. ...
2 votes
1 answer
195 views

How does a Proxy contract communicate with the underlying Implementation?

When a user interacts with a proxy contract, they send a transaction signed by themselves to that proxy. My question is, how is that transaction communicated to the underlying implementation contract? ...
0 votes
1 answer
117 views

Factory pattern for multiple contracts inheriting from same abstract contract exceeds size

I have a base abstract contract which is inherited by 3 other contracts (all having the same interface). I am trying to use a factory contract to conditionally create instances of the derived ...
  • 1
1 vote
0 answers
243 views

ERC-2222 : Funds Distribution Token implementation for a fee contract

My MainCore contract is a contract who sell NFT, and all the sell and buy have a 1% fee for team developper (uint DevelopperCutTotalSupply). I try to implement the ERC-2222 "Funds Distribution ...
0 votes
0 answers
322 views

How can a contract accept some ether and send a stablecoin in return

My contract has to take ETH as a collateral and send some stablecoins ( like USDC) to user. How can I use any stablecoin into my contract , assuming contract has an infinite supply of USDC ? I too ...
1 vote
1 answer
2k views

Override inherited function visability

I have a contract that looks like this: pragma solidity ^0.6.0; import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; contract SwappableToken is ERC20 { constructor(string memory name, ...
0 votes
1 answer
93 views

Reflect Base contract's update in another contract

I have wanted to know what concept is it called when we want two contracts which are deployed on the Network, reflect the transaction and updates in another contract. for example: contract Base{ ...
0 votes
1 answer
426 views

Contract Polymorphism based on address type cast issue

I am new to solidity and having difficulty understanding polymorphism and address typecasting of contracts. I am passing the address of child_1 contract to getChild2Value(address adr) which type cast ...
1 vote
1 answer
178 views

Declaring function with the same name but different arguments in a derived contract [closed]

What happens if one declares a function with the same name as a function in a base contract, but with different arguments in a derived contract? How does it behave with different combinations of ...
  • 1,444