以太坊 ERC20 代币合约 returns 0.00 代币余额,当它通过重新混合部署的合约地址添加到钱包时
Ethereum ERC20 Token contract returns 0.00 token balance when it added to wallet by remix deployed contract address
我尝试在混音编辑器中创建一个 ERC20 代币智能合约,如下所示。
我能够部署智能合约并且保留所有变量,但是当我将我的合约添加到 wallet.ethereum.org 合约页面(在 watch 代币下)时,代币余额显示为 0 而令牌符号、名称、小数位都正确注册。
代码片段:
pragma solidity ^0.4.19;
//import './IERC20.sol';
//contract FuncToken is IERC20 {
interface IERC20 {
function totalsupply() constant returns(uint256 total);
function balanceof(address _owner)constant returns(uint256 balance);
function transfer(address to, uint256 value)returns(bool success);
function transferfrom(address from,address to,uint256 _value) returns(bool success);
function approve(address spender,uint256 value)returns(bool success);
function allowance(address owner,address spender)constant returns(uint256 remaining);
event Transfer(address indexed from,address indexed to,uint256 _value);
event Approval(address indexed owner,address indexed spender,uint256 _value);
}
contract PerlToken{
uint public constant _totalSupply=100000;
string public constant symbol="perl";
string public constant name="PERL Token";
uint8 public constant decimals=3;
mapping(address=>uint256) balances;
mapping(address=>mapping(address =>uint256)) allowed;
function FuncToken(){
balances[msg.sender]=_totalSupply;
}
function totalsupply() constant returns(uint256 total){
return _totalSupply;
}
function balanceof(address _owner)constant returns(uint256 balance){
return balances[_owner];
}
function transfer(address to, uint256 value)returns(bool success){
require(
balances[msg.sender]>=_value && _value>0
);
balances[msg.sender] -=_value;
balances[_to] +=+_value;
Transfer(msg.sender,_to,_value);
return true;
}
function transferfrom(address from,address to,uint256 _value) returns(bool success){
require(
allowed[_from][msg.sender]>=_value
&& balances[_from]>=_value
&& _value>0
);
balances[_from]-=_value;
balances[_to]+= _value;
allowed[_from][msg.sender]-=_value;
Transfer(_from,_to,_value);
return true;
}
function approve(address spender,uint256 value)returns(bool success){
allowed[msg.sender][_spender]=_value;
Approval(msg.sender,_spender,_value);
return true;
}
function allowance(address owner,address spender)constant returns(uint256 remaining){
allowed[_owner][_spender];
}
event Transfer(address indexed from,address indexed to,uint256 _value);
event Approval(address indexed owner,address indexed spender,uint256 _value);
}
您在部署合同时没有设置余额。我相信您打算使用 FuncToken
作为您的构造函数。
我清理了合同(我在这里使用的是 0.4.17),部署它,然后导入到 Mist 中。现在看起来不错。
pragma solidity ^0.4.17;
//import './IERC20.sol';
//contract FuncToken is IERC20 {
interface IERC20 {
function totalSupply() constant returns(uint256 total);
function balanceOf(address _owner)constant returns(uint256 balance);
function transfer(address to, uint256 value)returns(bool success);
function transferFrom(address from,address to,uint256 _value) returns(bool success);
function approve(address spender,uint256 value)returns(bool success);
function allowance(address owner,address spender)constant returns(uint256 remaining);
event Transfer(address indexed from,address indexed to,uint256 _value);
event Approval(address indexed owner,address indexed spender,uint256 _value);
}
contract PerlToken{
uint public constant _totalSupply=100000;
string public constant symbol="perl";
string public constant name="PERL Token";
uint8 public constant decimals=3;
mapping(address=>uint256) balances;
mapping(address=>mapping(address =>uint256)) allowed;
function PerlToken(){
balances[msg.sender]=_totalSupply;
}
function totalSupply() constant returns(uint256 total){
return _totalSupply;
}
function balanceOf(address _owner)constant returns(uint256 balance){
return balances[_owner];
}
function transfer(address _to, uint256 _value)returns(bool success){
require(
balances[msg.sender]>=_value && _value>0
);
balances[msg.sender] -=_value;
balances[_to] +=+_value;
Transfer(msg.sender,_to,_value);
return true;
}
function transferFrom(address _from,address _to,uint256 _value) returns(bool success){
require(
allowed[_from][msg.sender]>=_value
&& balances[_from]>=_value
&& _value>0
);
balances[_from]-=_value;
balances[_to]+= _value;
allowed[_from][msg.sender]-=_value;
Transfer(_from,_to,_value);
return true;
}
function approve(address _spender,uint256 _value)returns(bool success){
allowed[msg.sender][_spender]=_value;
Approval(msg.sender,_spender,_value);
return true;
}
function allowance(address _owner,address _spender)constant returns(uint256 remaining){
allowed[_owner][_spender];
}
event Transfer(address indexed from,address indexed to,uint256 _value);
event Approval(address indexed owner,address indexed spender,uint256 _value);
}
我尝试在混音编辑器中创建一个 ERC20 代币智能合约,如下所示。
我能够部署智能合约并且保留所有变量,但是当我将我的合约添加到 wallet.ethereum.org 合约页面(在 watch 代币下)时,代币余额显示为
代码片段:
pragma solidity ^0.4.19;
//import './IERC20.sol';
//contract FuncToken is IERC20 {
interface IERC20 {
function totalsupply() constant returns(uint256 total);
function balanceof(address _owner)constant returns(uint256 balance);
function transfer(address to, uint256 value)returns(bool success);
function transferfrom(address from,address to,uint256 _value) returns(bool success);
function approve(address spender,uint256 value)returns(bool success);
function allowance(address owner,address spender)constant returns(uint256 remaining);
event Transfer(address indexed from,address indexed to,uint256 _value);
event Approval(address indexed owner,address indexed spender,uint256 _value);
}
contract PerlToken{
uint public constant _totalSupply=100000;
string public constant symbol="perl";
string public constant name="PERL Token";
uint8 public constant decimals=3;
mapping(address=>uint256) balances;
mapping(address=>mapping(address =>uint256)) allowed;
function FuncToken(){
balances[msg.sender]=_totalSupply;
}
function totalsupply() constant returns(uint256 total){
return _totalSupply;
}
function balanceof(address _owner)constant returns(uint256 balance){
return balances[_owner];
}
function transfer(address to, uint256 value)returns(bool success){
require(
balances[msg.sender]>=_value && _value>0
);
balances[msg.sender] -=_value;
balances[_to] +=+_value;
Transfer(msg.sender,_to,_value);
return true;
}
function transferfrom(address from,address to,uint256 _value) returns(bool success){
require(
allowed[_from][msg.sender]>=_value
&& balances[_from]>=_value
&& _value>0
);
balances[_from]-=_value;
balances[_to]+= _value;
allowed[_from][msg.sender]-=_value;
Transfer(_from,_to,_value);
return true;
}
function approve(address spender,uint256 value)returns(bool success){
allowed[msg.sender][_spender]=_value;
Approval(msg.sender,_spender,_value);
return true;
}
function allowance(address owner,address spender)constant returns(uint256 remaining){
allowed[_owner][_spender];
}
event Transfer(address indexed from,address indexed to,uint256 _value);
event Approval(address indexed owner,address indexed spender,uint256 _value);
}
您在部署合同时没有设置余额。我相信您打算使用 FuncToken
作为您的构造函数。
我清理了合同(我在这里使用的是 0.4.17),部署它,然后导入到 Mist 中。现在看起来不错。
pragma solidity ^0.4.17;
//import './IERC20.sol';
//contract FuncToken is IERC20 {
interface IERC20 {
function totalSupply() constant returns(uint256 total);
function balanceOf(address _owner)constant returns(uint256 balance);
function transfer(address to, uint256 value)returns(bool success);
function transferFrom(address from,address to,uint256 _value) returns(bool success);
function approve(address spender,uint256 value)returns(bool success);
function allowance(address owner,address spender)constant returns(uint256 remaining);
event Transfer(address indexed from,address indexed to,uint256 _value);
event Approval(address indexed owner,address indexed spender,uint256 _value);
}
contract PerlToken{
uint public constant _totalSupply=100000;
string public constant symbol="perl";
string public constant name="PERL Token";
uint8 public constant decimals=3;
mapping(address=>uint256) balances;
mapping(address=>mapping(address =>uint256)) allowed;
function PerlToken(){
balances[msg.sender]=_totalSupply;
}
function totalSupply() constant returns(uint256 total){
return _totalSupply;
}
function balanceOf(address _owner)constant returns(uint256 balance){
return balances[_owner];
}
function transfer(address _to, uint256 _value)returns(bool success){
require(
balances[msg.sender]>=_value && _value>0
);
balances[msg.sender] -=_value;
balances[_to] +=+_value;
Transfer(msg.sender,_to,_value);
return true;
}
function transferFrom(address _from,address _to,uint256 _value) returns(bool success){
require(
allowed[_from][msg.sender]>=_value
&& balances[_from]>=_value
&& _value>0
);
balances[_from]-=_value;
balances[_to]+= _value;
allowed[_from][msg.sender]-=_value;
Transfer(_from,_to,_value);
return true;
}
function approve(address _spender,uint256 _value)returns(bool success){
allowed[msg.sender][_spender]=_value;
Approval(msg.sender,_spender,_value);
return true;
}
function allowance(address _owner,address _spender)constant returns(uint256 remaining){
allowed[_owner][_spender];
}
event Transfer(address indexed from,address indexed to,uint256 _value);
event Approval(address indexed owner,address indexed spender,uint256 _value);
}