Geth - Transaction 전송

CHOYEAH·2023년 11월 27일
0

Go ethreume

목록 보기
5/11

geth에서 트랜잭션 전송

게스 실행

./geth --datadir ./data --http --http.api "admin, debug, web3, eth, txpool, personal, ethash, miner, net" --mine --miner.threads "1" --allow-insecure-unlock --unlock 0 --password ./password console

트랜잭션 전송을 위해 언락 옵션 필요, 언락 매개 변수는 주소, 비밀번호, 지속시간 3개이다. 0은 게스가 종료될때까지 잠금해제 상태가 유지된다.

콘솔 사용을 위한 attach

 ./geth attach http://127.0.0.1:8545

새 계정 생성

 personal.newAccount("1234")
"0x8ef79508112a2369ec7a3f276ea803eb8be5a9fe"

이더 전송

> eth.sendTransaction({from: eth.accounts[0], to: eth.accounts[2], value: web3.toWei(10, "ether")})
"0x42ee7be6c6832031f4fbc2f01c8b3ac2df22be2ecbe8b51b4bd47ae6528d9c08" // 트랜잭션 해시

마이닝이 진행중이지 않으면 트랜잭션 해시는 리턴되나 해당 트랜잭션은 처리되지 않는다. 펜딩 트랜잭션은 다음 명령어로 확인 가능

> eth.pendingTransactions
[]

결과 확인

> web3.fromWei(eth.getBalance(eth.accounts[2]), "ether")
10

트랜잭션 확인

> eth.getTransaction("0x42ee7be6c6832031f4fbc2f01c8b3ac2df22be2ecbe8b51b4bd47ae6528d9c08")
{
  blockHash: "0x968a1efda3bbfa22310b4096576b250084d01839d500d1b75ecdf18e07fe5ff6",
  blockNumber: 470,
  chainId: "0x3039",
  from: "0x6730ae899d1b135f13544543c88f354b5d79a715",
  gas: 21000,
  gasPrice: 1000000000,
  hash: "0x42ee7be6c6832031f4fbc2f01c8b3ac2df22be2ecbe8b51b4bd47ae6528d9c08",
  input: "0x",
  nonce: 1,
  r: "0xeb7c0c553cd1022ad0fd9a783c149d8925ae31f20457e8eb975fed4ab403b4b9",
  s: "0x552f01ef9eae8f45a0338fbd643f7b261632463fd4fedcb0110df2998349b827",
  to: "0x8ef79508112a2369ec7a3f276ea803eb8be5a9fe",
  transactionIndex: 0,
  type: "0x0",
  v: "0x6095",
  value: 10000000000000000000
}

데이터와 함께 트랜잭션 보내기

> eth.sendTransaction({from: eth.accounts[0], to: eth.accounts[2], value: web3.toWei(1, "ether"), data: "0x01234567"})
"0x88abfcaac5e2de99ee8f19877318c1c99f3bf677216666430795eb245e53d846"

문자열을 16진수로 변환하여 네 번째 매개변수로 전달

결과 확인

> eth.getTransaction("0x88abfcaac5e2de99ee8f19877318c1c99f3bf677216666430795eb245e53d846")
{
  blockHash: "0xec155e8565eb52c11baa40e7c251ef384cd7415f22a5f2798d83b67c1199610a",
  blockNumber: 987,
  chainId: "0x3039",
  from: "0x6730ae899d1b135f13544543c88f354b5d79a715",
  gas: 21064,
  gasPrice: 1000000000,
  hash: "0x88abfcaac5e2de99ee8f19877318c1c99f3bf677216666430795eb245e53d846",
  input: "0x01234567",
  nonce: 3,
  r: "0xe20b438324f2c50585aa4e218eef75b7134d496e5b7bebfe7afdf53fb36c2c06",
  s: "0x96f47383423cbf32ff4a704b9a755a909119822ffe8676687b4418cb9e104df",
  to: "0x8ef79508112a2369ec7a3f276ea803eb8be5a9fe",
  transactionIndex: 0,
  type: "0x0",
  v: "0x6096",
  value: 1000000000000000000
}

input 필드에 전달한 데이터 정보 확인 가능, 데이터를 보내지 않을경우 input 필드는 0x값이 디폴트.

profile
Move fast & break things

0개의 댓글