* 우분투 터미널 접속
1. git 설치
$ sudo apt-get install git
2. ethereum 설치
$ git clone https://github.com/ethereum/go-ethereum.git
3.Go & C complier install
$ sudo apt-get install -y build-essential libgmp3-dev golang git tree
4. cd go-ethereum
$ make geth
5. geth version check
/go-ethereum$ ./build/bin/geth version
Geth
Version: 1.5.5-stable
Git Commit: ff07d54843ea7ed9997c420d216b4c007f9c80c3
Protocol Versions: [63 62]
Network Id: 1
Go Version: go1.6.2
OS: linux
GOPATH=
GOROOT=/usr/lib/go-1.6
6. geth copy(location : go-ethereum)
$ sudo cp build/bin/geth /usr/local/bin/
7. path setting check
$ which geth
/usr/local/bin/geth
================================================================================
* Geth 기동
1. home/account/test_data_geth
$ mkdir test_data_geth
2. Creation genesis file (ver 1.6.x ~ 생성)
genesis.json
{
"nonce":"0x0000000000000042",
"timestamp":"0x0",
"parentHash":"0x0000000000000000000000000000000000000000000000000000000000000000",
"extraData":"0x0",
"gasLimit":"0x80000000",
"difficulty":"0x4000",
"mixhash":"0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase":"0x3333333333333333333333333333333333333333",
"alloc":{}
}
3. geth format
$ geth --datadir /home/owthit/test_data_geth init /home/owthit/test_data_geth/genesis.json
I0122 18:56:36.507891 cmd/utils/flags.go:615] WARNING: No etherbase set and no accounts found as default
I0122 18:56:36.507974 ethdb/database.go:83] Allotted 128MB cache and 1024 file handles to /home/owthit/test_data_geth/geth/chaindata
I0122 18:56:36.515644 ethdb/database.go:176] closed db:/home/owthit/test_data_geth/geth/chaindata
I0122 18:56:36.515697 ethdb/database.go:83] Allotted 128MB cache and 1024 file handles to /home/owthit/test_data_geth/geth/chaindata
I0122 18:56:36.520115 cmd/geth/chaincmd.go:131] successfully wrote genesis block and/or chain rule set: 04d8be6fcee0e7706d1693b818d85b2f55352a917b2fc7a6806b33caa0e469b5
4. geth execution
$ geth --networkid 4649 --nodiscover --maxpeers 0 --datadir /home/owthit/test_data_geth console 2>> /home/owthit/test_data_geth/geth.log
Welcome to the Geth JavaScript console!
instance: Geth/v1.5.5-stable-ff07d548/linux/go1.6.2
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
>
=================================================================================
* Geth Ether 송금 by test network
0. 채굴
> eth.accounts
> eth.coinbase
0.1 채굴자변경
> miner.setEtherbase(eth.accounts[1])
1. 계좌생성 Type 1
> personal.newAccount("bompapa")
"0x4f748372302fb177ea2036c13d064225f63021eb"
> personal.newAccount("bommam")
"0xdfb6aa5643759ec1a1b3f31a1a78689645e2fa91"
> personal.newAccount("bom")
"0xd1d15cdfce6db3da12970d3c67216f14d1cd61bf"
2. 계좌생성 Type 2 (toto)
$ geth --datadir /home/owthit/test_data_geth account new
Your new account is locked with a password. Please give a password. Do not forget this password.
Passphrase:
Repeat passphrase:
Address: {c71d79251ad51ba6bd094521eae632957035fabd}
$ geth --datadir /home/owthit/test_data_geth account list
3. 잔고확인
> eth.getBalance(eth.accounts[0])
4. 블록확인
> eth.blockNumber
5. 채굴시작
> miner.start(1)
6. 단위변경(wei -> ether)
> web3.fromWei(eth.getBalance(eth.accounts[0]),"ether")
7. 채굴종료
> miner.stop()
8. 송금
> eth.sendTransaction({from:eth.accounts[0], to:eth.accounts[1], value:web3.toWei(300,"ether")})
Error: account is locked
at web3.js:3119:20
at web3.js:6023:15
at web3.js:4995:36
at <anonymous>:1:1
에러가 발생하면 출금계좌 잠금 해제 한다.
8.1 계좌잠금 해제(limit 300 second)
> personal.unlockAccount(eth.accounts[0])
Unlock account 0x4f748372302fb177ea2036c13d064225f63021eb
Passphrase:
true
> personal.unlockAccount(eth.accounts[0], "bompapa")
true
8.2 송금 재시도
> eth.sendTransaction({from:eth.accounts[0], to:eth.accounts[1], value:web3.toWei(300,"ether")})
"0x98a677e43a0b61fdc12900bb7fc3a6507f9e99976e8351fcaf9b413c6818c5ea"
8.3 수신자 잔액조회
> eth.getBalance(eth.accounts[1])
0
8.4 송금 상태 확인
> eth.getTransaction("0x98a677e43a0b61fdc12900bb7fc3a6507f9e99976e8351fcaf9b413c6818c5ea")
{
blockHash: "0x0000000000000000000000000000000000000000000000000000000000000000",
blockNumber: null,
from: "0x4f748372302fb177ea2036c13d064225f63021eb",
gas: 90000,
gasPrice: 20000000000,
hash: "0x98a677e43a0b61fdc12900bb7fc3a6507f9e99976e8351fcaf9b413c6818c5ea",
input: "0x",
nonce: 0,
r: "0x779696ed032ba5c0775810f1c9dffec9671f34178d654e48d8240c95983ed17d",
s: "0x6321ea788d60d036252fcf653fcaeb08c4a1c75eaa62b54c579c43edb95a931e",
to: "0xdfb6aa5643759ec1a1b3f31a1a78689645e2fa91",
transactionIndex: null,
v: "0x1b",
value: 300000000000000000000
}
blockNumber: null 은 미처리,계류 중으로 eth.pendingTransactions 에서 확인 가능
8.5 채굴 시작
> miner.start(1)
true
8.6 블록 상택 확인
> eth.pendingTransactions
[]
> eth.getTransaction("0x98a677e43a0b61fdc12900bb7fc3a6507f9e99976e8351fcaf9b413c6818c5ea")
{
blockHash: "0xefae906c77961aa22b07611d75600593d27d15bc96be80f161d210dcb2986443",
blockNumber: 233,
from: "0x4f748372302fb177ea2036c13d064225f63021eb",
gas: 90000,
gasPrice: 20000000000,
hash: "0x98a677e43a0b61fdc12900bb7fc3a6507f9e99976e8351fcaf9b413c6818c5ea",
input: "0x",
nonce: 0,
r: "0x779696ed032ba5c0775810f1c9dffec9671f34178d654e48d8240c95983ed17d",
s: "0x6321ea788d60d036252fcf653fcaeb08c4a1c75eaa62b54c579c43edb95a931e",
to: "0xdfb6aa5643759ec1a1b3f31a1a78689645e2fa91",
transactionIndex: 0,
v: "0x1b",
value: 300000000000000000000
}
8.7 채굴 종료
> miner.stop()
true
8.8 블록 확인
> eth.getBlock(233)
{
difficulty: 146458,
extraData: "0xd783010505846765746887676f312e362e32856c696e7578",
gasLimit: 1710262223,
gasUsed: 21000,
hash: "0xefae906c77961aa22b07611d75600593d27d15bc96be80f161d210dcb2986443",
logsBloom: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
miner: "0x4f748372302fb177ea2036c13d064225f63021eb",
mixHash: "0x2a37d3889604d92379f6d232a73c6847a9d10390e4d6c0f598d267c4e9cf61ea",
nonce: "0x1872609251f1deab",
number: 233,
parentHash: "0xf82bf60309714b3ecdc1a9ce1d89aafccbb414f1eebf9c71a8ad00729496e73a",
receiptsRoot: "0x3e2d22c6fc0c2dfc38be795c6c22b8df27c37cb65230b5c5e0a32957b179c0e4",
sha3Uncles: "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
size: 652,
stateRoot: "0xa0c8bedb7bbcba6e18aa55d8ad19d3fb368baaa7d1c9d8a850581ded507c6fdf",
timestamp: 1516618336,
totalDifficulty: 32323838,
transactions: ["0x98a677e43a0b61fdc12900bb7fc3a6507f9e99976e8351fcaf9b413c6818c5ea"],
transactionsRoot: "0x788f88d2517c3c39ea3c2716147ea9d1dd8ca07cbd34ccbbc5a4f42cc8d7ae8e",
uncles: []
}
8.9 수신자 잔액조회
> eth.getBalance(eth.accounts[1])
> web3.fromWei(eth.getBalance(eth.accounts[1]),"ether")
300
9. Transaction gas( 1=>2 )
9.1 bommam 잠금해제
> personal.unlockAccount(eth.accounts[1],"bommam")
true
9.2 bommam => bom 송금
> eth.sendTransaction({from:eth.accounts[1], to:eth.accounts[2], value:web3.toWei(100,"ether")})
"0x3e86a214ef80a9994f38a80c0dc145c956953c440661f8b5d4fd9a112281d7dd"
9.3 채굴
> eth.pendingTransaction
undefined
> eth.pendingTransactions
[{
blockHash: null,
blockNumber: null,
from: "0xdfb6aa5643759ec1a1b3f31a1a78689645e2fa91",
gas: 90000,
gasPrice: 20000000000,
hash: "0x3e86a214ef80a9994f38a80c0dc145c956953c440661f8b5d4fd9a112281d7dd",
input: "0x",
nonce: 0,
r: "0x53b5dcbb3838cecf598ba2b55e1dc2f8f58fc73e94179bd20eb20428c202a381",
s: "0x38ef4a0a626c84ad88d960e3c41662c935e6543030d7297ae43f00056f71fe8b",
to: "0xd1d15cdfce6db3da12970d3c67216f14d1cd61bf",
transactionIndex: null,
v: "0x1c",
value: 100000000000000000000
}]
> miner.start(1)
true
> eth.pendingTransactions
[]
> miner.stop()
true
> eth.blockNumber
303
9.4 수신자 잔액조회( 1의 gas를 0에게(Etherbase) 지불)
> web3.fromWei(eth.getBalance(eth.accounts[2]),"ether")
100
> web3.fromWei(eth.getBalance(eth.accounts[1]),"ether")
199.99958 => 0.00042 감소
> web3.fromWei(eth.getBalance(eth.accounts[0]),"ether")
1215.00042 => 0.00042 증가
>
10. Background Geth
$ nohup geth --networkid 4649 --nodiscover --maxpeers 0 --datadir /home/owthit/test_data_geth --mine --minerthreads 1 --rpc 2 >> /home/owthit/test_data_geth/geth_bg.log &
[1] 4244
owthit@owthit:~$ nohup: 입력을 무시하고 stderr를 stdout으로 redirecting
10.1 geth 접속
$ geth attach rpc:http://localhost:8545
Welcome to the Geth JavaScript console!
instance: Geth/v1.5.5-stable-ff07d548/linux/go1.6.2
coinbase: 0x4f748372302fb177ea2036c13d064225f63021eb
at block: 350 (Tue, 23 Jan 2018 15:47:07 KST)
modules: eth:1.0 net:1.0 rpc:1.0 web3:1.0
11. JSON-RPC
$ nohup geth --networkid 4649 --nodiscover --maxpeers 0 --datadir /home/owthit/test_data_geth --mine --minerthreads 1 --rpc --rpcaddr "0.0.0.0" --rpcport 8545 --rpccorsdomain "*" --rpcapi "admin,db,eth,degub,miner,netshh,txpool,personal,web3" 2 >> /home/owthit/test_data_geth/geth_rpc.log &
'나 어제 배웠다 > Solidity' 카테고리의 다른 글
로컬에서 Solidity 설치 하기 (0) | 2018.01.31 |
---|---|
우분투 geth Solidity 사용하기 (0) | 2018.01.31 |