Solidity
完成此 BEP20 的合約代幣需要什麼?
我想弄清楚總供應量的 80% 是否分配給了網路?如果我在這裡缺少任何基本的東西?
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; contract Token { mapping(address => uint) public balances; mapping(address => mapping(address => uint)) public allowance; uint public totalSupply = 1000000000 * 10 ** 18; string public name = "alex"; string public symbol = "ali"; uint public decimals = 18; event Transfer(address indexed from, address indexed to, uint value); event Approval(address indexed owner, address indexed spender, uint value); constructor() { totalSupply = (totalSupply*80)/100; balances[msg.sender] = (totalSupply*20)/100; } // constructor () public totalSupply ("alex", "ali"){ // _mint(msg.sender, 100000000 *(10 ** unit256(decimals()))); //} function balanceOf(address owner) public returns(uint) { return balances[owner]; } function transfer(address to, uint value) public returns(bool) { require(balanceOf(msg.sender) >= value, 'balance too low'); //uint mymoney=(totalSupply*20)/100; balances[to] += totalSupply; balances[msg.sender] -= value; balances[msg.sender] += balances[msg.sender]; //balances[to] += value; //balances[msg.sender] -= value; emit Transfer(msg.sender, to, value); return true; } function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); //beforeTokenTransfer(address(0), account, amount); //totalSupply = msg.sender * 0.20; //20% //totalSupply = mymoney; balances[account] += amount; emit Transfer(address(0), account, amount); //afterTokenTransfer(address(0), account, amount); } function transferFrom(address from, address to, uint value) public returns(bool) { require(balanceOf(from) >= value, 'balance too low'); require(allowance[from][msg.sender] >= value, 'allowance too low'); balances[to] += value; balances[from] -= value; emit Transfer(from, to, value); return true; } function approval(address spender, uint value) public returns (bool) { allowance[msg.sender][spender] = value; emit Approval(msg.sender, spender, value); return true; } }
BEP20 規範在這裡。
它缺少一些方法:
- 津貼
- 批准
- 獲取所有者
某些方法的簽名錯誤
- 小數點
這個答案是快速瀏覽,所以其他事情可能是錯誤的。
//這是一個更新的版本。謝謝你們的意見。//
// SPDX-License-Identifier: MIT pragma solidity 0.8.4; contract Alex{ string public name; string public symbol ; uint256 _totalSupply; uint8 public decimals ; uint _publicmoney; address public myaddress=address(this); event Transfer(address indexed _from, address indexed _to, uint256 _value); event Approval( address indexed _owner, address indexed _spender, uint256 _value ); mapping(address => uint256) public balanceOf; mapping(address => mapping(address => uint256)) public allowance; constructor() { name = "Alex"; symbol = "ali"; _totalSupply = 1000000000 * 10 ** 18; // 1 billion tokens decimals = 18; myaddress=address(this); balanceOf[myaddress] =(_totalSupply*80)/100; _publicmoney =(_totalSupply*20)/100; balanceOf[msg.sender]= _publicmoney; } function ownmoney() public view returns (uint256) { return balanceOf[myaddress]; } function totalSupply() public view returns (uint256) { return _publicmoney; } function transfer(address _to, uint256 _value) public returns (bool success) { require(balanceOf[msg.sender] >= _value); balanceOf[msg.sender] -= _value; balanceOf[_to] += _value; emit Transfer(msg.sender, _to, _value); return true; } function approve(address _spender, uint256 _value) public returns (bool success) { allowance[myaddress]; allowance[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _value); return true; } function transferFrom( address _from, address _to, uint256 _value ) public returns (bool success) { require(_value <= balanceOf[_from]); require(_value <= allowance[_from][msg.sender]); balanceOf[_from] -= _value; balanceOf[_to] += _value; allowance[_from][msg.sender] -= _value; emit Transfer(_from, _to, _value); return true; } }