본문 바로가기
IT/이더리움 Ethereum

이더리움 Geth 테스트넷 계정(지갑) 생성하기

by SidePower 2022. 9. 20.

지난번에 테스트넷 기동까지 해봤어요.

 

사설 테스트넷이지만 이제 이더리움 블록체인에 참여해 볼 거예요.

 

블록체인은 내컴퓨터에 또는 특정 서버에 계정 정보들을 모아 중앙관리하는 게 아니고

해당 블록체인에 참여하는 모든 노드의 블록들과 P2P 네트워크상에 존재하는 데이터이기 때문에

블록 또는 계정을 찾기 위해 변조할 수 없는 유일값이 있어야 됩니다.

이 유일값은 암호화적 해시함수(SHA256)를 통해 얻은 해시(checksum) 값을 사용합니다.

 

블록체인에 참여하는 간단 절차로는

신규 계정 생성해서 주소(해시)를 할당받고 Ether를 채굴해서 송금(거래)도 시켜봅니다.

 

 계정(지갑) 생성

이더리움의 계정은 EOA와 Contract 두가지가 있습니다.

EOA는 Externally Owned Account . 사용자 계정입니다.

비밀번호가 있어야 되고 계약과 송금할 때 사용됩니다.

Contract는 영어 해석 그대로 계약 전용 계정으로

계약을 블록체인으로 내보낼 때 또 다른 계정들과 메시지를 주고받을 때 사용합니다.

 

지금은 EOA 사용자 계정을 만듭니다.

 

사용자 계정(지갑)은 만드는 방법은 두가지가 있습니다.

 

 Geth console에서 만드는 경우

personal.newAccount("암호")

 테스트넷 실행 명령어가 길어서 
쉘스크립트(tnet_start.sh)로 만들어서 실행합니다.
[tmach@localhost gethmain]$ tnet_start.sh
Welcome to the Geth JavaScript console!

instance: Geth/v1.10.14-unstable-85064ed0-20211202/linux-amd64/go1.17.3
at block: 0 (Wed Dec 31 1969 19:00:00 GMT-0500 (EST))
 datadir: /home/tmach/gethmain/testnet_data
 modules: admin:1.0 debug:1.0 eth:1.0 ethash:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0

To exit, press ctrl-d or type exit
>
>
personal.newAccount("eth999-1")
"0x117309097e7afac115949c9384addca22d65451c"
>

명령어 실행하면 바로 계정의 주소가 만들어집니다.

0x117309097e7afac115949c9384addca22d65451c

이와 같은 다른 계정 주소를 알면 송금할 수 있겠죠.

블록체인은 계정이 주소고 주소가 계정입니다.

 

 리눅스 쉘 환경에서 만드는 경우

geth --datadir 데이터 디렉터리 경로 account new
[tmach@localhost gethmain]$ geth --datadir testnet_data account new
INFO [12-06|08:07:59.618] Maximum peer count                       ETH=50 LES=0 total=50
INFO [12-06|08:07:59.618] Smartcard socket not found, disabling    err="stat /run/pcscd/pcscd.comm: no such file or directory"
Your new account is locked with a password. Please give a password. Do not forget this password.
Password:
Repeat password:

Your new key was generated

Public address of the key:   0x8502AF7eb47E8dCadC4f67923fDD7928A806F860
Path of the secret key file: testnet_data/keystore/UTC--2021-12-06T13-08-59.882195055Z--8502af7eb47e8dcadc4f67923fdd7928a806f860

- You can share your public address with anyone. Others need it to interact with you.
- You must NEVER share the secret key with anyone! The key controls access to your funds!
- You must BACKUP your key file! Without the key, it's impossible to access account funds!
- You must REMEMBER your password! Without the password, it's impossible to decrypt the key!

 Password에 eth999-2를 비밀번호로 했어요.
계정 주소가 만들어지네요.
0x8502AF7eb47E8dCadC4f67923fDD7928A806F860

 

 계정 정보 확인

 테스트넷 데이터 디렉터리의 keystore안에 보면
계정 주소가 2개 추가된게 보일거에요.
[tmach@localhost testnet_data]$ ll
total 20
-rw-rw-r--. 1 tmach tmach   477 Dec  4 03:10 genesis.json
drwx------. 6 tmach tmach   126 Dec  6 07:26 geth
-rw-rw-r--. 1 tmach tmach 14148 Dec  6 07:26 gethErr.log
-rw-------. 1 tmach tmach     0 Dec  6 07:26 history
drwx------. 2 tmach tmach   176 Dec  6 08:09 keystore
[tmach@localhost testnet_data]$ cd keystore
[tmach@localhost keystore]$ ll
total 8
-rw-------. 1 tmach tmach 491 Dec  5 20:40 UTC--2021-12-06T01-40-13.143913369Z--117309097e7afac115949c9384addca22d65451c
-rw-------. 1 tmach tmach 491 Dec  6 08:09 UTC--2021-12-06T13-08-59.882195055Z--8502af7eb47e8dcadc4f67923fdd7928a806f860

 테스트넷의 모든 계정 정보 보기
① 쉘에서 보는 방법
[tmach@localhost gethmain]$ geth --datadir testnet_data account list
INFO [12-06|08:20:54.484] Maximum peer count                       ETH=50 LES=0 total=50
INFO [12-06|08:20:54.484] Smartcard socket not found, disabling    err="stat /run/pcscd/pcscd.comm: no such file or directory"
INFO [12-06|08:20:54.511] Set global gas cap                       cap=50,000,000
Account #0: {117309097e7afac115949c9384addca22d65451c} keystore:///home/tmach/gethmain/testnet_data/keystore/UTC--2021-12-06T01-40-13.143913369Z--117309097e7afac115949c9384addca22d65451c
Account #1: {8502af7eb47e8dcadc4f67923fdd7928a806f860} keystore:///home/tmach/gethmain/testnet_data/keystore/UTC--2021-12-06T13-08-59.882195055Z--8502af7eb47e8dcadc4f67923fdd7928a806f860

② 테스트넷 console에서 보는 방법
[tmach@localhost gethmain]$ tnet_start.sh
Welcome to the Geth JavaScript console!

instance: Geth/v1.10.14-unstable-85064ed0-20211202/linux-amd64/go1.17.3
coinbase: 0x117309097e7afac115949c9384addca22d65451c
at block: 0 (Wed Dec 31 1969 19:00:00 GMT-0500 (EST))
 datadir: /home/tmach/gethmain/testnet_data
 modules: admin:1.0 debug:1.0 eth:1.0 ethash:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0

To exit, press ctrl-d or type exit
>
eth.accounts
["0x117309097e7afac115949c9384addca22d65451c", "0x8502af7eb47e8dcadc4f67923fdd7928a806f860"]

 

감사합니다.

반응형

댓글