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
0 answers
10 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 ...
user avatar
0 votes
1 answer
15 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 ...
user avatar
0 votes
1 answer
16 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 ...
user avatar
  • 107
0 votes
0 answers
18 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 ...
user avatar
  • 1
0 votes
0 answers
10 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
user avatar
1 vote
1 answer
53 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 ...
user avatar
  • 246
0 votes
2 answers
25 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/...
user avatar
  • 49
1 vote
1 answer
54 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 // ...
user avatar
0 votes
2 answers
111 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'...
user avatar
  • 342
0 votes
0 answers
35 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 ...
user avatar
  • 1
0 votes
1 answer
24 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 ...
user avatar
0 votes
1 answer
31 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 ...
user avatar
0 votes
1 answer
58 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 ...
user avatar
0 votes
1 answer
56 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 ...
user avatar
1 vote
1 answer
477 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 ...
user avatar
  • 159
0 votes
1 answer
68 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 ...
user avatar
0 votes
0 answers
36 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 ...
user avatar
  • 181
0 votes
1 answer
62 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 ...
user avatar
  • 265
1 vote
1 answer
381 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 ...
user avatar
0 votes
1 answer
221 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 ...
user avatar
0 votes
0 answers
17 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 ...
user avatar
0 votes
1 answer
51 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 ...
user avatar
  • 11
2 votes
1 answer
293 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, ...
user avatar
  • 584
0 votes
0 answers
82 views

Creating an Instance of a function (Uniswap v3 code)

In UniswapV3PoolDeployer Contract they make an instance of a function that is inherited from an interface contract, which has me perplexed. This certainly looks like a gas optimization but I couldn't ...
user avatar
0 votes
1 answer
71 views

Call 2 functions from 2 seperate 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 ...
user avatar
0 votes
1 answer
43 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!
user avatar
  • 87
0 votes
0 answers
26 views

Why creation of child by a function of parent contract results in creation of a new parent in the same address of the new born child

I am trying to create a child erc20 token from a mother contract. But every time that I set the inputs of the mint_erc20 function and submit it, in addition to the creation of a new child erc20 ...
user avatar
1 vote
1 answer
130 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-...
user avatar
2 votes
0 answers
335 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 ...
user avatar
  • 303
0 votes
1 answer
124 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 ...
user avatar
1 vote
1 answer
997 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 ...
user avatar
0 votes
1 answer
761 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. ...
user avatar
2 votes
1 answer
118 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? ...
user avatar
0 votes
1 answer
86 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 ...
user avatar
  • 1
1 vote
0 answers
205 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 ...
user avatar
0 votes
0 answers
233 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 ...
user avatar
1 vote
1 answer
1k 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, ...
user avatar
0 votes
1 answer
90 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{ ...
user avatar
0 votes
1 answer
341 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 ...
user avatar
1 vote
1 answer
148 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 ...
user avatar
  • 1,284
2 votes
1 answer
943 views

Calling super class external functions

Is there a way in Solidity to call super class external functions? Normally with inherited contracts, when overriding inherited functions you can also call the original function logic with super....
user avatar
  • 616
0 votes
1 answer
691 views

Abstract contract not inheriting constructor from parent abstract contract

I'm using solidity 0.7.1 and I seem to be running into issues while inheriting from an abstract contract. Specifically with the open zeppelin library, now I'm not creating an issue there because their ...
user avatar
  • 417
1 vote
1 answer
538 views

Multiple Inheritance - Inheritance Graph Impossible

I'm trying to build a contract based on the ERC1404 standard outlined here: https://github.com/simple-restricted-token/simple-restricted-token The contracts allow you to add restrictions on top of ...
user avatar
  • 136
2 votes
2 answers
3k views

Why Can't I Call This Parent Function in Solidity?

Parent function in ERC1155: function uri(uint256) external virtual view override returns (string memory) { return _uri; } Attempted overriding function in my child contract: ...
user avatar
  • 122
0 votes
1 answer
290 views

A contract inherit from a token contract

I have a token contract(ERC20) A, then another contract B inherited from A (B is A). A contract C imported B. questions are: if I deployed B alone, is the address of this contract B represent the ...
user avatar
0 votes
1 answer
115 views

I written an ERC20 token contract, now I have to use my token in another contract for transaction amount. How? [closed]

Taking help of openzepplin, in making ERC20 token , I now have to use this token in multiple contracts for various use. So, how do I code my ERC20 token into other contracts, so that at time of amount ...
user avatar
0 votes
1 answer
37 views

Call method of another contract from one contract in upgradable smartcontract

I have two contracts Vase and Box contract Vase { uint256 public vase1; event VaseValueChanged(uint256 newValue); function createVase(uint256 newValue) public { vase1 = newValue; ...
user avatar
  • 359
0 votes
1 answer
143 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 ...
user avatar
4 votes
1 answer
373 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 ...
user avatar
1 vote
1 answer
227 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 {...
user avatar