交易失败 - 钱包到钱包和钱包到合约余额

问题描述

我刚刚开始使用 solidity,为了理解和学习 solidity 以及与 Remix 的结合,我复制了一些合同。 目前我正在测试合约“Token69”,如果我现在尝试部署令牌,我会收到错误消息:

“创建 Token69 出错:错误编码参数:错误:无效的 BigNumber 字符串 (argument="value",value="",code=INVALID_ARGUMENT,version=bignumber/5.1.1)”

我发现我的问题的原因是因为构造函数中的数据。我可以毫无问题地删除代码的这些部分,还是必须用数据来完成这些部分? 除此之外,如果我取出构造函数并尝试部署令牌(标准 gas 限制的所有内容并收取 Remix 的所有其他标准值),该令牌将永久处于“待创建令牌”状态 没有错误错误报告或任何东西。我真的不知道该怎么办。

有人可以帮我吗?


我已经测试了另一个合约,现在我可以部署合约并且代币被发送到我的钱包,但我无法将代币转移到另一个钱包。我在这份合同中找不到问题,有人可以帮我解决这个问题吗?


pragma solidity ^0.8.2;


abstract contract Context {
    function _msgSender() internal view virtual returns (address payable) {
        return payable(msg.sender);
    }

    function _msgData() internal view virtual returns (bytes memory) {
        this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
        return msg.data;
    }
}

interface IBEP20 {
    function totalSupply() external view returns (uint256);

    function balanceOf(address account) external view returns (uint256);

    function transfer(address recipient,uint256 amount) external returns (bool);

    function allowance(address owner,address spender) external view returns (uint256);

    function approve(address spender,uint256 amount) external returns (bool);

    function transferFrom(address sender,address recipient,uint256 amount) external returns (bool);

    event Transfer(address indexed from,address indexed to,uint256 value);

    event Approval(address indexed owner,address indexed spender,uint256 value);
}

library SafeMath {

    function add(uint256 a,uint256 b) internal pure returns (uint256) {
        uint256 c = a + b;
        require(c >= a,"SafeMath: addition overflow");

        return c;
    }

    function sub(uint256 a,uint256 b) internal pure returns (uint256) {
        return sub(a,b,"SafeMath: subtraction overflow");
    }

    function sub(uint256 a,uint256 b,string memory errorMessage) internal pure returns (uint256) {
        require(b <= a,errorMessage);
        uint256 c = a - b;

        return c;
    }

    function mul(uint256 a,uint256 b) internal pure returns (uint256) {
        // Gas optimization: this is cheaper than requiring 'a' not being zero,but the
        // benefit is lost if 'b' is also tested.
        // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
        if (a == 0) {
            return 0;
        }

        uint256 c = a * b;
        require(c / a == b,"SafeMath: multiplication overflow");

        return c;
    }

    function div(uint256 a,uint256 b) internal pure returns (uint256) {
        return div(a,"SafeMath: division by zero");
    }

    function div(uint256 a,string memory errorMessage) internal pure returns (uint256) {
        require(b > 0,errorMessage);
        uint256 c = a / b;
        // assert(a == b * c + a % b); // There is no case in which this doesn't hold

        return c;
    }

    function mod(uint256 a,uint256 b) internal pure returns (uint256) {
        return mod(a,"SafeMath: modulo by zero");
    }

    function mod(uint256 a,string memory errorMessage) internal pure returns (uint256) {
        require(b != 0,errorMessage);
        return a % b;
    }
}

