[발표자료]
[참고문헌]
- 블록체인 구조와 이론 예제로 배우는 핀테크 핵심 기술
- 마스터링 이더리움:스마트 컨트랙트 및 댑 구축하기
[발표자료]
✏ Testing Blockchain
- Timestamp : the time that the block was added to the blockchain
- Index : a running number starting from() indicating the block number.
- Hash of the previous block : the hash result of the previous block.
- Nonce : the number used once.
- Transaction(s) : each block will hold a variable number of transactions.
✔ 관리자 권한으로 실행
$ pip install flask
$ pip install request
Flask is a web framework that makes building web applications easy and rapid
$ python blockchain.py 5000
- 결과
✔ 첫 번째 노드에서 실행되는 첫 번째 블록체인이 현재 실행 중인것을 볼 수 있다.
$ curl http://localhost:5000/blockchain
- 결과
{
"chain" : [{
"hash_of_previous_block: "181cfa3e85f3c2a7aa9fb74f992d
0d061d3e4a6d7461792413aab3f97bd3da95",
"index" : 0,
"nonce" : 61093,
"timestamp" : 1644946853.955589,
"transactions" : []
}],
"length" : 1
}
✔ 첫 번째 블록(인덱스 0)인 제니시스 블록이다.
- Try mining a block to see how it will affect the blockchain Type the following
$ curl http://localhost:5000/mine
- 결과
✔ The block that is mined will now be returned:
{
"hash_of_previous_block": "d7a7c6ee011820a5d156c5158cb27ea48943d4817a48218829aa865bf4a21fbc",
"index" : 1,
"message" : "New Block Mined",
"nonce" : 13807,
"transactions" : [{
"amount" : 1,
"recipient: "4d9de024d88d4eb7b16f4f353e5b9ddf",
"sender" : "0"
}]
}
✔ 블록에 단일 트랜잭션이 포함되어 있으며 이는 채굴자에게 제공되는 보상이다.
$ curl http://localhost:5000/blockchain
- 결과
✔ 이제 새로 채굴된 블록이 블록체인에 있는 것을 볼 수 있다:
{
"chain" : [{
"hash_of_previous_block: "181cfa3e85f3c2a7aa9fb74f992d
0d061d3e4a6d7461792413aab3f97bd3da95",
"index" : 0,
"nonce" : 61093,
"timestamp" : 1644946853.955589,
"transactions" : []
}, {
"hash_of_previous_block": "d7a7c6ee011820a5d156c5158cb27ea48943d4817a48218829aa865bf4a21fbc",
"index" : 1,
"message" : "New Block Mined",
"nonce" : 13807,
"transactions" : [{
"amount" : 1,
"recipient: "4d9de024d88d4eb7b16f4f353e5b9ddf",
"sender" : "0"
}]
}]
"lenght" : 2
}
Remember that the default difficulty target is set to four zero. you can change it to five zero and retest the blockchain.
you will realize that it now takes a longer time to mine block. since it is more difficult to find a nonce thath results in a hash beginning with five zeros.
- Let's add a transaction to a block by issuing the following command in Terminal.
$ curl -X POST -H "Content-Type: application/json" -d "{\"sender\": \"04d0988bfa799f7d7ef9ab3de97ef481\", \"recipient\": \"cd0f75d2367ad456607647edde665d6f\",\"amount\": 5}" "http://localhost:5000/transactions/new"
- 결과
✔ 성공적으로 블록이 추가되었다.
✔ 이제 블록을 mine 할 수 있다.
$ curl http://localhost:5000/mine
- 결과
{
"hash_of_previous_block": "7beffae74017f36dfd91d1e3a71bab570d6f10e8d97dfdae37d17d66ae7b4c32",
"index" : 2,
"message" : "New Block Mined",
"nonce" : 98128,
"transactions" : [{
"amount" : 5,
"recipient: "cd0f75d2367ad456607647edde665d6f",
"sender" : "04d0988bfa799f7d7ef9ab3de97ef481"
}, {
"amount" : 1,
"recipient: "4d9de024d88d4eb7b16f4f353e5b9ddf",
"sender" : "0"
}]
}
✔ 블록 2가 채굴되었으며 여기에는 두 개의 트랜잭션이 포함되어 있다. 하나는 수동으로 추가한 것이고 miner에 대한 보상이 있다.
-
Examine the content of the blockchain by issuing this command.
-
결과
{
"chain" : [{
"hash_of_previous_block: "181cfa3e85f3c2a7aa9fb74f992d
0d061d3e4a6d7461792413aab3f97bd3da95",
"index" : 0,
"nonce" : 61093,
"timestamp" : 1644946853.955589,
"transactions" : []
}, {
"hash_of_previous_block": "d7a7c6ee011820a5d156c5158cb27ea48943d4817a48218829aa865bf4a21fbc",
"index" : 1,
"message" : "New Block Mined",
"nonce" : 13807,
"transactions" : [{
"amount" : 1,
"recipient: "4d9de024d88d4eb7b16f4f353e5b9ddf",
"sender" : "0"
}]
}, {
"hash_of_previous_block": "7beffae74017f36dfd91d1e3a71bab570d6f10e8d97dfdae37d17d66ae7b4c32",
"index" : 2,
"message" : "New Block Mined",
"nonce" : 98128,
"transactions" : [{
"amount" : 5,
"recipient: "cd0f75d2367ad456607647edde665d6f",
"sender" : "04d0988bfa799f7d7ef9ab3de97ef481"
}, {
"amount" : 1,
"recipient: "4d9de024d88d4eb7b16f4f353e5b9ddf",
"sender" : "0"
}]
}]
"lenght" : 3
}
✔ 이제 두 트랜잭션이 포함된 새로 추가된 블록이 표시된다.
✏ Connecting to the Ethereum Blockchain
-
이더리움 블록체인과 상호 작용하는데 사용할 수 있는 많은 이더리움 클라이언트가 있다.
-
Eth : A C++ Ethereum client
-
Geth : The official Ethereum dlient implemented using the Go programing language
-
Pyethapp : A Python Ethereum client
-
Parit : An Ethereum client written using the Rust Programming language
-
-
Geth를 사용.
- https://geth.ethereum.org/downloads/
- 윈도우 버전 Geth 다운로드
📌 최신 버전은 --testnet이 오류가 발생함.
- Geth를 사용하여 이더리움 블록체인에 연결
$ geth --testnet --datadir ~/.ethereum-testnet
-
--testnet: connect to the Ropsten test network.
- Rinkeby 테스트 네트워크에 연결하고 싶다면 --rinkeby 사용.
-
--datadir: 블록체인, 키 저장소 및 기타 로컬 클라이언트 데이터를 저장하는데 사용할 로컬 저장소를 지정.
-
실행결과: 네트워크의 전체 블록체인이 컴퓨터에 다운로드 되고, ~/.ethereum-testnet에 저장된다.
- ~/.ethereum-testnet 디렉토리에서 Geth가 만든 폴더를 볼 수 있다.
- The geth folder contains the blockchain that you are downloading, while the keystore folder contains the account details of your local Ehtereum node.
- To use the Geth JavaScript Console, add the following option in bold to the geth command in the Terminal.
geth --testnet --datadir ~/.ethereum-testnet console 2>console.log
- The command Prompt allows you to issue JavaScript commands
personal.newAccount()
We will discuss more Geth commands in the next chapter.
[발표자료]
참고문헌 - 핸즈온 머신러닝 사이킷런, 케라스, 텐서플로 2를 활용한 머신러닝, 딥러닝 완벽 실무
[발표자료]
참고문헌 - Cryptography and network security - Principles and Practice, William Stallings, Pearson.