본문 바로가기

Web3

[web3j] getTransactionCount

https://ethereum.stackexchange.com/questions/115600/web3js-gettransactioncount-always-return-1

 

Web3js getTransactionCount() always return 1

web3js.eth.getTransactionCount(CONTRACT_ADDRESS+'').then( txcount => { console.log( "-> getTransactionCount: " + txcount ); }); Always return 1, but my contract has lot of

ethereum.stackexchange.com

getTransactionCount returns the account nonce.

For an Externally Owned Account (EOA) the nonce is the number of previously sent transactions which starts at 0 and is incremented by 1 for each transaction sent hence the name of the function getTransactionCount.

However, for Contract Accounts (CA) the nonce is the number of contract created by this contract. CA's nonce starts at 1 (since EIP-161) and is also incremented by 1 for each CREATE or CREATE2 call which creates a new contract.

Your contract never sent a single transaction because contract cannot do that. They can do message calls but the transaction is coming from an EOA. A value of 1 in that case simply means that your contract never created other contracts by means of CREATE or CREATE2, it's nonce is therefore the default value : 1.

You could check the nonce of a contract factory this as the Uniswap V2 Factory Contract to see that its nonce is greater than 1, and is incremented everytime a contract is created by this factory contract.

===============================

getTransactionCount는 nonce를 return한다

컨트랙트는 create를 할떄마다 nonce가 증가하기 떄문에 nonce는 1이 초기 상태라 볼수 있다.

 

'Web3' 카테고리의 다른 글

web3j (web3 java)에서 isAddress 쓰기  (0) 2022.12.22