# 빠른 트랜잭션 유입으로 발생하는 오류

**URL:** <https://devforum.kaia.io/t/topic/1618>\
**Category:** Caver\
**Tags:** caver-java\
**Created:** [8월 10, 2021, 10:03오전 UTC](https://devforum.kaia.io/t/topic/1618 "2021-08-10T10:03:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kslee](https://avatars.discourse-cdn.com/v4/letter/k/ea5d25/32.png) [@kslee](https://devforum.kaia.io/u/kslee)\
**Post date:** [8월 10, 2021, 10:03오전 UTC](https://devforum.kaia.io/t/topic/1618/1 "2021-08-10T10:03:04Z")

</div>

안녕하세요~

트랜잭션 객체를 사용해서 여러 트랜잭션을 거의 동시에 보내다 보면 아래 오류가 발생합니다.  
(트랜잭션 간격이 100 밀리 세컨드 이상인 경우는 발생하지 않는 것 같네요.)

there is another tx which has the same nonce in the tx pool

관련 내용을 검색해보니 nonce가 같아서 발생한 문제이더라구요.  
nonce를 수동으로 관리하면 해결된다고 답변하셨는데  
caver-java로 트랜잭션 nonce를 설정하는 방법이 있을까요?

api를 검색하여도 caver.rpc.klay.getTransactionCount 현재 nonce를 가져오는 것 밖에는 없는 것 같습니다.  
감사합니다~

---

<div class="post-metadata">

**Author:** ![Kale](https://yyz1.discourse-cdn.com/flex035/user_avatar/devforum.kaia.io/kale/32/148_2.png) [@Kale](https://devforum.kaia.io/u/Kale)\
**Post date:** [8월 11, 2021, 6:42오전 UTC](https://devforum.kaia.io/t/topic/1618/2 "2021-08-11T06:42:38Z")

</div>

안녕하세요. 클레이튼 포럼에 질문 남겨주셔서 감사드립니다.

caver-java에서는 getTransactionCount()함수를 통해 klaytn의 node를 통해 nonce를 조회해서 가져오는 로직 말곤 없습니다.  
수동으로 트랜잭션을 만드실 때 nonce를 1씩 증가시키는 로직을 직접 구현하셔야 할 것 같습니다.

감사합니다.

---

<div class="post-metadata">

**Author:** ![kslee](https://avatars.discourse-cdn.com/v4/letter/k/ea5d25/32.png) [@kslee](https://devforum.kaia.io/u/kslee)\
**Post date:** [8월 11, 2021, 9:09오전 UTC](https://devforum.kaia.io/t/topic/1618/3 "2021-08-11T09:09:57Z")

</div>

답변 감사합니다. nonce를 관리하는 로직은 구현하면 되는데  
스마트 컨트랙트에서 nonce를 세팅하는 방법을 모르겠습니다.

혹시 아래 코드에서 제가 직접 nonce를 set할 수 있는 방법이 있을까요?

```auto
String abi = getABIString();
Contract contract = new Contract(caver, abi, CONTRACT_ADDRESS);

SendOptions sendOptions = new SendOptions();
sendOptions.setFrom(keyring.getAddress());
sendOptions.setGas(BigInteger.valueOf(DEFAULT_GAS_FEE));

BigInteger amount = getAmonutBigInteger(count);
TransactionReceipt.TransactionReceiptData receipt = contract.getMethod(method_name).send(Arrays.asList(target_address, amount), sendOptions);

```

---

<div class="post-metadata">

**Author:** ![Kale](https://yyz1.discourse-cdn.com/flex035/user_avatar/devforum.kaia.io/kale/32/148_2.png) [@Kale](https://devforum.kaia.io/u/Kale)\
**Post date:** [8월 12, 2021, 4:29오전 UTC](https://devforum.kaia.io/t/topic/1618/4 "2021-08-12T04:29:26Z")

</div>

Contract class를 통해 Transaction을 보내는 send()와 같은 함수는 내부적으로 getTransactionCount()함수를 통해 nonce를 설정하게 되어있으므로, 직접 nonce를 설정하실 수 없습니다.

직접 nonce를 설정하고 싶으신 경우에는 SmartContractExecution class instance를 직접 생성하셔서 nonce 값을 설정하는 방법이 있을 것 같습니다. SmartContractExecution의 input 필드는, Contract class의 encodeABI()함수를 사용하셔서 나온 결과값을 넣으시면됩니다.

`String input = contract.encodeABI(methodName, param1, param2....);`
