以太坊现在发币很贵,天价手续费,今天我刚刚帮别人发了一个需要250美金的手续费,我真为顾客心疼,但是没办法,人家有需求,GWEI现在稳定都是100多,对应就是200多美金的手续费,天下苦以太坊久以,更可笑的是转账也有差不多100的手续费。
闲话不多说,我们来讲解一下ERC20怎么发币的吧。不会的,我可以帮你。
https://remix.ethereum.org/首先用到是这个,
合约代码是这个pragma solidity ^0.4.16;
interface tokenRecipient { function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData) public; }
contract TokenERC20 {
string public name;
string public symbol;
uint8 public decimals = 8;
uint256 public totalSupply;
mapping (address => uint256) public balanceOf; //
mapping (address => mapping (address => uint256)) public allowance;
event Transfer(address indexed from, address indexed to, uint256 value);
event Burn(address indexed from, uint256 value);
function TokenERC20(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, uint _value) internal {
require(_to != 0x0);
require(balanceOf[_from] >= _value);
require(balanceOf[_to] + _value > balanceOf[_to]);
uint previousBalances = balanceOf[_from] + balanceOf[_to];
balanceOf[_from] -= _value;
balanceOf[_to] += _value;
Transfer(_from, _to, _value);
assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
}
function transfer(address _to, uint256 _value) public returns (bool) {
_transfer(msg.sender, _to, _value);
return true;
}
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
require(_value <= allowance[_from][msg.sender]); // Check allowance
allowance[_from][msg.sender] -= _value;
_transfer(_from, _to, _value);
return true;
}
function approve(address _spender, uint256 _value) public
returns (bool success) {
allowance[msg.sender][_spender] = _value;
return true;
}
function approveAndCall(address _spender, uint256 _value, bytes _extraData) public returns (bool success) {
tokenRecipient spender = tokenRecipient(_spender);
if (approve(_spender, _value)) {
spender.receiveApproval(msg.sender, _value, this, _extraData);
return true;
}
}
function burn(uint256 _value) public returns (bool success) {
require(balanceOf[msg.sender] >= _value);
balanceOf[msg.sender] -= _value;
totalSupply -= _value;
Burn(msg.sender, _value);
return true;
}
function burnFrom(address _from, uint256 _value) public returns (bool success) {
require(balanceOf[_from] >= _value);
require(_value <= allowance[_from][msg.sender]);
balanceOf[_from] -= _value;
allowance[_from][msg.sender] -= _value;
totalSupply -= _value;
Burn(_from, _value);
return true;
}
}
把合约代码复制进去,就可以部署了,
Compile and Deploy ERC20 Contract
Open Remix IDE: https://remix.ethereum.org
img
Select solidity language
img
Create new contract ERC20Token.sol and copy contract code from the bep20 token template here
Modify “name”, “symbol”, “decimals” and “totalSupply” according to your requirements.
img
Compile the ERC20 token contract
a. Step1: Click button to switch to compile page
b. Step2: Select “ERC20Token” contract
c. Step3: Enable “Auto compile” and “optimization”
d. Step4: Click “ABI” to copy the contract abi and save it.
img
Depoy the contract to ETH
a. Step1: Click button to switch to compile button.
b. Step2: Select “Injected Web3”
c. Step3: Select “ERC20Token”
d. Step4: Client “Deploy” button and Metamask will pop up
img
e. Client “confirm” button to sign and broadcast transaction to ETH.
img
至此,发币结束,大家学会了吗?