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
1answer
21 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
0answers
15 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 ...
0
votes
1answer
25 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 ...
0
votes
1answer
25 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
1answer
25 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
0answers
15 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
1answer
39 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 ...
1
vote
1answer
29 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, ...
0
votes
0answers
44 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 ...
0
votes
1answer
43 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 ...
0
votes
1answer
19 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!
0
votes
0answers
14 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 ...
1
vote
1answer
40 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
0answers
97 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 ...
0
votes
1answer
47 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 ...
0
votes
1answer
362 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
1answer
341 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
1answer
40 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
1answer
50 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 ...
0
votes
0answers
21 views

A smart contract that compiles and doesn't have errors, is not deployed and revert all the process

I have a central smart contract that inherits from other contracts and create two entities that are the entities of the contract that are going to sign it. This "central" contract is named &...
0
votes
0answers
229 views

definition of base has to precede definition of derived contract

I have two different files which are Project1.sol and Project2.sol Project2.sol is like: import "./Project1.sol"; contract Project2{ address newProject1Address =address(new ...
0
votes
0answers
32 views

Implementing the template method pattern w/ Solidity's static types

I'm building an interface, let's call it HandlerInterface. The interface would have two implementations for starters: Erc20Handler: with a handle(uint256 tokenAmount) function. Erc721Handler: with a ...
1
vote
0answers
106 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
0answers
115 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
1answer
399 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
1answer
76 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
1answer
158 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
1answer
96 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 ...
2
votes
1answer
337 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....
0
votes
1answer
322 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 ...
0
votes
1answer
279 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 ...
2
votes
2answers
1k 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: ...
0
votes
1answer
171 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 ...
0
votes
1answer
84 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 ...
0
votes
1answer
28 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; ...
0
votes
1answer
95 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
282 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
141 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
202 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
154 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
1k 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 ...
1
vote
2answers
357 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
302 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
27 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
72 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
108 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
36 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
26 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
653 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
41 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 ...