使用remix发布部署 发币 智能合约

时间:2022-08-08 23:11:26

Remix是一个基于浏览器的编译器和IDE,使用户能够使用Solidity语言构建以太坊合约并调试事务。

在上一篇文章已经成功的使用代码讲智能合约编译并且发布部署到了链上,可是在部署 发币的智能合约 不行,于是另找方法➡️remix

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:8080

发币的智能合约

pragma solidity 0.4.;
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()) {
owner = newOwner;
}
}
}
contract HEAToken is SafeMath,owned {
string public name="C-money";
string public symbol="$$";
uint8 public decimals = ;
uint256 public totalSupply=;
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 * ** uint256(decimals);
balanceOf[msg.sender] = totalSupply;
name = tokenName;
symbol = tokenSymbol;
}
function _transfer(address _from, address _to, uint256 _value) internal {
require(_to != 0x0);
require(_value > );
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 > );
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 > );
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 进去

使用remix发布部署 发币 智能合约

部署合约

1.选择环境为web3 Provider ,设置为我们自己链上的地址

使用remix发布部署 发币 智能合约

2.选择发布合约的账户

使用remix发布部署 发币 智能合约

3.配置信息

使用remix发布部署 发币 智能合约

结果

使用remix发布部署 发币 智能合约

更多

在下面我们还可以查询某个账户对代币,以及代币对基础信息,用户之间代币转账等功能。

使用remix发布部署 发币 智能合约

github:https://github.com/ethereum/remix-ide

此随笔乃本人学习工作记录,如有疑问欢迎在下面评论,转载请标明出处。

如果对您有帮助请动动鼠标右下方给我来个赞,您的支持是我最大的动力。