我想测试与我的客户端一起发送ERC20令牌,所以我需要在一个测试网上创建一些令牌。我正在使用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,它就能工作。显然,remix重新推荐使用Constructor并使用类名作为废弃的调用,但是如果这样做,您将无法部署您的合同。听起来像虫子?
发布于 2019-03-05 11:38:52
您不必在构造函数前面添加函数关键字。它不会在部署期间出现,因为您将它声明为契约函数。删除函数关键字并尝试。肯定会成功的。
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
}发布于 2018-07-04 16:53:19
转到右上角的“编译”选项卡,单击“编译”按钮,然后勾选“自动编译”复选框。
当您返回部署时,应该有文本框来传递初始参数。
https://ethereum.stackexchange.com/questions/52677
复制相似问题