이더리움(Ethereum) 기본
in Dev on Blockchain

Go Ethereum
Official Go implementation of the Ethereum protocol
Download: https://ethereum.github.io/go-ethereum/downloads/
sudo apt-get -y update && sudo apt-get -y upgrade
sudo apt-get install nodejs
sudo apt install aptitude
sudo aptitude install npm
https://247cryptonews.com/how-to-install-latest-ethereum-node-on-ubuntu-16-04/
sudo apt-get install software-properties-common
sudo add-apt-repository -y ppa:ethereum/ethereum
sudo add-apt-repository -y ppa:ethereum/ethereum-dev
sudo apt-get update
sudo apt-get install ethereum
@eth-VirtualBox:~$ geth version
Geth Version: 1.8.2-stable
Git Commit: b8b9f7f4476a30a0aaf6077daade6ae77f969960
Architecture: amd64
Protocol Versions: [63 62]
Network Id: 1
Go Version: go1.9.4
Private 네트워크 구축
Geth 초기화 및 실행
genesis.json
{
"config": {
"chainId": 33,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
},
"nonce": "0x0000000000000033",
"timestamp": "0x0",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"gasLimit": "0x8000000",
"difficulty": "0x100",
"mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x3333333333333333333333333333333333333333",
"alloc": {}
}
$ mkdir data_testnet
$ cd data_testnet/
$ vi genesis.json
$ geth --datadir /home/user01/data_testnet/ init /home/user01/data_testnet/genesis.json
이더리움 디렉토리 구조
$ sudo apt-get install tree
$ tree /home/user01/data_testnet
.
├── genesis.json
├── geth
│ ├── chaindata
│ │ ├── 000001.log
│ │ ├── CURRENT
│ │ ├── LOCK
│ │ ├── LOG
│ │ └── MANIFEST-000000
│ └── lightchaindata
│ ├── 000001.log
│ ├── CURRENT
│ ├── LOCK
│ ├── LOG
│ └── MANIFEST-000000
└── keystore
4 directories, 11 files
Geth 실행
$ geth --identity "PrivateNetwork" --datadir "/home/user01/data_testnet/" --port "30303" --rpc --rpcaddr 0.0.0.0 --rpcport "8123" --rpccorsdomain "*" --nodiscover --networkid 1900 --rpcapi "db,eth,net,web3,miner" console 2>> /home/user01/data_testnet/geth.log
계정 생성과 조회
Welcome to the Geth JavaScript console!
instance: Geth/PrivateNetwork/v1.8.2-stable-b8b9f7f4/linux-amd64/go1.9.4
modules: admin:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0
> eth
> eth.accounts
[]
> net.peerCount
0
> personal.newAccount("pass0")
"0x7a8f36c21f1b2f89a9f6c810c1289b88e559f85c"
> personal.newAccount("pass1")
"0xbd2cc6e8c322be5a43c862d39984980076930d0d"
> eth.accounts
["0x7a8f36c21f1b2f89a9f6c810c1289b88e559f85c", "0xbd2cc6e8c322be5a43c862d39984980076930d0d"]
> eth.getBalance(eth.accounts[0])
0
> eth.getBalance(eth.accounts[1])
0
> eth.getBalance(eth.coinbase)
0
채굴
> miner.start()
null
> eth.getBalance(eth.coinbase)
115000000000000000000
> web3.fromWei(eth.getBalance(eth.coinbase))
185
> miner.stop()
true
> eth.blockNumber
37
송금
> personal.unlockAccount(eth.accounts[0])
Unlock account 0x7a8f36c21f1b2f89a9f6c810c1289b88e559f85c
Passphrase:
true
> eth.sendTransaction({from:eth.accounts[0], to:eth.accounts[1], value:web3.toWei(10,"ether")})
"0x8fbfdacc783756decfdd68ecdb4f7f35fdee5fb8b43e23983c7072bf38822ae1"
> eth.sendTransaction({from:eth.accounts[0], to:eth.accounts[1], value:web3.toWei(20,"ether")})
"0x1217431a1fc1d1b1fc1b750fcf84e46f4238044d9d629cca04dbb891c823f97d"
> eth.sendTransaction({from:eth.accounts[0], to:eth.accounts[1], value:web3.toWei(12,"ether")})
"0x1350b63b35a47f5d9f8b553fe08ba82fe6c2709c4505b5e7a063f676bcb95218"
> eth.getTransaction("0x8fbfdacc783756decfdd68ecdb4f7f35fdee5fb8b43e23983c7072bf38822ae1")
{
blockHash: "0x0000000000000000000000000000000000000000000000000000000000000000",
blockNumber: null,
from: "0x7a8f36c21f1b2f89a9f6c810c1289b88e559f85c",
gas: 90000,
gasPrice: 18000000000,
hash: "0x8fbfdacc783756decfdd68ecdb4f7f35fdee5fb8b43e23983c7072bf38822ae1",
input: "0x",
nonce: 0,
r: "0x91626fa3e14ca6407d2928d59059575cb2717ff0baadfb6c397962281c67e198",
s: "0x68b26e0306a6e8ed34360cf6a650ff9ca151f9aba1139c3705cf05f1a0449e80",
to: "0xbd2cc6e8c322be5a43c862d39984980076930d0d",
transactionIndex: 0,
v: "0x66",
value: 10000000000000000000
}
# 채굴되지 않은 트랜잭션 리스트
> eth.pendingTransactions
> miner.start()
null
> eth.pendingTransactions
[]
> miner.stop()
true
> eth.pendingTransactions
[]
> eth.blockNumber
43
> eth.getBlock(43)
{
difficulty: 131328,
extraData: "0xd783010802846765746887676f312e392e34856c696e7578",
gasLimit: 128695843,
gasUsed: 0,
hash: "0xbfb8727fb4b56163f57fa5ebfd8cc677514a6e1e731e08c67a092ee56c1df2f3",
logsBloom: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
miner: "0x7a8f36c21f1b2f89a9f6c810c1289b88e559f85c",
mixHash: "0x646c28605eca9abf3283f7a6e1556431652b6fcba4455a33d780c0f553a736af",
nonce: "0x000510e55c54ad12",
number: 43,
parentHash: "0x53d1e0aa4a211f4e76772eb214fe1afc2be0f965fdedcef80137eafe4e051a43",
receiptsRoot: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
sha3Uncles: "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
size: 536,
stateRoot: "0x3a06000c8690c54e0fccb390958b519b7de12cf0d44c593a9919841cb10c9149",
timestamp: 1527579249,
totalDifficulty: 5673536,
transactions: [],
transactionsRoot: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
uncles: []
}
Peer 연결
$ sudo ifconfig enp0s8 192.168.0.207 netmask 255.255.255.0 up
[sudo] password for user01:
$ sudo route add default gw 192.168.0.1
$ ping 192.168.0.107
$ ifconfig -a
enp0s8 Link encap:Ethernet HWaddr 08:00:27:05:44:dc
inet addr:192.168.0.207 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe05:44dc/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:710 errors:0 dropped:446 overruns:0 frame:0
TX packets:37 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:47898 (47.8 KB) TX bytes:2713 (2.7 KB)
Interrupt:16 Base address:0xd240
> admin.nodeInfo.enode
"enode://b128200b26a55a5aa2b605905b1dfa9be8426cf6d8f73c1a1c0ea89e4d4771a98feead21cc9830b772c559d42b91ee2455fad4402738571cad61f17c93b787ae@[::]:30303?discport=0"
> admin.addPeer("enode://b128200b26a55a5aa2b605905b1dfa9be8426cf6d8f73c1a1c0ea89e4d4771a98feead21cc9830b772c559d42b91ee2455fad4402738571cad61f17c93b787ae@192.168.0.202:30303?discport=0")
> net.peerCount
0
> admin.peers
[]
이더리움 클라이언트 연결
$ geth attach http://192.168.0.207:8123
Welcome to the Geth JavaScript console!
instance: Geth/PrivateNetwork/v1.8.10-stable-eae63c51/linux-amd64/go1.10
coinbase: 0x0ec6a531ce4720abdee547967ea3fdbc9c6df147
at block: 21 (Thu, 31 May 2018 10:41:00 JST)
modules: eth:1.0 miner:1.0 net:1.0 rpc:1.0 web3:1.0
>
Unlock account
$ echo pass0 >> /home/user01/smartcontract_testnet/passwd
$ echo pass1 >> /home/user01/smartcontract_testnet/passwd
$ echo pass2 >> /home/user01/smartcontract_testnet/passwd
$ echo pass3 >> /home/user01/smartcontract_testnet/passwd
--unlock 0,1,2,3
--password /home/user01/smartcontract_testnet/passwd
pragma solidity ^0.4.18;
contract Coursetro {
string fName;
uint age;
function setInstructor(string _fName, uint _age) public {
fName = _fName;
age = _age;
}
function getInstructor() view public returns (string, uint) {
return (fName, age);
}
}
참조
- DCode
- codingground
- 가상화폐리스트 사이트
- Bitcoin Difficulty
- BitNodes
- BitNodes Live Map
- Go Ethereum
- ETH Gas Station
- Mastering Bitcoin