FeeDelegatedSmartContractExecution
@Test
public void testABC() throws Exception {
String testPrivateKey = "0x07f2066d045c19f72479cf3079a8161244bb3a9d0899a3487b6ec00c13596360";
String method = "ABC";
AbstractKeyring feePayerKeyring = keyStoreTools.getFeePayerKeyring(true);
Caver caver = caverProvider.get();
Utils Utils = new Utils(caver, TokenContractAddress, feePayerKeyring);
Token token = Utils.getToken();
Contract Contract = caver.contract.create(.getAbi());
AbstractKeyring senderKeyring = Utils.createFromPrivateKey(testPrivateKey);
// caver 객체에 sender, feePayer 설정
Utils.getToken().setSender(senderKeyring);
Utils.getToken().setFeePayer(feePayerKeyring);
Contract.setWallet(caver.wallet);
// defaultSendOption객체에 senderKeyring, feePayerKeyring 초기값 설정
token.getDefaultSendOptions().setFrom(senderKeyring.getAddress());
token.getDefaultSendOptions().setFeeDelegation(true);
token.getDefaultSendOptions().setFeePayer(feePayerKeyring.getAddress());
List<String> toAddressList = new ArrayList<>();
toAddressList.add("0x980e41f0a74f1c3d749b8ec54d9e3de3279e1feb");
toAddressList.add("0xeca192412098a7d76044129a136f43769b074da2");
String amount = caver.utils.convertToPeb("1", Utils.KlayUnit.KLAY);
List<BigInteger> amountList = new ArrayList<>();
amountList.add(new BigInteger(amount));
amountList.add(new BigInteger(amount));
String input = Contract.encodeABI(method, toAddressList, amountList);
BigInteger nonce = caver.rpc.klay.getTransactionCount(senderKeyring.getAddress()).send().getValue();
SendOptions sendOptions = determineSendOptions(, .getDefaultSendOptions(), method, Arrays.asList(toAddressList, amountList));
log.info("================ nonce : {}", nonce);
FeeDelegatedSmartContractExecution fdsce = new FeeDelegatedSmartContractExecution.Builder()
.setKlaytnCall(caver.rpc.klay)
.setFrom(senderKeyring.getAddress())
.setTo(TokenContractAddress)
.setGas(sendOptions.getGas())
.setInput(input)
.setNonce(nonce)
.build();
// Decoding하지 않고 sign(), signAsFeePayer()를 수행
caver.wallet.sign(senderKeyring.getAddress(), fdsce);
caver.wallet.signAsFeePayer(feePayerKeyring.getAddress(), fdsce);
String decoded = fdsce.getRLPEncoding();
Bytes32 txHash_executed = caver.rpc.klay.sendRawTransaction(decoded).send();
log.info("========= {}", objectToString(txHash_executed));
}
위와 같이 테스트클래스를 실행했을 때
정상적인 응답을 받았습니다
이때 Transaction은 "0xda92dae550f4106a88826c88784f23b716ff1a464e0d6bbfe63cea05eb7c827a"이고 시간은 2024. 01. 19 13:13:13 KST입니다.
그리고 바로 다시 실행했는데
"24-01-19 13:16:58:734 INFO io.token.klaytn.TestClassDonTouch:215 - ================ nonce : 631"로 응답이 왔습니다.
응답을 받고 여러번 실행했을 때의 결과값도 같이 남겨놓겠습니다.
[실행결과]
24-01-19 13:51:12 transferMulti 성공
24-01-19 13:52:09 transferMulti 성공
24-01-19 13:53:44 Transaction receipt was not generated after 45 seconds for transaction: 0x3c5f2098e7e68e60eae84164cdbfeafbd5b5735bf89b736eb5a389d6876fe4a4
24-01-19 13:58:39 known transaction: a93ebf4dae0ca37709356f63e7005a353cbcad380997437b7a1423793cf4cf2b / nonce : 631
24-01-19 14:03:43 nonce too low / nonce : 631
정상적으로 성공한 트랜잭션이 있는데 getTransactionCount의 결과가 더 작게 나왔는데 이거는 어떻게 수정하나요?