Solidity
Remix 不顯示合約部署的建構子呼叫(remix 中的錯誤?)
我想用我的客戶端測試發送 ERC20 代幣,所以我需要在測試網上創建一些代幣。我正在使用 Remix 和 Rinkeby 測試網,但我不再習慣使用 remix。當我之前這樣做(創建契約)時,曾經有一個文本欄位,可以在其中放置建構子參數來部署契約。但現在我看到的只是一個
Local contract from Address
. 以前的建構子欄位在哪裡?這就是我所看到的:
這是我的契約:
/* Implements EIP20 token standard: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md .*/ pragma solidity ^0.4.21; import "./EIP20Interface.sol"; import "./SafeMath.sol"; contract MyToken is EIP20Interface { uint256 constant private MAX_UINT256 = 2**256 - 1; mapping (address => uint256) public balances; mapping (address => mapping (address => uint256)) public allowed; /* NOTE: The following variables are OPTIONAL vanities. One does not have to include them. They allow one to customise the token contract & in no way influences the core functionality. Some wallets/interfaces might not even bother to look at this information. */ string public name; //fancy name: eg Simon Bucks uint8 public decimals; //How many decimals to show. string public symbol; //An identifier: eg SBX function Constructor ( uint256 _initialAmount, string _tokenName, uint8 _decimalUnits, string _tokenSymbol ) public { balances[msg.sender] = _initialAmount; // Give the creator all initial tokens totalSupply = _initialAmount; // Update total supply name = _tokenName; // Set the name for display purposes decimals = _decimalUnits; // Amount of decimals for display purposes symbol = _tokenSymbol; // Set the symbol for display purposes } function transfer(address _to, uint256 _value) public returns (bool success) { require(balances[msg.sender] >= _value); balances[msg.sender] = SafeMath.sub(balances[msg.sender], _value); balances[_to] = SafeMath.add(balances[_to], _value); emit Transfer(msg.sender, _to, _value); //solhint-disable-line indent, no-unused-vars return true; } function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { uint256 allowance = allowed[_from][msg.sender]; require(balances[_from] >= _value && allowance >= _value); balances[_to] = SafeMath.add(balances[_to], _value); balances[_from] = SafeMath.sub(balances[_from], _value); if (allowance < MAX_UINT256) { allowed[_from][msg.sender] = SafeMath.sub(allowed[_from][msg.sender], _value); } emit Transfer(_from, _to, _value); //solhint-disable-line indent, no-unused-vars return true; } function balanceOf(address _owner) public view returns (uint256 balance) { return balances[_owner]; } function approve(address _spender, uint256 _value) public returns (bool success) { allowed[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _value); //solhint-disable-line indent, no-unused-vars return true; } function allowance(address _owner, address _spender) public view returns (uint256 remaining) { return allowed[_owner][_spender]; } }
編輯:
我發現如果我將建構子從 更改
Constructor
為MyToken
,它可以工作。顯然Constructor
,使用已棄用的類名重新混合建議和呼叫,但如果你這樣做,你將無法部署你的契約。聽起來像一個錯誤?
您不必在建構子前添加 function 關鍵字。它不會在部署期間出現,因為您將其聲明為合約功能。刪除 function 關鍵字並嘗試。肯定會奏效的。
constructor (uint256 _initialAmount, string _tokenName, uint8 _decimalUnits, string _tokenSymbol) public { balances[msg.sender] = _initialAmount; // Give the creator all initial tokens totalSupply = _initialAmount; // Update total supply name = _tokenName; // Set the name for display purposes decimals = _decimalUnits; // Amount of decimals for display purposes symbol = _tokenSymbol; // Set the symbol for display purposes }
轉到右上角的編譯選項卡,然後點擊“編譯”按鈕,然後勾選“自動編譯”複選框。
當您返回 Deploy 時,您應該有文本框來傳遞初始參數。