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
1
vote
1answer
57 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, ...
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 ...
1
vote
1answer
230 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 ...
1
vote
1answer
192 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
89 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
1answer
109 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
2answers
210 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 ...
1
vote
0answers
40 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 ...
1
vote
0answers
138 views

Truffle: How to test for inheritance

I have a Contract B which should inherit from contract A. Using Truffle, how can I test that this is indeed the case?
0
votes
1answer
78 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 ...
0
votes
2answers
78 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
45 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
52 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
242 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 ...
0
votes
1answer
33 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
16 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
18 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 ...
0
votes
1answer
65 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?
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
116 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
66 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
68 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
281 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
260 views

BalanceOf from BasicToken & totalSupply from ERC20Basic not working from Crowdsale.sol

I'm using Crowdsale.sol from OpenZeppelin / zeppelin-solidity. Here's a snippet: import '../token/MintableToken.sol'; import '../math/SafeMath.sol'; /** * @title Crowdsale * @dev Crowdsale is a ...
0
votes
1answer
52 views

Unable to store/retreive the value of an inherited attribute

Contract code: pragma solidity ^0.4.11; contract Base { uint stored; function set (uint _stored) { stored = _stored; } function get () constant returns (uint) { ...
0
votes
1answer
16 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
26 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 ...
0
votes
2answers
26 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
29 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
0answers
32 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
2answers
159 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
54 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
24 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
14 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 ...
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; ...
0
votes
1answer
76 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 ...
0
votes
1answer
67 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
169 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 ...
0
votes
1answer
58 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
791 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 ...
0
votes
1answer
194 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
234 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. ...
0
votes
1answer
240 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 ...
0
votes
1answer
278 views

I cant get the value of a state variable public

I am developing a smart contract which I have two contracts(A and B). I have an array variable in A and fill it with values but when I get that variable from B, the array address is empty. pragma ...
0
votes
1answer
239 views

Contracts work on testrpc but not Rinkeby. Using delegatecall (upgradeable contracts) pattern and trying to add new Contract() to array is failing

I have a series of contracts that work perfectly fine on testrpc but not when I deploy to Rinkeby. I am using a standard token contract with Zeppelin that I am having no issues with. The issue is ...
0
votes
1answer
150 views

Trying to use single library for both parent and child contracts

I would like to have a single owner across the parent contract and child contracts that this parent creates. However, when the child contract is created, it redeploys the library and uses the parent ...

1
2