Minwook’s portfolio

Geth 설치 및 계정생성 본문

Codestates 블록체인 부트캠프 6기

Geth 설치 및 계정생성

yiminwook 2022. 8. 29. 20:05

 

 

 

1.Geth설치(우분투 20.04v)

 

Launchpad PPA(Personal Package Archives) 활성화를 위해 아래 코드를 실행합니다

$sudo add-apt-repository -y ppa:ethereum/ethereum

https://itsfoss.com/ppa-guide/  <-  자세한내용은 여기에

 

 

Geth를 설치합니다.

$sudo apt-get update
$sudo apt-get install ethereum

 

설치가 정상적으로 되었는지 버젼을 확인해보겠습니다.

$geth -version

 

아래와 같이 나오면 출력된다면 성공적으로 설치되었습니다.

Geth
Version: 1.10.23-stable
Git Commit: d...
Architecture: amd64
Go Version: go1.18.5
Operating System: linux
GOPATH=
GOROOT=go

 

 


 

 

2. Geth계정생성

 

아래명령어를 입력합니다.

$get account new

 

 

계정에서 사용할 비밀번호를 입력합니다.

INFO [08-29|18:53:40.970] Maximum peer count                       ETH=50 LES=0 total=50
INFO [08-29|18:53:40.970] 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와 secret key file의 경로를 알려줍니다.

*비밀번호 / Public address / secret key file 경로는 잊어버리지 않도록 주의합니다!

Public address of the key:   0x..... //주소
Path of the secret key file: /home/users/.ethereum/keystore/UTC--2022-08-29T09-53-52.60..... //키파일 경로

- 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!

 

 

아래 코드를 통해 자신의 계정리스트를 확인 할 수 있습니다.

$geth account list

 

users@ubuntu:~$ geth account list
INFO [08-29|20:12:43.567] Maximum peer count                       ETH=50 LES=0 total=50
INFO [08-29|20:12:43.567] Smartcard socket not found, disabling    err="stat /run/pcscd/pcscd.comm: no such file or directory"
INFO [08-29|20:12:43.568] Set global gas cap                       cap=50,000,000
Account #0: {6d...} keystore:///home/users/.ethereum/keystore/UTC--2022-08-29T09-53-52.60...

 


3. Geth javascript 콘솔실행

 

$geth console 2> /dev/null --goerli   //goerli 테스트서버접속

https://geth.ethereum.org/docs/interface/javascript-console

 

 

Ctrl + D 또는 exit를 타이핑하여 콘솔을 종료 할 수 있습니다.

Welcome to the Geth JavaScript console!

instance: Geth/v1.10.23-stable-d901d853/linux-amd64/go1.18.5
at block: 0 (Thu Jan 01 1970 09:00:00 GMT+0900 (KST))
 datadir: /home/minwook/.ethereum/goerli
 modules: admin:1.0 debug:1.0 engine: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
>

 

 

네트워크 연결확인

> net.listening   //연결이 성공적으로 이루어졌다면 true가 출력

 

네트워크 계정생성

> personal.newAccount();
Passphrase: 
Repeat passphrase: 
"0x..."   //account

 

계정확인

> eth.accounts;

 

계정잔고확인

> eth.getBalance(eth.accounts[i]);   //eth.accounts의 배열 index를 입력

 

geth는 콘솔을 열고 주변 노드들에게 block을 받아 동기화 과정을 걸쳐야 잔고를 확인할 수 있습니다.

그러나 동기화과정에는 매우 긴시간이 소요됩니다.

 

third party API를 사용한다면 동기화하는 과정없이 원격으로 노드에 접근하여 데이터를 받아 올 수 있습니다.

 

 

 

예시코드

users@ubuntu:~$ geth console 2> /dev/null --goerli
Welcome to the Geth JavaScript console!

instance: Geth/v1.10.23-stable-d901d853/linux-amd64/go1.18.5
at block: 0 (Thu Jan 01 1970 09:00:00 GMT+0900 (KST))
 datadir: /home/users/.ethereum/goerli
 modules: admin:1.0 debug:1.0 engine: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
> net.listening
true
> eth.accounts
[]                                  //계정이 없으므로 빈배열
> personal.newAccount()
Passphrase: 
Repeat passphrase: 
"0x..."                             //계정이 생성됨
> eth.accounts;
["0x..."]                           //만든계정이 배열안으로 들어가 있음
> eth.getBalance(eth.accounts[0]);  //0번째 계정을 조회
0                                   //잔고
> exit
users@ubuntu:~$

 


 

테스트용 ropsten Ether 받는곳 

https://goerlifaucet.com/

 

Goerli Faucet

A fast and reliable Ethereum Goerli testnet faucet for blockchain developers.

goerlifaucet.com

 

 

이렇게 생성된 계정을 이더스캔에서 내 계정의 활동과 정보를 검색할 수 있다.

https://goerli.etherscan.io/

 

TESTNET Goerli (GTH) Blockchain Explorer

Etherscan allows you to explore and search the Goerli blockchain for transactions, addresses, tokens, prices and other activities taking place on Goerli (GTH)

goerli.etherscan.io

 

 

 

 

 

Comments