Solidity
使用 MEW 測試自定義 ERC20 代幣
在提問之前,我想列出我的開發環境配置:
- 我正在使用 Remix 線上 Solidity IDE 進行編碼
- 我的契約正在使用 RPC 的本地 PC 上執行(Remix 中的 web3 提供程序選項)
- 我設置 MEW 在我的 http:127.0.0.1:8545 節點上執行
我設法部署了我的 ERC20 代幣合約,將其添加到顯示該賬戶目前金額的 MEW 列表中;然而,即使在合約中我將 10000000 設置為代幣的初始供應量,MEW 仍將“0.000 1e-11 RC”顯示為總量。我錯過了什麼?
編碼:
pragma solidity ^0.4.0; contract UnclearlyToken { string public constant name = "Unclearly"; string public constant symbol = "UC"; uint8 public constant decimals = 18; uint totalAmount = 10000000; mapping (address => uint256) public balances; mapping(address => mapping (address => uint256)) allowed; event Transfer(address indexed _from, address indexed _to, uint _value); event Approval(address indexed _owner, address indexed _spender, uint _value); function UnclearlyToken() { balances[msg.sender] = totalAmount; } function totalSupply() constant returns(uint) { return totalAmount; } function balanceOf(address _owner) constant returns(uint256) { return balances[_owner]; } function transfer(address _to, uint _value) returns (bool success) { if(balances[msg.sender] >= _value && _value > 0 && balances[_to] + _value > balances[_to]) { balances[msg.sender] -= _value; balances[_to] += _value; Transfer(msg.sender, _to, _value); return true; } return false; } function transferFrom(address _from, address _to, uint _value) returns (bool success) { if(balances[_from] >= _value && _value > 0 && balances[_to] + _value > balances[_to] && allowed[_from][msg.sender] >= _value) { balances[_from] -= _value; balances[_to] += _value; Transfer(_from, _to, _value); return true; } return false; } function approve(address _spender, uint _value) returns (bool success) { allowed[msg.sender][_spender] = _value; Approval(msg.sender, _spender, _value); return true; } function allowance(address _owner, address _spender) constant returns (uint remaining) { return allowed[_owner][_spender]; } }
水電側:
好的,對不起這個問題,這很簡單。您只需要更改令牌的小數。有關更多詳細資訊,請參閱此討論:Float not allowed in solidity vs decimal places ask for token contract