블록체인 애플리케이션 개발 실전 입문 2-3 4장

in #gasprice6 years ago (edited)

이제 geth콘솔에서 계정을 만들고 ether를 송금해보자

이더리움에는 두가지 종류의 계정이 있다.

  1. EOA는 일반 사용자가 사용하는 계정으로 비킬키를 관리한다. Ether를 송금하거나 계약을 실행할 수 있다.
  2. Contrat계정은 이름처럼 계양용 계정으로, 계약을 블록체인에 배포할 때 만들어지는 계정으로 다른 계정으로부터 메시지를 수신해 코드를 실행하고 계정에 메시지를 보낼 수 있다.

personal.newAccount 명령어를 이용하여 EOA를 생성한다.

$ personal.newAccount("pass0")

eth.accounts로 계정을 확인해보자

$ eth.accounts

계정을 하나 더 추가해보자

Exit로 콘솔을 종료하면 geth프로세스도 종료된다. Ps명령으로 geth프로세스가 동작하지 않는 것을 확인할 수 있다.

$ ps -eaf | grep geth

터미널 창에서도 계정을 생성할 수 있다.

$ geth --datadir /Users/Humanscape/Desktop/data_testnet account new

계정확인도 가능하다.


계정 생성이 완료 되었으니 채굴을 시작하겠다.

이더리움에서 채굴에 성공했을 때 보상을 받는 계정을 Etherbase라고 한다. 기본적으로 eth.account[0]이 설정된다.

$ eth.coinbase
$ eth.accounts

잔고 확인은 eth.getBalance 명령으로 알 수 있다.

$ eth.getBalance(eth.accounts[0])
$ eth.blockNumber

이제 채굴을 시작한다.

$ miner.start(1)

Geth콘솔에서 빠져나와 로그 파일을 확인해보면 mining중인것을 알수있다.

$ tail -100f -~/data_testnet/geth.log

채굴을 하고 있는지 해시 속도, 블록의길이 등을 확인할수있다.

$ eth.mining
$ eth.hashhrate
$ eth.blockNumber

어느 정도 채굴이 되었으면 채굴을 중단해보겠다.

$ miner.stop()
$ eth.mining
$ eth.hashhrate
$ eth.blockNumber

Eth.getBalance(eth.accounts[0])의 명령어로 coinbase의 잔고를 확인해보자
숫자의 단위는 wei로 표시가 된다. 아래의 코드는 wei를 ether로 변환해서 보여준다.

$ web3.fromWei(eth.getBalance(eth.accounts[0],"ether")

위에 eth.blockNumber로 1197블록이 있고 getBalance로 5985ether가 있는 것을 확인하였다.
현재 채굴로 받을 수 있는 보상은 1블록에 5ether이다. 블록의 길이가 1197이므로 1197x5=5985 임을 확인할 수 있다.


채굴을 통해 ether를 생성했으니 송금을 해보자.

송금을 하기 위해선 계정 잠금을 먼저 해제해야한다. 해제의 유효시간은 기본적으로 300초이다.

$ personal.unlockAccount(eth.accounts[0], "pass0")

잠금을 해제했으니 accounts[0] -> accounts[1]로 10ether를 송금해보자.

$eth.sendTransaction({from:eth.accounts[0], to:eth.accounts[1], value:web3.toWei(10,"ether")})

송금 후 정상적으로 송금이 됐는지 잔고 확인을 해보자.

$ eth.getBalance(eth.accounts[1])

잔고가 0일 것이다.
sendTransaction으로 트랜잭션이 발생해도 처리가 실행되지 않는다. 블록체인에서 블록 안에 트랜잭션이 포함될 때 트랜잭션의 내용이 실행된다. 트랜잭션 상태를 확인해 보자.

$ eth.getTransaction("sendTransaction해시값")

blockNumber가 null인 상태다. Null은 블록에 포함되지 않았다는 것을 포함한다.
eth.pendingTransactions로 현재 계류 중인 트랜잭션을 확인할 수 있다.

미처리된 트랜잭션을 처리하기 위해서는 채굴을 재개해야한다.
재개한 후에 pendingTransactions로 미처리 트랜잭션 내용이 남아 있는지 확인한다.
eth.account[1]로 10이더가 전송 됐는지 확인해보자.

$ miner.start(1)
$ eth.pendingTransactions
$ eth.getBalance(eth.account[1])

getTransaction으로 bloackNumver의 값을 확인해보자

$ eth.getTransaction("sendTransaction해시값")

1198번째 blockNumber 값으로 할당된 것을 확인했다.
1198번째 블록 정보를 확인해보자

$ eth.getBlock(1198)

이번엔 accounts[1] -> accounts[2]로 5ether를 송금해보자.

전송결과 accounts[2]의 잔고가 5ether가 아닌 4.99958ether이다.

거래 트랜잭션을 확인해 보자

여기서 gas와 gasprice를 확인해보자

지불한 수수료 / gasPrice를 해보면 420000000000000 / 20000000000 = 21000gas이다.
실제 지불한 gas는 21000이다. 트랜잭션에서 지정한 gas의 값 90000보다 작은 것을 확인할 수 있다.

처음에 [0] -> [1] 10이더를 송금할 때 생긴 수수료는 [0]이 etherbase임으로 해당 수수료를 자기가 받게 된다. 따라서 수수료가 발생하지 않는 것처럼 보였었다.


이상 이더의 계정을 생성, 채굴, 송금해 보았다.

Sort:  

Congratulations @loowin! You received a personal award!

Thank you for the witness votes you made to support your Steem community and for keeping the Steem blockchain decentralized

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Do not miss the last post from @steemitboard:

Use your witness votes and get the Community Badge
Vote for @Steemitboard as a witness to get one more award and increased upvotes!

Congratulations @loowin! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

Award for the number of upvotes

Click on the badge to view your Board of Honor.
If you no longer want to receive notifications, reply to this comment with the word STOP

Do not miss the last post from @steemitboard!


Participate in the SteemitBoard World Cup Contest!
Collect World Cup badges and win free SBD
Support the Gold Sponsors of the contest: @good-karma and @lukestokes


Do you like SteemitBoard's project? Then Vote for its witness and get one more award!

Congratulations @loowin! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 1 year!

Click here to view your Board

Support SteemitBoard's project! Vote for its witness and get one more award!

Congratulations @loowin! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 2 years!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Vote for @Steemitboard as a witness to get one more award and increased upvotes!

Coin Marketplace

STEEM 0.14
TRX 0.12
JST 0.025
BTC 53375.38
ETH 2393.56
USDT 1.00
SBD 2.15