geth 명령어들

blockchain 2018. 12. 6. 00:58
//geth init
> geth --datadir .\node1_data_dir\ init .\node1_data_dir\genesis.json
//genesis.json 필요

//콘솔 실행
> geth --networkid 8484 --nodiscover --maxpeers 0 --datadir .\node1_data_dir\ console 2>> .\node1_data_dir\geth.l
og
//nodiscover 생성자 노드를 다른 노드에서 검색할 수 없게 하는 옵션
//maxpeers n 피어 접속 최대 수치
//datadir 데이터 디렉토리 data_testnet
//console 콘솔 실행, 로그

//콘솔 실행 2
> geth --networkid 8484 --nodiscover --maxpeers 0 --rpc --rpcaddr "0.0.0.0" --rpcport 8545 --rpccorsdomain "*" --data
dir .\node1_data_dir console 2>> .\node1_data_dir\geth.log

//원격접속
> geth attach rpc:http://localhost:8545




- remix로 compile 한 contract를 geth로 불러와서 실행해보기


1. Remix [Compile]에 [Details] 클릭


2. abi를 복사하는데, "WEB3DEPLOY"항목의 var helloworldContract = web3.eth.contract([{"constant":true,"inputs":[],"name":"say","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_greeting","type":"string"}],"name":"setGreeting","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"greeting","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"_greeting","type":"string"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"}]);

이 부분이 공백없는 abi니까 복사하면 됨


3. geth로 가서 다음과 같이 코딩

> abi = '[{"constant":true,"inputs":[],"name":"say","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"
},{"constant":false,"inputs":[{"name":"_greeting","type":"string"}],"name":"setGreeting","outputs":[],"payable":false,"stateMutability":"nonpayable","
type":"function"},{"constant":true,"inputs":[],"name":"greeting","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","typ
e":"function"},{"inputs":[{"name":"_greeting","type":"string"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"}]';

> contract = eth.contract(JSON.parse(abi)).at("0xb6eb1c592e03639685513669ae7a877f51fc469a");

at에 들어가는 파라메터는 remix에서 Deployed Contract 의 주소임


4. 테스트

> contract.say.hello()






'blockchain' 카테고리의 다른 글

Powershell의 curl 명령어 대안  (0) 2018.12.06
geth genesis.json (181205 기준)  (0) 2018.12.05
Windows PowerShell 에서 UNIX tail 명령어  (0) 2018.12.05
Posted by 아마루아00
,