안녕하세요?
수수료 대납 (fee delegation) 테스트를 하는 중에 질문이 생겨 이렇게 글 올립니다.
caver.wallet.keyring.generate() 을 이용하여 legacy keyring을 생성한 후 수수료 대납 테스트는 정상적으로 대납이 이루어지는 것을 확인했습니다.
그런데 수수료 대납 계정을 rolebased keyring으로 생성하여 수행하니 아래와 같은 에러가 발생합니다.
Error: Returned error: invalid fee payer
at Object.ErrorResponse (/home/hlibmaster/klaytn/works/ex-caverjs/node_modules/caver-js/packages/caver-core-helpers/src/errors.js:87:16)
at /home/hlibmaster/klaytn/works/ex-caverjs/node_modules/caver-js/packages/caver-core-requestmanager/src/index.js:155:44
at XMLHttpRequest.request.onreadystatechange (/home/hlibmaster/klaytn/works/ex-caverjs/node_modules/caver-js/packages/caver-core-requestmanager/caver-providers-http/src/index.js:119:13)
at XMLHttpRequestEventTarget.dispatchEvent (/home/hlibmaster/klaytn/works/ex-caverjs/node_modules/xhr2-cookies/dist/xml-http-request-event-target.js:34:22)
at XMLHttpRequest._setReadyState (/home/hlibmaster/klaytn/works/ex-caverjs/node_modules/xhr2-cookies/dist/xml-http-request.js:208:14)
at XMLHttpRequest._onHttpResponseEnd (/home/hlibmaster/klaytn/works/ex-caverjs/node_modules/xhr2-cookies/dist/xml-http-request.js:318:14)
at IncomingMessage. (/home/hlibmaster/klaytn/works/ex-caverjs/node_modules/xhr2-cookies/dist/xml-http-request.js:289:61)
at IncomingMessage.emit (events.js:388:22)
at endReadableNT (internal/streams/readable.js:1336:12)
at processTicksAndRejections (internal/process/task_queues.js:82:21)
아래는 소스 코드 원문입니다.
let RunProcTest = async function() {
try {
let keystoreFrom = require('./keystores/feeDelegate01.json');
let keyringFrom = await caver.wallet.keyring.decrypt(keystoreFrom, "password");
await caver.wallet.add(keyringFrom)
let nonce = toHex(await caver.rpc.klay.getTransactionCount(keyringFrom.address));
let rawTx = {
from: keyringFrom.address,
to: "0x7b3f9ff0f4215c41b3e4a49510b540e80d0c790b",
value: "1000000000000000000",
gas: ESTIMATEGAS_VALUETRANSFER,
nonce: nonce++};
let tx = caver.transaction.feeDelegatedValueTransfer.create(rawTx);
let signed = await caver.wallet.sign(keyringFrom.address, tx);
console.log('>>>>>> 1st signed data')
console.log(signed)
let rlpEncoded = signed.getRLPEncoding();
console.log('>>>>>> rlpEncoding string')
console.log(rlpEncoded)
//let keystoreSigner = require('./keystores/ksRoleBase.json');
let keystoreSigner = require('./keystores/feeDelegate02.json');
let keyringSigner = await importKeyring(keystoreSigner, "password");
await caver.wallet.add(keyringSigner);
let feeDelegationTx = await caver.transaction.feeDelegatedValueTransfer.create(rlpEncoded);
console.log('>>>>>> fee delegation tx')
console.log(feeDelegationTx)
feeDelegationTx.feePayer = keyringSigner.address;
let signedfeeDelegationTx = await caver.wallet.signAsFeePayer(keyringSigner.address, feeDelegationTx);
console.log('>>>>>> 2nd signed data')
console.log(signedfeeDelegationTx)
await caver.rpc.klay.sendRawTransaction(signedfeeDelegationTx)
.on('transactionHash', async function(txHash) {
console.log(`Transfer TX:['${colors.green(txHash)}'] Created!`);
})
.on('receipt', async function(receipt) {
console.log(`Transfer TX:['${colors.green(receipt.transactionHash)}'] Done! BlockNumber:[${colors.green(parseInt(receipt.blockNumber))}]`);
});
} catch(error) {
console.log(colors.red(error));
process.exit(1);
}
}
RunProcTest();
도움 주시면 감사하겠습니다.