zoukankan      html  css  js  c++  java
  • 以太坊开发环境(私有链)

    http://truffleframework.com/tutorials

    truffle是以太坊开发框架,采用JavaScript编写,支持智能合约的编译、部署和测试。
    可以使用本地测试网络(ganache、testrpc),公共开发者测试网络(Ropsten、Kovan、Rinkeby),私有网络(私有链)进行测试。

    开发环境

    #安装NodeJs
    curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
    sudo apt-get install -y nodejs
    sudo npm config set registry http://registry.npm.taobao.org
    
    # 安装web框架
    sudo npm install -g express
    
    # 安装Truffle
    sudo npm install -g truffle solhint
    
    # 安装Ganache-cli
    sudo npm install -g ganache-cli
    
    # Ganache-gui
    axel -n 10 https://github.com/trufflesuite/ganache/releases/download/v1.1.0-beta.0/ganache-1.1.0-beta.0-x86_64.AppImage
    chmod 755 ganache-1.1.0-beta.0-x86_64.AppImage
    ./ganache-1.1.0-beta.0-x86_64.AppImage
    
    #通讯端口 127.0.0.1:7545 
    

    智能合约

    # 建立项目目录
    mkdir myToken && cd myToken
    
    # 初始化,生成文件
    truffle init
    
    生成目录结构如下
    myToken
    ├── contracts
    │   └── Migrations.sol
    ├── migrations
    │   └── 1_initial_migration.js
    ├── test
    ├── truffle-config.js
    └── truffle.js
    
    contracts  ['kɒntrækts]  合约
    migration [maɪ'greɪʃ(ə)n] 迁移
    
    # 合约目录编写helloworld.sol程序
    pragma solidity ^0.4.18;
    
    contract hello {
        string greeting;
        
        function hello(string _greeting) public {
            greeting = _greeting;
        }
    
        function say() constant public returns (string) {
            return greeting;
        }
    }
    
    # 编译
    truffle compile
    Compiling ./contracts/HelloWorld.sol...
    Writing artifacts to ./build/contracts
    
    # 解锁用户
    > personal.unlockAccount(eth.accounts[0], "me", 1000000)
    true
    
    ####demo程序
    truffle unbox webpack
    truffle compile --network private
    
    # truffle.js
        private: {
          network_id: 123,
          host: "10.0.70.22",
          port: 8545,
          gas:  3000000,  // gasLimit 不要超过块默认的gasLimit
          gasPrice: 1000000,
          from: "0x6700cbea6dfe938b3863938028e71fbf4ef4fa9a"
        },
        
        /*
        Gas由两个部分组成: 限制(Gas limit)和价格(Gas Price)。
        Gas Limit 是用户愿意为执行某个操作或确认交易支付的最大Gas量(最少21,000)。
        Gas Price 是 Gwei 的数量,用户愿意花费于每个 Gas 单位的价钱。
        当进行每笔交易时,发送人设定Gas Limit 和Gas Price,将 Gas Limit*Gas Price ,就得到了ETH交易佣金的成本。
        Wei是最小的 ETH 单位,一个ETH 等于一千 Finney,一百万 Szabo,十亿Gwei和百万万亿 Wei 。
        */
        
    npm run dev
    
  • 相关阅读:
    说说那些低级错误
    vue双向数据绑定
    妙用$.extend
    写一个限制执行次数的函数
    强类型语言不好的地方,比如这样:
    form表单里的坑
    Java Day 09
    Java Day 08
    Java Day 07
    Java Day 06
  • 原文地址:https://www.cnblogs.com/liujitao79/p/8426960.html
Copyright © 2011-2022 走看看