Questions tagged [override]
override is a keyword that is used the mark functions whose logic is overriding functions of the same signature in inherited contracts.
16
questions
1
vote
1
answer
18
views
How to cache the result of an inherited function before overriding it
contract A {
function getUINT() public virtual view returns (uint) {
return 100000;
}
}
contract B is A {
uint trycache;
uint public trycache2 = getUINT(); // still 200000
...
1
vote
1
answer
31
views
Re declaration question - Inheritance & overriding
I need help clearing somethings up when it comes down to redeclaration and implementation of inherited functions. I have an example below. I am building an nft erc1155 marketplace and inherited the ...
1
vote
2
answers
45
views
Is it possible to define interface getters for arrays of structs?
Given a state variable defined like this:
struct Segment {
uint256 foo;
uint256 bar;
}
Segment[] public override segments;
Is it possible to define a getter in an interface?
I've tried this ...
1
vote
1
answer
86
views
Do I need a burn function to inherit ERC721URIStorage?
I have an ERC721 contract that inherits ERC721URIStorage because I have to keep the URI on-chain. The problem I have is I am getting all these errors:
Derived contract must override function "...
0
votes
1
answer
14
views
Function override error and abstract error after importing the contract
*this a contract for erc721:
contract erc721{
event Transfer(address indexed _from, address indexed _to, uint256 indexed _tokenId);
event Approval(address indexed _owner,address indexed _approved, ...
1
vote
2
answers
31
views
Add new logic without removing old logic inherited from Openzeppelin contract
I'm using ERC1155 and I want NFT in my contract that cannot be transferred in a specific condition. If I use override for _transferFrom, It will override new logic, and old logic will be lost. I just ...
0
votes
1
answer
98
views
Inheritance issue using virtual and override (probably): Member not found
I'm trying to work through a course that is covering virtual and override and seem to be getting an error due to inheritance. Below is the code:
//SPDX-License-Identifier: GPL-3.0
pragma solidity >...
3
votes
2
answers
421
views
Override mock contracts's address in test
I have a smart contract that is dependent on a pre-deployed ERC-20 smart contract that is always deployed to the same address (in the local test network as well as public ones).
I want to override the ...
4
votes
1
answer
667
views
Interface overriding giving error. Overriding public state variable return types differ [duplicate]
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 ...
0
votes
1
answer
163
views
When to use override in these two different ways
In these two examples from the AccessControl library, override is used differently, one is more specific. When does it necessitate using it in one format over another?
function grantRole(bytes32 ...
0
votes
1
answer
604
views
ERC20 token, override functions but state variable do not update as expected
I am trying to implement and test an ERC20 token by inheriting from ERC20.sol from OpenZeppelin.
I want most of the functions to be by default from OpenZeppelin but I also want to overrride some of ...
2
votes
1
answer
3k
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, ...
53
votes
1
answer
48k
views
What are the virtual and override keywords in Solidity?
Solidity 0.6.0 introduced the keywords virtual and override. What do they do?
0
votes
1
answer
587
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 ...
7
votes
1
answer
5k
views
Override parent method and modifiers
For example, we have a contract:
contract A {
modifier checkCaller() {
require(msg.sender == 0x123);
_;
}
function doSmth() checkCaller {}
}
We make child contract and ...
0
votes
1
answer
2k
views
Call derived function from base contract
I have the following smart contracts:
pragma solidity ^0.4.11;
contract base {
uint public v;
separate public mySep;
function base() {
mySep = new separate();
}
...