boolean feePayerExists = true;
BufferedReader br = new BufferedReader(new FileReader(projectBaseDir +"/json/Contract.json"));
KIP7Json kip7Json = new Gson().fromJson(br, KIP7Json.class);
Contract contract = KIP7.create(caver, kip7Json.getAbi().toString(), "0x0bbcd245044c507ba1c9c3011d69b33ff3cbc7ed");
Caver caver = setCaver(accessKey, secretAccessKey, chainId);
SingleKeyring senderKeyring = KeyringFactory.createFromPrivateKey("0x15321f6b31d600b59cd5e7e2f3f63a49331eafa5de9cfbf8701c8b4c0cdee7a4");
caver.wallet.add(senderKeyring);
AbstractKeyring feePayerKeyring = null;
if(feePayerExists){
String feePayerWallet = "0x6e4d6118358d76412163d3d71510a3365e32fa64";
String feePayerWalletFilePath = walletsRootPath + messageByLocaleService.getMessage("mcc.wallet." + feePayerWallet + ".path");
//Decrypt keystore.
ObjectMapper objectMapper = ObjectMapperFactory.getObjectMapper();
KeyStore keyStore = objectMapper.readValue(new File(feePayerWalletFilePath), KeyStore.class);
feePayerKeyring = KeyringFactory.decrypt(keyStore, "1q2w3e4r");
caver.wallet.add(feePayerKeyring);
contract.setWallet(caver.wallet);
}
SendOptions sendOptions = new SendOptions(senderKeyring.getAddress());
sendOptions.setFeeDelegation(false);
sendOptions.setGas(BigInteger.valueOf(1000000));
if(feePayerExists){
sendOptions.setFeeDelegation(true);
sendOptions.setFeePayer(feePayerKeyring.getAddress());
}else{
sendOptions.setFeeDelegation(false);
}
String account = "0xb7cc824e26fea75cb930f1036d9159eb65f73f8d";
String convertAmount = caver.utils.convertToPeb("1", Utils.KlayUnit.KLAY);
AbstractTransaction executionTx = contract.sign(sendOptions, "transfer", account, new BigInteger(convertAmount));
caver.wallet.signAsFeePayer(feePayerKeyring.getAddress(), (AbstractFeeDelegatedTransaction)executionTx, 2);
Bytes32 txHash_executed = caver.rpc.klay.sendRawTransaction(executionTx).send();
TransactionReceiptProcessor receiptProcessor = new PollingTransactionReceiptProcessor(caver, 1000, 15);
TransactionReceipt.TransactionReceiptData receiptData = receiptProcessor.waitForTransactionReceipt(txHash_executed.getResult());
위 소스처럼 지갑을 생성하고 RoleBasedKey로 업데이트하고 샘플에 나온 newKeyring을 encrypt하여 KeyStore를 만들어 저장해두고 그 KeyStore를 불러오는 방식으로 했습니다
위 소스를 실행했을 때 오류가 발생해서 디버깅 해보니까 feepayer 주소는 맞게 전달 된것 같은데 아래처럼 오류가 발생했습니다.
[] - 21-10-29 14:09:49:751 DEBUG org.web3j.protocol.http.HttpService:210 - {"jsonrpc":"2.0","method":"klay_sendRawTransaction","params":["0x31f90123378505d21dba00830f4240940bbcd245044c507ba1c9c3011d69b33ff3cbc7ed809430f645dcce248679dbb51024c85865bcbed9b7f8b844a9059cbb000000000000000000000000b7cc824e26fea75cb930f1036d9159eb65f73f8d0000000000000000000000000000000000000000000000000de0b6b3a7640000f847f8458207f5a0ed9df441702a903e68658e595a4a4eae54c696404af56ab602132db35b7a9ac4a04de08cdf8929d56d649c13dbf9c953f2372570e02386fb622ad4165a29c79d55946e4d6118358d76412163d3d71510a3365e32fa64f847f8458207f6a08f13d9ecc5054af6dc25bf53c6fde676b536c5dea7b929056326ac394eb878f2a06f7596493f99d23787d4b597ea5a07f4c91715b153a0eb6802e02276cbf833cc"],"id":3}
[] - 21-10-29 14:09:49:752 DEBUG org.web3j.protocol.http.HttpService:211 - --> END POST (665-byte body)
[] - 21-10-29 14:09:50:205 DEBUG org.web3j.protocol.http.HttpService:233 - <-- 200 OK https://node-api.klaytnapi.com/v1/klaytn (453ms)
[] - 21-10-29 14:09:50:206 DEBUG org.web3j.protocol.http.HttpService:294 - content-length: 79
[] - 21-10-29 14:09:50:207 DEBUG org.web3j.protocol.http.HttpService:294 - content-type: application/json
[] - 21-10-29 14:09:50:208 DEBUG org.web3j.protocol.http.HttpService:294 - date: Fri, 29 Oct 2021 05:09:49 GMT
[] - 21-10-29 14:09:50:209 DEBUG org.web3j.protocol.http.HttpService:294 - server: istio-envoy
[] - 21-10-29 14:09:50:209 DEBUG org.web3j.protocol.http.HttpService:294 - vary: Origin
[] - 21-10-29 14:09:50:210 DEBUG org.web3j.protocol.http.HttpService:294 - x-envoy-upstream-service-time: 2
[] - 21-10-29 14:09:50:211 DEBUG org.web3j.protocol.http.HttpService:276 -
[] - 21-10-29 14:09:50:212 DEBUG org.web3j.protocol.http.HttpService:277 - {"jsonrpc":"2.0","id":3,"error":{"code":-32000,"message":"invalid fee payer"}}
fee payer 정보가 안맞는것 같은데 이건 어떤 오류인지 알 수 있을까요??
이후 오류는
[] - 21-10-29 14:09:50:213 DEBUG org.web3j.protocol.http.HttpService:284 - <-- END HTTP (79-byte body)
[] - 21-10-29 14:10:09:622 DEBUG org.web3j.protocol.http.HttpService:169 - --> POST https://node-api.klaytnapi.com/v1/klaytn
[] - 21-10-29 14:10:09:624 DEBUG org.web3j.protocol.http.HttpService:176 - Content-Type: application/json; charset=utf-8
[] - 21-10-29 14:10:09:625 DEBUG org.web3j.protocol.http.HttpService:179 - Content-Length: 78
[] - 21-10-29 14:10:09:626 DEBUG org.web3j.protocol.http.HttpService:294 - Authorization: Basic S0FTS09HTTVMMkoyTFZFSVlKVzhZS01DOmo4RFpISG5SZktkZzdub3EzR3JwWld0WGhJYjZ0SEQ2YitUeFcrVXo=
[] - 21-10-29 14:10:09:627 DEBUG org.web3j.protocol.http.HttpService:294 - x-chain-id: 1001
[] - 21-10-29 14:10:09:628 DEBUG org.web3j.protocol.http.HttpService:208 -
[] - 21-10-29 14:10:09:629 DEBUG org.web3j.protocol.http.HttpService:210 - {"jsonrpc":"2.0","method":"klay_getTransactionReceipt","params":[null],"id":4}
[] - 21-10-29 14:10:09:630 DEBUG org.web3j.protocol.http.HttpService:211 - --> END POST (78-byte body)
[] - 21-10-29 14:10:09:656 DEBUG org.web3j.protocol.http.HttpService:233 - <-- 200 OK https://node-api.klaytnapi.com/v1/klaytn (25ms)
[] - 21-10-29 14:10:09:657 DEBUG org.web3j.protocol.http.HttpService:294 - content-length: 149
[] - 21-10-29 14:10:09:658 DEBUG org.web3j.protocol.http.HttpService:294 - content-type: application/json
[] - 21-10-29 14:10:09:659 DEBUG org.web3j.protocol.http.HttpService:294 - date: Fri, 29 Oct 2021 05:10:08 GMT
[] - 21-10-29 14:10:09:660 DEBUG org.web3j.protocol.http.HttpService:294 - server: istio-envoy
[] - 21-10-29 14:10:09:661 DEBUG org.web3j.protocol.http.HttpService:294 - vary: Origin
[] - 21-10-29 14:10:09:662 DEBUG org.web3j.protocol.http.HttpService:294 - x-envoy-upstream-service-time: 2
[] - 21-10-29 14:10:09:663 DEBUG org.web3j.protocol.http.HttpService:276 -
[] - 21-10-29 14:10:09:664 DEBUG org.web3j.protocol.http.HttpService:277 - {"jsonrpc":"2.0","id":4,"error":{"code":-32602,"message":"invalid argument 0: json: cannot unmarshal non-string into Go value of type common.Hash"}}
이렇게 되는데 이부분은 invalid feepayer 부분이 오류가 발생했는데 호출해서 발생한것으로 보여집니다.