library Address {

    function isContract(address account) internal view returns (bool) {
        // According to EIP-1052,0x0 is the value returned for not-yet created accounts
        // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
        // for accounts without code,i.e. `keccak256('')`
        bytes32 codehash;
        bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
        // solhint-disable-next-line no-inline-assembly
        assembly { codehash := extcodehash(account) }
        return (codehash != accountHash && codehash != 0x0);
    }

    function sendValue(address payable recipient,uint256 amount) internal {
        require(address(this).balance >= amount,"Address: insufficient balance");

        // solhint-disable-next-line avoid-low-level-calls,avoid-call-value
        (bool success,) = recipient.call{ value: amount }("");
        require(success,"Address: unable to send value,recipient may have reverted");
    }

    function functionCall(address target,bytes memory data) internal returns (bytes memory) {
      return functionCall(target,data,"Address: low-level call Failed");
    }

    function functionCall(address target,bytes memory data,string memory errorMessage) internal returns (bytes memory) {
        return _functionCallWithValue(target,errorMessage);
    }

    function functionCallWithValue(address target,uint256 value) internal returns (bytes memory) {
        return functionCallWithValue(target,value,"Address: low-level call with value Failed");
    }

    function functionCallWithValue(address target,uint256 value,string memory errorMessage) internal returns (bytes memory) {
        require(address(this).balance >= value,"Address: insufficient balance for call");
        return _functionCallWithValue(target,errorMessage);
    }

    function _functionCallWithValue(address target,uint256 weiValue,string memory errorMessage) private returns (bytes memory) {
        require(isContract(target),"Address: call to non-contract");

        // solhint-disable-next-line avoid-low-level-calls
        (bool success,bytes memory returndata) = target.call{ value: weiValue }(data);
        if (success) {
            return returndata;
        } else {
            // Look for revert reason and bubble it up if present
            if (returndata.length > 0) {
                // The easiest way to bubble the revert reason is using memory via assembly

                // solhint-disable-next-line no-inline-assembly
                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32,returndata),returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}

contract Ownable is Context {
    address private _owner;

    event OwnershipTransferred(address indexed prevIoUsOwner,address indexed newOwner);

    constructor () {
        address msgSender = _msgSender();
        _owner = msgSender;
        emit OwnershipTransferred(address(0),msgSender);
    }

    function owner() public view returns (address) {
        return _owner;
    }

    modifier onlyOwner() {
        require(_owner == _msgSender(),"Ownable: caller is not the owner");
        _;
    }

    function renounceOwnership() public virtual onlyOwner {
        emit OwnershipTransferred(_owner,address(0));
        _owner = address(0);
    }

    function transferOwnership(address newOwner) public virtual onlyOwner {
        require(newOwner != address(0),"Ownable: new owner is the zero address");
        emit OwnershipTransferred(_owner,newOwner);
        _owner = newOwner;
    }
}

contract TestToken is Context,IBEP20,Ownable {
    using SafeMath for uint256;
    using Address for address;

    mapping (address => uint256) private _rOwned;
    mapping (address => uint256) private _tOwned;
    mapping (address => mapping (address => uint256)) private _allowances;

    mapping (address => bool) private _isExcluded;
    mapping (address => bool) private _isCharity;
    address[] private _excluded;
    address[] private _charity;
    
    string  private constant _NAME = 'TestToken';
    string  private constant _SYMBOL = 'TT';
    uint8   private constant _DECIMALS = 18;
   
    uint256 private constant _MAX = ~uint256(0);
    uint256 private constant _DECIMALFACTOR = 10 ** uint256(_DECIMALS);
    uint256 private constant _GRANULARITY = 100;
    
    uint256 private _tTotal = 1000000000000000 * _DECIMALFACTOR;
    uint256 private _rTotal = (_MAX - (_MAX % _tTotal));
    
    uint256 private _tFeetotal;
    uint256 private _tBurnTotal;
    uint256 private _tCharityTotal;
    
    uint256 private     _TAX_FEE = 500; // 5% BACK TO HOLDERS
    uint256 private    _BURN_FEE = 500; // 5% BURNED
    uint256 private _CHARITY_FEE = 100; // 1% TO CHARITY WALLET
    uint256 private constant _MAX_TX_SIZE = 1000000000000000 * _DECIMALFACTOR;

    // Track original fees to bypass fees for charity account
    uint256 private ORIG_TAX_FEE = _TAX_FEE;
    uint256 private ORIG_BURN_FEE = _BURN_FEE;
    uint256 private ORIG_CHARITY_FEE = _CHARITY_FEE;

    constructor () {
        _rOwned[_msgSender()] = _rTotal;
        emit Transfer(address(0),_msgSender(),_tTotal);
    }

    function name() public pure returns (string memory) {
        return _NAME;
    }

    function symbol() public pure returns (string memory) {
        return _SYMBOL;
    }

    function decimals() public pure returns (uint8) {
        return _DECIMALS;
    }

    function totalSupply() public view override returns (uint256) {
        return _tTotal;
    }

    function balanceOf(address account) public view override returns (uint256) {
        if (_isExcluded[account]) return _tOwned[account];
        return tokenFromreflection(_rOwned[account]);
    }

    function transfer(address recipient,uint256 amount) public override returns (bool) {
        _transfer(_msgSender(),recipient,amount);
        return true;
    }

    function allowance(address owner,address spender) public view override returns (uint256) {
        return _allowances[owner][spender];
    }

    function approve(address spender,uint256 amount) public override returns (bool) {
        _approve(_msgSender(),spender,amount);
        return true;
    }

    function transferFrom(address sender,uint256 amount) public override returns (bool) {
        _transfer(sender,amount);
        _approve(sender,_allowances[sender][_msgSender()].sub(amount,"BEP20: transfer amount exceeds allowance"));
        return true;
    }

    function increaseAllowance(address spender,uint256 addedValue) public virtual returns (bool) {
        _approve(_msgSender(),_allowances[_msgSender()][spender].add(addedValue));
        return true;
    }

    function decreaseAllowance(address spender,uint256 subtractedValue) public virtual returns (bool) {
        _approve(_msgSender(),_allowances[_msgSender()][spender].sub(subtractedValue,"BEP20: decreased allowance below zero"));
        return true;
    }

    function isExcluded(address account) public view returns (bool) {
        return _isExcluded[account];
    }
    
    function isCharity(address account) public view returns (bool) {
        return _isCharity[account];
    }

    function totalFees() public view returns (uint256) {
        return _tFeetotal;
    }
    
    function totalBurn() public view returns (uint256) {
        return _tBurnTotal;
    }
    
    function totalCharity() public view returns (uint256) {
        return _tCharityTotal;
    }

    function deliver(uint256 tAmount) public {
        address sender = _msgSender();
        require(!_isExcluded[sender],"Excluded addresses cannot call this function");
        (uint256 rAmount,) = _getValues(tAmount);
        _rOwned[sender] = _rOwned[sender].sub(rAmount);
        _rTotal = _rTotal.sub(rAmount);
        _tFeetotal = _tFeetotal.add(tAmount);
    }

    function reflectionFromToken(uint256 tAmount,bool deductTransferFee) public view returns(uint256) {
        require(tAmount <= _tTotal,"Amount must be less than supply");
        if (!deductTransferFee) {
            (uint256 rAmount,) = _getValues(tAmount);
            return rAmount;
        } else {
            (,uint256 rTransferAmount,) = _getValues(tAmount);
            return rTransferAmount;
        }
    }

    function tokenFromreflection(uint256 rAmount) public view returns(uint256) {
        require(rAmount <= _rTotal,"Amount must be less than total reflections");
        uint256 currentRate =  _getRate();
        return rAmount.div(currentRate);
    }

    function excludeAccount(address account) external onlyOwner() {
        require(account != 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D,'We can not exclude Uniswap router.');
        require(!_isExcluded[account],"Account is already excluded");
        if(_rOwned[account] > 0) {
            _tOwned[account] = tokenFromreflection(_rOwned[account]);
        }
        _isExcluded[account] = true;
        _excluded.push(account);
    }

    function includeAccount(address account) external onlyOwner() {
        require(_isExcluded[account],"Account is already excluded");
        for (uint256 i = 0; i < _excluded.length; i++) {
            if (_excluded[i] == account) {
                _excluded[i] = _excluded[_excluded.length - 1];
                _tOwned[account] = 0;
                _isExcluded[account] = false;
                _excluded.pop();
                break;
            }
        }
    }

    function setAsCharityAccount(address account) external onlyOwner() {
        require(account != 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D,'The Uniswap router can not be the charity account.');
        require(!_isCharity[account],"Account is already charity account");
        _isCharity[account] = true;
        _charity.push(account);
    }

    function _approve(address owner,address spender,uint256 amount) private {
        require(owner != address(0),"BEP20: approve from the zero address");
        require(spender != address(0),"BEP20: approve to the zero address");

        _allowances[owner][spender] = amount;
        emit Approval(owner,amount);
    }

    function _transfer(address sender,uint256 amount) private {
        require(sender != address(0),"BEP20: transfer from the zero address");
        require(recipient != address(0),"BEP20: transfer to the zero address");
        require(amount > 0,"Transfer amount must be greater than zero");

        // Remove fees for transfers to and from charity account or to excluded account
        bool takeFee = true;
        if (_isCharity[sender] || _isCharity[recipient] || _isExcluded[recipient]) {
            takeFee = false;
        }

        if (!takeFee) removeAllFee();
        
        if (sender != owner() && recipient != owner())
            require(amount <= _MAX_TX_SIZE,"Transfer amount exceeds the maxTxAmount.");
        
        if (_isExcluded[sender] && !_isExcluded[recipient]) {
            _transferFromExcluded(sender,amount);
        } else if (!_isExcluded[sender] && _isExcluded[recipient]) {
            _transferToExcluded(sender,amount);
        } else if (!_isExcluded[sender] && !_isExcluded[recipient]) {
            _transferStandard(sender,amount);
        } else if (_isExcluded[sender] && _isExcluded[recipient]) {
            _transferBothExcluded(sender,amount);
        } else {
            _transferStandard(sender,amount);
        }

        if (!takeFee) restoreAllFee();
    }

    function _transferStandard(address sender,uint256 tAmount) private {
        uint256 currentRate =  _getRate();
        (uint256 rAmount,uint256 rFee,uint256 tTransferAmount,uint256 tFee,uint256 tBurn,uint256 tCharity) = _getValues(tAmount);
        uint256 rBurn =  tBurn.mul(currentRate);
        uint256 rCharity = tCharity.mul(currentRate);     
        _standardTransferContent(sender,rAmount,rTransferAmount);
        _sendtocharity(tCharity,sender);
        _reflectFee(rFee,rBurn,rCharity,tFee,tBurn,tCharity);
        emit Transfer(sender,tTransferAmount);
    }
    
    function _standardTransferContent(address sender,uint256 rAmount,uint256 rTransferAmount) private {
        _rOwned[sender] = _rOwned[sender].sub(rAmount);
        _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount);
    }
    
    function _transferToExcluded(address sender,uint256 tCharity) = _getValues(tAmount);
        uint256 rBurn =  tBurn.mul(currentRate);
        uint256 rCharity = tCharity.mul(currentRate);
        _excludedFromTransferContent(sender,tTransferAmount,rTransferAmount);        
        _sendtocharity(tCharity,tTransferAmount);
    }
    
    function _excludedFromTransferContent(address sender,uint256 rTransferAmount) private {
        _rOwned[sender] = _rOwned[sender].sub(rAmount);
        _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount);
        _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount);    
    }
    

    function _transferFromExcluded(address sender,uint256 tCharity) = _getValues(tAmount);
        uint256 rBurn =  tBurn.mul(currentRate);
        uint256 rCharity = tCharity.mul(currentRate);
        _excludedToTransferContent(sender,tAmount,tTransferAmount);
    }
    
    function _excludedToTransferContent(address sender,uint256 tAmount,uint256 rTransferAmount) private {
        _tOwned[sender] = _tOwned[sender].sub(tAmount);
        _rOwned[sender] = _rOwned[sender].sub(rAmount);
        _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount);  
    }

    function _transferBothExcluded(address sender,uint256 tCharity) = _getValues(tAmount);
        uint256 rBurn =  tBurn.mul(currentRate);
        uint256 rCharity = tCharity.mul(currentRate);    
        _bothTransferContent(sender,rTransferAmount);  
        _sendtocharity(tCharity,tTransferAmount);
    }
    
    function _bothTransferContent(address sender,uint256 rTransferAmount) private {
        _tOwned[sender] = _tOwned[sender].sub(tAmount);
        _rOwned[sender] = _rOwned[sender].sub(rAmount);
        _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount);
        _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount);  
    }

    function _reflectFee(uint256 rFee,uint256 rBurn,uint256 rCharity,uint256 tCharity) private {
        _rTotal = _rTotal.sub(rFee).sub(rBurn).sub(rCharity);
        _tFeetotal = _tFeetotal.add(tFee);
        _tBurnTotal = _tBurnTotal.add(tBurn);
        _tCharityTotal = _tCharityTotal.add(tCharity);
        _tTotal = _tTotal.sub(tBurn);
    }
    

    function _getValues(uint256 tAmount) private view returns (uint256,uint256,uint256) {
        (uint256 tFee,uint256 tCharity) = _getTBasics(tAmount,_TAX_FEE,_BURN_FEE,_CHARITY_FEE);
        uint256 tTransferAmount = getTTransferAmount(tAmount,tCharity);
        uint256 currentRate =  _getRate();
        (uint256 rAmount,uint256 rFee) = _getRBasics(tAmount,currentRate);
        uint256 rTransferAmount = _getRTransferAmount(rAmount,rFee,tCharity,currentRate);
        return (rAmount,rTransferAmount,tCharity);
    }
    
    function _getTBasics(uint256 tAmount,uint256 taxFee,uint256 burnFee,uint256 charityFee) private pure returns (uint256,uint256) {
        uint256 tFee = ((tAmount.mul(taxFee)).div(_GRANULARITY)).div(100);
        uint256 tBurn = ((tAmount.mul(burnFee)).div(_GRANULARITY)).div(100);
        uint256 tCharity = ((tAmount.mul(charityFee)).div(_GRANULARITY)).div(100);
        return (tFee,tCharity);
    }
    
    function getTTransferAmount(uint256 tAmount,uint256 tCharity) private pure returns (uint256) {
        return tAmount.sub(tFee).sub(tBurn).sub(tCharity);
    }
    
    function _getRBasics(uint256 tAmount,uint256 currentRate) private pure returns (uint256,uint256) {
        uint256 rAmount = tAmount.mul(currentRate);
        uint256 rFee = tFee.mul(currentRate);
        return (rAmount,rFee);
    }
    
    function _getRTransferAmount(uint256 rAmount,uint256 tCharity,uint256 currentRate) private pure returns (uint256) {
        uint256 rBurn = tBurn.mul(currentRate);
        uint256 rCharity = tCharity.mul(currentRate);
        uint256 rTransferAmount = rAmount.sub(rFee).sub(rBurn).sub(rCharity);
        return rTransferAmount;
    }

    function _getRate() private view returns(uint256) {
        (uint256 rSupply,uint256 tSupply) = _getCurrentSupply();
        return rSupply.div(tSupply);
    }

    function _getCurrentSupply() private view returns(uint256,uint256) {
        uint256 rSupply = _rTotal;
        uint256 tSupply = _tTotal;      
        for (uint256 i = 0; i < _excluded.length; i++) {
            if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal,_tTotal);
            rSupply = rSupply.sub(_rOwned[_excluded[i]]);
            tSupply = tSupply.sub(_tOwned[_excluded[i]]);
        }
        if (rSupply < _rTotal.div(_tTotal)) return (_rTotal,_tTotal);
        return (rSupply,tSupply);
    }

    function _sendtocharity(uint256 tCharity,address sender) private {
        uint256 currentRate = _getRate();
        uint256 rCharity = tCharity.mul(currentRate);
        address currentCharity = _charity[0];
        _rOwned[currentCharity] = _rOwned[currentCharity].add(rCharity);
        _tOwned[currentCharity] = _tOwned[currentCharity].add(tCharity);
        emit Transfer(sender,currentCharity,tCharity);
    }

    function removeAllFee() private {
        if(_TAX_FEE == 0 && _BURN_FEE == 0 && _CHARITY_FEE == 0) return;
        
        ORIG_TAX_FEE = _TAX_FEE;
        ORIG_BURN_FEE = _BURN_FEE;
        ORIG_CHARITY_FEE = _CHARITY_FEE;
        
        _TAX_FEE = 0;
        _BURN_FEE = 0;
        _CHARITY_FEE = 0;
    }
    
    function restoreAllFee() private {
        _TAX_FEE = ORIG_TAX_FEE;
        _BURN_FEE = ORIG_BURN_FEE;
        _CHARITY_FEE = ORIG_CHARITY_FEE;
    }
    
    function _getTaxFee() private view returns(uint256) {
        return _TAX_FEE;
    }

    function _getMaxTxAmount() private pure returns(uint256) {
        return _MAX_TX_SIZE;
    }
    
}```

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...