区块链笔记3

多节点组成私有网络与多重签名钱包:

一台电脑可以构建一个私有节点,因此多个私有节点需要两台及以上电脑才能实现,选取两台电脑,分别创建一个私有节点,启动私有节点成功后进入控制台输入admin.nodeInfo获取当前私有节点的信息:比如如下信息是电脑A的私有节点信息

 admin.nodeInfo
{
  enode: "enode://f9315a2a7689b497b79d7cf96dc30c2712c153217b3c5b36f84b07ae47fdc78dcb21f97a2b6b57c0cba0d033eae39261c99138170da30eb0df06eaead3a4dbb5@0.0.0.0:30303",
  id: "f9315a2a7689b497b79d7cf96dc30c2712c153217b3c5b36f84b07ae47fdc78dcb21f97a2b6b57c0cba0d033eae39261c99138170da30eb0df06eaead3a4dbb5",
  ip: "0.0.0.0",
  listenAddr: "[::]:30303",
  name: "Geth/mydev/v1.8.2-stable-b8b9f7f4/windows-amd64/go1.9.2",
  ports: {
    discovery: 30303,
    listener: 30303
  },
  protocols: {
    eth: {
      config: {
        chainId: 15,
        eip150Hash: "0x0000000000000000000000000000000000000000000000000000000000000000",
        eip155Block: 0,
        eip158Block: 0,
        homesteadBlock: 0
      },
      difficulty: 28940279,
      genesis: "0xb34c4f7ce1e629caf31754c1ef557dfbfa4007a4cb1bfb0c8eb89e56d8140429",
      head: "0x403c186f2d08aa040e2affaf6241177858bb20812ef74f975a2e4abe38ee7bfc",
      network: 101
    }
  }
}
其中:
enode://f9315a2a7689b497b79d7cf96dc30c2712c153217b3c5b36f84b07ae47fdc78dcb21f97a2b6b57c0cba0d033eae39261c99138170da30eb0df06eaead3a4dbb5@0.0.0.0:30303

就是构建多节点所需的信息,然后把@0.0.0.0:30303中的0.0.0.0换成电脑IPV4地址即可

打开电脑B,同时启动私有节点,打开Mist或者在命令行窗口进入控制台通过命令admin.addPeer("")把上面的enode全部复制到括号,回车返回true表示添加节点成功;然后也可以通过命令admin.peers查看节点是否是刚刚添加的节点


多重签名钱包:

进入Mist界面,点击新增钱包


填入所有者地址:即合伙人的钱包地址,然后点击创建即可创建多重签名钱包,这样在发送数值达到或者超过预设额度后则需要其他所有者同意该交易才能顺利进行


智能合约代币编写以及部署使用:

进入官方文档:http://solidity.readthedocs.io/en/latest/introduction-to-smart-contracts.html有如下代码

pragma solidity ^0.4.21;

contract Coin {
    // The keyword "public" makes those variables
    // readable from outside.
    address public minter;
    mapping (address => uint) public balances;

    // Events allow light clients to react on
    // changes efficiently.
    event Sent(address from, address to, uint amount);

    // This is the constructor whose code is
    // run only when the contract is created.
    function Coin() public {
        minter = msg.sender;
    }

    function mint(address receiver, uint amount) public {
        if (msg.sender != minter) return;
        balances[receiver] += amount;
    }

    function send(address receiver, uint amount) public {
        if (balances[msg.sender] < amount) return;
        balances[msg.sender] -= amount;
        balances[receiver] += amount;
        emit Sent(msg.sender, receiver, amount);
    }
}

点击Mist界面右上角的合约,然后部署新合约,如下图


在合约原始代码处copy上诉代码,其中有个错误,

 emit Sent(msg.sender, receiver, amount);//删掉此行中的emit即可

部署成功后,可以在选择函数处选择要操作的函数,Mint为挖矿,send为发送代币,新增的合约只能在已经部署该合约的帐号上进行操作,如果其他账户想通过该合约进行相关操作,需要新增观察合约,填写该合约地址即可实现相应的合约功能

其中发送代币操作,合约部署等都需要在挖矿情况下才能得到确认生效

你可能感兴趣的:(区块链)