以太坊测试链环境node.js版本
為什么80%的碼農都做不了架構師?>>> ??
MAC升級Nodejs和Npm到最新版
第一步,先查看本機node.js版本:
node -v
第二步,清除node.js的cache:
sudo npm cache clean -f
第三步,安裝 n 工具,這個工具是專門用來管理node.js版本的,別懷疑這個工具的名字,是他是他就是他,他的名字就是 "n"
sudo npm install -g n
第四步,安裝最新版本的node.js
sudo n stable
第五步,再次查看本機的node.js版本:
node -v
第六步,更新npm到最新版:
$ sudo npm install npm@latest -g
第七步,驗證
node -v
npm -v
--------------------------------------------------
部署ERC20智能合約
pragma solidity ^0.4.16;
interface tokenRecipient { function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData) external; }
contract TokenERC20 {
? ? //合約地址0xf6482ba598a1a94d82cffefbc21997ba225f2007
? ? //10000,"YanBing3000","YanBing"
? ? // Public variables of the token令牌的公共變量
? ? string public name;
? ? string public symbol;
? ? uint8 public decimals = 18;
? ? //
? ? uint256 public totalSupply;
? ? // This creates an array with all balances這將創建一個包含所有余額的數組
? ? mapping (address => uint256) public balanceOf;
? ? mapping (address => mapping (address => uint256)) public allowance;
? ? // This generates a public event on the blockchain that will notify clients這將在區塊鏈上生成將通知客戶的公共事件
? ? event Transfer(address indexed from, address indexed to, uint256 value);
? ? // This generates a public event on the blockchain that will notify clients
? ? event Approval(address indexed _owner, address indexed _spender, uint256 _value);
? ? // This notifies clients about the amount burnt這會通知客戶有關燒毀的金額
? ? event Burn(address indexed from, uint256 value);
? ? /**
? ? ?* Constructor function構造函數
? ? ?*
? ? ?* Initializes contract with initial supply tokens to the creator of the contract將初始供應代幣的合同初始化為合同的創建者
? ? ?*/
? ? function TokenERC20(
? ? ? ? uint256 initialSupply,
? ? ? ? string tokenName,
? ? ? ? string tokenSymbol
? ? ) public {
? ? ? ? totalSupply = initialSupply * 10 ** uint256(decimals); ?// 使用小數量更新總供應量
? ? ? ? balanceOf[msg.sender] = totalSupply; ? ? ? ? ? ? ? ?// 為創建者提供所有初始令牌
? ? ? ? name = tokenName; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? // 設置名稱以用于顯示目的
? ? ? ? symbol = tokenSymbol; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? // Set the symbol for display purposes
? ? }
? ? /**
? ? ?* Internal transfer, only can be called by this contract內部轉移,只能由本合同調用
? ? ?*/
? ? function _transfer(address _from, address _to, uint _value) internal {
? ? ? ? // Prevent transfer to 0x0 address. Use burn() instead防止轉移到0x0地址。請改用burn()
? ? ? ? require(_to != 0x0);
? ? ? ? // Check if the sender has enough
? ? ? ? require(balanceOf[_from] >= _value);
? ? ? ? // Check for overflows
? ? ? ? require(balanceOf[_to] + _value >= balanceOf[_to]);
? ? ? ? // Save this for an assertion in the future
? ? ? ? uint previousBalances = balanceOf[_from] + balanceOf[_to];
? ? ? ? // Subtract from the sender
? ? ? ? balanceOf[_from] -= _value;
? ? ? ? // Add the same to the recipient
? ? ? ? balanceOf[_to] += _value;
? ? ? ? emit Transfer(_from, _to, _value);
? ? ? ? // Asserts are used to use static analysis to find bugs in your code. They should never fail
? ? ? ? assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
? ? }
? ? /**
? ? ?* Transfer tokens
? ? ?*
? ? ?* Send `_value` tokens to `_to` from your account
? ? ?*
? ? ?* @param _to The address of the recipient
? ? ?* @param _value the amount to send
? ? ?*/
? ? function transfer(address _to, uint256 _value) public returns (bool success) {
? ? ? ? _transfer(msg.sender, _to, _value);
? ? ? ? return true;
? ? }
? ? /**
? ? ?* Transfer tokens from other address
? ? ?*
? ? ?* Send `_value` tokens to `_to` on behalf of `_from`
? ? ?*
? ? ?* @param _from The address of the sender
? ? ?* @param _to The address of the recipient
? ? ?* @param _value the amount to send
? ? ?*/
? ? 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;
? ? ? ? emit Approval(msg.sender, _spender, _value);
? ? ? ? return true;
? ? }
? ? /**
? ? ?* ?為其他地址設置津貼并通知
? ? ?* @param _spender The address authorized to spend 授權花費的地址
? ? ?* @param _value the max amount they can spend 他們可以花費的最大金額
? ? ?* @param _extraData some extra information to send to the approved contract 一些額外的信息發送到批準的合同
? ? ?*/
? ? 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;
? ? ? ? }
? ? }
? ? /**
? ? ?* Destroy tokens 銷毀令牌
? ? ?* 來自系統的令牌不可逆轉
? ? ?* 燒錢的金額
? ? ?*/
? ? function burn(uint256 _value) public returns (bool success) {
? ? ? ? require(balanceOf[msg.sender] >= _value); ? // 檢查發件人是否有足夠的
? ? ? ? balanceOf[msg.sender] -= _value; ? ? ? ? ? ?// Subtract from the sender
? ? ? ? totalSupply -= _value; ? ? ? ? ? ? ? ? ? ? ?// Updates totalSupply
? ? ? ? emit Burn(msg.sender, _value);
? ? ? ? return true;
? ? }
? ? /**
? ? ?* Destroy tokens from other account 從其他帳戶銷毀令牌
? ? ?*/
? ? function burnFrom(address _from, uint256 _value) public returns (bool success) {
? ? ? ? require(balanceOf[_from] >= _value); ? ? ? ? ? ? ? ?// Check if the targeted balance is enough
? ? ? ? require(_value <= allowance[_from][msg.sender]); ? ?// Check allowance
? ? ? ? balanceOf[_from] -= _value; ? ? ? ? ? ? ? ? ? ? ? ? // Subtract from the targeted balance
? ? ? ? allowance[_from][msg.sender] -= _value; ? ? ? ? ? ? // Subtract from the sender's allowance
? ? ? ? totalSupply -= _value; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?// Update totalSupply
? ? ? ? emit Burn(_from, _value);
? ? ? ? return true;
? ? }
}
--------------------------------------------------
啟動node.js項目
mac終端
$ cd /Users/shijun/Desktop/nodejsWorkspace
$ git clone http://www.github.com/peopleName/projectName
WebStorm命令行
$ npm install
$ npm install koa
$ node index.js
訪問 http://localhost:3000
--------------------------------------------------
保存你的私鑰(發行者) 123456
0x1f5dacd2dc047570c6d068d5c6502a80df9f45a8b4c98fa11a692fa98dc8a1fc
UTC--2018-11-23T08_53_33.601Z--2e729a99eB5ee1f791B0FbDdcaa38A5d7E7a56D7
/Users/shijun/Desktop/word/membersheep/項目/sheepCoin/UTC--2018-11-23T08_53_33.601Z--2e729a99eB5ee1f791B0FbDdcaa38A5d7E7a56D7
保存你的私鑰 123456
需要在metamask中Add Token,Token的合約地址是:0xf6482ba598a1a94d82cffefbc21997ba225f2007
0x07a19997045edd19959e5628e02e0bc4d49b67e34c8ccefef0dc7e6a39921e77
UTC--2018-11-23T09_19_22.461Z--12D7A6ef0CAD3397f7937529413104Fc7a5eEBD7
/Users/shijun/Desktop/word/membersheep/項目/sheepCoin/UTC--2018-11-23T09_19_22.461Z--12D7A6ef0CAD3397f7937529413104Fc7a5eEBD7
轉載于:https://my.oschina.net/duojin/blog/2934650
總結
以上是生活随笔為你收集整理的以太坊测试链环境node.js版本的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 配置docker静态IP地址
- 下一篇: zabbix之 自定义内存使用率监控报警