此隨筆乃本人學習工做記錄,若有疑問歡迎在下面評論,轉載請標明出處。
若是對您有幫助請動動鼠標右下方給我來個贊,您的支持是我最大的動力。
Remix是一個基於瀏覽器的編譯器和IDE,使用戶可以使用Solidity語言構建以太坊合約並調試事務。git
在上一篇文章已經成功的使用代碼講智能合約編譯而且發佈部署到了鏈上,但是在部署 發幣的智能合約 不行,因而另找方法➡️remixgithub
git clone https://github.com/ethereum/remix-ide.git cd remix-ide npm install //可能會出錯多試幾回,網絡問題。 sudo npm run setupremix npm run build npm start
瀏覽器打開: http://127.0.0.1:8080web
pragma solidity 0.4.24; contract SafeMath { function safeSub(uint256 a, uint256 b) internal returns (uint256) { assert(b <= a); return a - b; } function safeAdd(uint256 a, uint256 b) internal returns (uint256) { uint256 c = a + b; assert(c>=a && c>=b); return c; } } contract owned { address public owner; constructor() public { owner = msg.sender; } modifier onlyOwner { require(msg.sender == owner); _; } function transferOwnership(address newOwner) onlyOwner public { if (newOwner != address(0)) { owner = newOwner; } } } contract HEAToken is SafeMath,owned { string public name="C-money"; string public symbol="$$"; uint8 public decimals = 18; uint256 public totalSupply=30000000000000; mapping (address => uint256) public balanceOf; mapping (address => mapping (address => uint256)) public allowance; mapping (address => bool) public frozenAccount; event Transfer(address indexed from, address indexed to, uint256 value); event Freeze(address indexed from, bool frozen); constructor(uint256 initialSupply, string tokenName, string tokenSymbol) public { totalSupply = initialSupply * 10 ** uint256(decimals); balanceOf[msg.sender] = totalSupply; name = tokenName; symbol = tokenSymbol; } function _transfer(address _from, address _to, uint256 _value) internal { require(_to != 0x0); require(_value > 0); require(balanceOf[_from] >= _value); require(balanceOf[_to] + _value > balanceOf[_to]); require(!frozenAccount[_from]); require(!frozenAccount[_to]); uint previousBalances = SafeMath.safeAdd(balanceOf[_from] , balanceOf[_to]); balanceOf[_from] = SafeMath.safeSub( balanceOf[_from] , _value); balanceOf[_to] =SafeMath.safeAdd(balanceOf[_to] , _value); emit Transfer(_from, _to, _value); assert(balanceOf[_from] + balanceOf[_to] == previousBalances); } function transfer(address _to, uint256 _value) public returns (bool success) { _transfer(msg.sender, _to, _value); return true; } function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { require(_to != 0x0); require(_value > 0); require(balanceOf[_from] >= _value); require(balanceOf[_to] + _value > balanceOf[_to]); require(!frozenAccount[_from]); require(!frozenAccount[_to]); require(_value <= allowance[_from][msg.sender]); uint previousBalances = SafeMath.safeAdd(balanceOf[_from] , balanceOf[_to]); allowance[_from][msg.sender] = SafeMath.safeSub(allowance[_from][msg.sender] , _value); balanceOf[_from] = SafeMath.safeSub( balanceOf[_from] , _value); balanceOf[_to] =SafeMath.safeAdd(balanceOf[_to] , _value); assert(balanceOf[_from] + balanceOf[_to] == previousBalances); emit Transfer(_from, _to, _value); return true; } function approve(address _spender, uint256 _value) public returns (bool success) { require(_spender != 0x0); require(_value > 0); require(balanceOf[_spender] >= _value); require(!frozenAccount[msg.sender]); require(!frozenAccount[_spender]); allowance[msg.sender][_spender] = _value; return true; } function freezeMethod(address target, bool frozen) onlyOwner public returns (bool success){ require(target != 0x0); frozenAccount[target] = frozen; emit Freeze(target, frozen); return true; } }
將發幣的智能合約 copy 進去 npm
1.選擇環境爲web3 Provider ,設置爲咱們本身鏈上的地址瀏覽器
2.選擇發佈合約的帳戶網絡
3.配置信息app
結果ide
更多post
在下面咱們還能夠查詢某個帳戶對代幣,以及代幣對基礎信息,用戶之間代幣轉帳等功能。學習
github:https://github.com/ethereum/remix-ide
此隨筆乃本人學習工做記錄,若有疑問歡迎在下面評論,轉載請標明出處。
若是對您有幫助請動動鼠標右下方給我來個贊,您的支持是我最大的動力。