【问题标题】:Type is not callable _isExcludedFromFee[(owner)] = true;类型不可调用 _isExcludedFromFee[(owner)] = true;
【发布时间】:2021-08-11 05:05:34
【问题描述】:

我的solidity 0.8.4 代币合约正在流行:

TypeError: Type is not callable 

_isExcludedFromFee[(owner)] = true;
^^^^^^^^

发件人:

     constructor ()  {
        _rOwned[_msgSender()] = _rTotal;
        
        IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(0x05fF2B0DB69458A0750badebc4f9e13aDd608C7F);
         // Create a uniswap pair for this new token
        uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory())
            .createPair(address(this), _uniswapV2Router.WETH());

        // set the rest of the contract variables
        uniswapV2Router = _uniswapV2Router;
        
        _isExcludedFromFee[owner()] = true;
        _isExcludedFromFee[address(this)] = true;
        
        emit Transfer(address(0), _msgSender(), _tTotal);
        
        initialize();
        pause();
    }

我认为是“所有者”导致了错误,并将在下面附上 Ownable 和令牌合约。有一个所有者函数通常包含在 SafeMoon 的 Ownable 中,它返回 _owner 但这只会破坏一切,因为我新声明了地址公共所有者。

【问题讨论】:

    标签: typeerror solidity callable remix owner


    【解决方案1】:

    能够通过进行这些更改来更正:

        contract Ownable is Context {
        
     // OWNER DATA
        address public _owner;
        address public _proposedOwner;
        address private _oldOwner;
        uint256 private _lockTime;
        
        // OWNABLE EVENTS
        event OwnershipTransferProposed(
            address indexed currentOwner,
            address indexed proposedOwner
        );
        event OwnershipTransferDisregarded(
            address indexed oldProposedOwner
        );
        event OwnershipTransferred(
            address indexed oldOwner,
            address indexed newOwner
        );
        
     
        
         /**
         * @dev Initializes the contract setting the deployer as the initial owner.
         */
        constructor () {
            address msgSender = _msgSender();
            _owner = msgSender;
            emit OwnershipTransferred(address(0), msgSender);
        }
        
       /**
         * @dev Returns the address of the current owner.
         */
        function owner() public view returns (address) {
            return _owner;
        }
        
    /**
         * @dev Returns the address of the current owner.
         */
        
        /**
         * @dev Throws if called by any account other than the owner.
         */
        modifier onlyOwner() {
            require(_owner == _msgSender(), "Ownable: caller is not the owner");
            _;
        }
    
         /**
         * @dev Leaves the contract without owner. It will not be possible to call
         * `onlyOwner` functions anymore. Can only be called by the current owner.
         *
         * NOTE: Renouncing ownership will leave the contract without an owner,
         * thereby removing any functionality that is only available to the owner.
         */
        function renounceOwnership() public virtual onlyOwner {
            emit OwnershipTransferred(_owner, address(0));
            _owner = address(0);
        }
    
        /**
         * @dev Transfers ownership of the contract to a new account (`newOwner`).
         * Can only be called by the current owner.
         */
        function transferOwnership(address newOwner) public virtual onlyOwner {
            require(newOwner != address(0), "Ownable: new owner is the zero address");
            emit OwnershipTransferred(_owner, newOwner);
            _owner = newOwner;
        }
    
        function getUnlockTime() public view returns (uint256) {
            return _lockTime;
        }
    
        //Locks the contract for owner for the amount of time provided
        function lock(uint256 time) public virtual onlyOwner {
            _oldOwner = _owner;
            _owner = address(0);
            _lockTime = block.timestamp + time;
            emit OwnershipTransferred(_owner, address(0));
        }
        
        //Unlocks the contract for owner when _lockTime is exceeds
        function unlock() public virtual {
            require(_oldOwner == msg.sender, "You don't have permission to unlock");
            require(block.timestamp > _lockTime , "Contract is locked until 7 days");
            emit OwnershipTransferred(_owner, _oldOwner);
            _owner = _oldOwner;
        }
    
      }
    

    【讨论】:

      猜你喜欢
      • 2022-12-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-08
      • 1970-01-01
      • 2023-02-07
      • 2020-08-29
      • 2021-10-31
      相关资源
      最近更新 更多