Solidity

更正建構子的程式碼

  • May 11, 2018

這個 StackExchange 問題幾乎回答了我的問題。但是我不知道如何準確地更正我的程式碼,以便以契約命名的函式被建構子替換。

該功能將如何具體糾正?

contract Fake_Smrt_Coin is EIC20{

uint256 constant private MAX_UINT256 = 2**256 - 1;
mapping (address => uint256) public balances;
mapping (address => mapping (address => uint256)) public allowed;

string public name;                   
uint8 public decimals;              
string public symbol;                 
//I know this line needs improvement
function Fake_Smrt_Coin (
   uint256 _initialAmount,
   string _tokenName,
   uint8 _decimalUnits,
   string _tokenSymbol
) public {
   balances[msg.sender] = _initialAmount;
   totalSupply = _initialAmount;
   name = _tokenName;
   decimals = _decimalUnits;
   symbol = _tokenSymbol;
}

function transfer(address _to, uint256 _value) public returns (bool success) {
   require(balances[msg.sender] >= _value);
   balances[msg.sender] -= _value;
   balances[_to] += _value;
   emit Transfer(msg.sender, _to, _value); 
   return true;
}

更新的程式碼會是嗎?

 constructor(){
   string public name;                   
   uint8 public decimals;              
   string public symbol;                    
   }

function transfer(address _to, uint256 _value) public returns (bool success) {
   require(balances[msg.sender] >= _value);
   balances[msg.sender] -= _value;
   balances[_to] += _value;
   emit Transfer(msg.sender, _to, _value); 
   return true;
}
//I know this line needs improvement
constructor (
   uint256 _initialAmount,
   string _tokenName,
   uint8 _decimalUnits,
   string _tokenSymbol
) public {
   balances[msg.sender] = _initialAmount;
   totalSupply = _initialAmount;
   name = _tokenName;
   decimals = _decimalUnits;
   symbol = _tokenSymbol;
}

希望能幫助到你。

只需function Fake_Smrt_Coin按程式碼字更改即可constructor

希望這可以幫助。

引用自:https://ethereum.stackexchange.com/questions/48248