Fee Delegation 사용하기
Fee Delegation Transaction은 Sender가 실행하고 싶은 Transaction의 수수료를 FeePayer가 대납해 주는 서비스로 Sender가 서명한 기존 Transaction 정보에 FeePayer의 서명을 추가하여 전송하는 개념을 통하여 제공됩니다.
Fee Delegation Transaction은 Sender가 서명한 기존 Transaction 중 DynamicFeeTxType 만을 지원하며 LegacyTxType, AccessListTxType은 지원하지 않습니다.
LegacyTxType
No
AccessListTxType
No
DynamicFeeTxType
Yes
CURL 명령어를 이용한 사용 방법
첫 번째로, personal_signTransaction method를 이용하며 DynamicFeeTxType(0x02) Transaction을 생성하여 raw data를 얻습니다.
curl -H "Content-Type: application/json" -X POST --data '{"jsonrpc":"2.0","method":"personal_signTransaction","params":[{"from":"0xc3e44aac2d0457942baffa1dc3be313bc8d65627","to":"0xdb8408bb47bf5e745fed00fc2c99e2f4e1a9270f","nonce":"0x1c","value":"0xDE0B6B3A7640000","maxPriorityFeePerGas":"0x174876E801","maxFeePerGas":"0x174876E801","gas":"0x5208"},""],"id":1}' http://127.0.0.1:8588
result: {"jsonrpc":"2.0","id":1,"result":{"raw":"0x02f8768204581c85174876e80185174876e80182520894db8408bb47bf5e745fed00fc2c99e2f4e1a9270f880de0b6b3a764000080c080a0b4dc96b4580bd1d3f090b953ea3612625dd834af8e7cc6146def84a0c137b32ca0082427bf3a4589ffe79bebad9151ece587790462cd44abdd810abe0016134b8f","tx":{"type":"0x2","nonce":"0x1c","gasPrice":null,"maxPriorityFeePerGas":"0x174876e801","maxFeePerGas":"0x174876e801","gas":"0x5208","value":"0xde0b6b3a7640000","input":"0x","v":"0x0","r":"0xb4dc96b4580bd1d3f090b953ea3612625dd834af8e7cc6146def84a0c137b32c","s":"0x82427bf3a4589ffe79bebad9151ece587790462cd44abdd810abe0016134b8f","to":"0xdb8408bb47bf5e745fed00fc2c99e2f4e1a9270f","chainId":"0x458","accessList":[],"hash":"0x80411634325036fe33e49104b1689f8d3ed92e2521ecfd058b26275b51471d70"}}}두 번째로, Fee Delegation Transaction을 지원하기 위해 추가된 personal_signRawFeeDelegateTransaction method 을 이용하여 Fee Delegation Transaction raw data를 생성합니다.
curl -H "Content-Type: application/json" -X POST --data '{"jsonrpc":"2.0","method":"personal_signRawFeeDelegateTransaction","params":[{"feePayer":"0xdb8408bb47bf5e745fed00fc2c99e2f4e1a9270f"},"0x02f8768204581c85174876e80185174876e80182520894db8408bb47bf5e745fed00fc2c99e2f4e1a9270f880de0b6b3a764000080c080a0b4dc96b4580bd1d3f090b953ea3612625dd834af8e7cc6146def84a0c137b32ca0082427bf3a4589ffe79bebad9151ece587790462cd44abdd810abe0016134b8f","test"],"id":1}' http://127.0.0.1:8588
result: {"jsonrpc":"2.0","id":1,"result":{"raw":"0x16f8d0f8768204581c85174876e80185174876e80182520894db8408bb47bf5e745fed00fc2c99e2f4e1a9270f880de0b6b3a764000080c080a0b4dc96b4580bd1d3f090b953ea3612625dd834af8e7cc6146def84a0c137b32ca0082427bf3a4589ffe79bebad9151ece587790462cd44abdd810abe0016134b8f94db8408bb47bf5e745fed00fc2c99e2f4e1a9270f80a0ba376dff9a2a4344a570367c94eeee2434a0e44ccf2da900f54becc6adaf0b5ca077b7d15ab7ba7213b5189094ca1bd41c7a48390767e4acb14c98f3442e561abb","tx":{"type":"0x17","nonce":"0x1c","gasPrice":null,"maxPriorityFeePerGas":"0x174876e801","maxFeePerGas":"0x174876e801","gas":"0x5208","value":"0xde0b6b3a7640000","input":"0x","v":"0x0","r":"0xb4dc96b4580bd1d3f090b953ea3612625dd834af8e7cc6146def84a0c137b32c","s":"0x82427bf3a4589ffe79bebad9151ece587790462cd44abdd810abe0016134b8f","to":"0xdb8408bb47bf5e745fed00fc2c99e2f4e1a9270f","chainId":"0x458","accessList":[],"hash":"0x19b5e90deb03cd4b87aca41ca09dcfed5e7c7ad33e6579f30f7efba722c54424","feePayer":"0xdb8408bb47bf5e745fed00fc2c99e2f4e1a9270f","fv":"0x0","fr":"0xba376dff9a2a4344a570367c94eeee2434a0e44ccf2da900f54becc6adaf0b5c","fs":"0x77b7d15ab7ba7213b5189094ca1bd41c7a48390767e4acb14c98f3442e561abb"}}}마지막으로, eth_sendRawTransaction method를 이용하여 Fee Delegation Transaction의 raw data를 전송합니다.
curl -H "Content-Type: application/json" -X POST --data '{"jsonrpc":"2.0","method":"eth_sendRawTransaction","params":["0x17f8d0f8768204581c85174876e80185174876e80182520894db8408bb47bf5e745fed00fc2c99e2f4e1a9270f880de0b6b3a764000080c080a0b4dc96b4580bd1d3f090b953ea3612625dd834af8e7cc6146def84a0c137b32ca0082427bf3a4589ffe79bebad9151ece587790462cd44abdd810abe0016134b8f94db8408bb47bf5e745fed00fc2c99e2f4e1a9270f80a0ba376dff9a2a4344a570367c94eeee2434a0e44ccf2da900f54becc6adaf0b5ca077b7d15ab7ba7213b5189094ca1bd41c7a48390767e4acb14c98f3442e561abb"],"id":1}' http://127.0.0.1:8588
result: {"jsonrpc":"2.0","id":1,"result":"0x19b5e90deb03cd4b87aca41ca09dcfed5e7c7ad33e6579f30f7efba722c54424"}personal_signRawFeeDelegateTransaction method
parameters
result
BlockChain node console을 이용한 방법
첫 번째로, personal.signTransaction을 이용하여 기존 DynamicFeeTxType의 Transaction을 생성합니다.
두 번째로, personal.signTransaction으로 생성한 raw와 새로 추가된 personal.signRawFeeDelegateTransaction으로 Fee Delegation Transaction을 생성합니다.
마지막으로, sendRawTransaction을 이용하여 Fee Delegation Transaction을 전송합니다.
personal.signRawFeeDelegateTransaction() RPC
parameters
result
web3.js , ethereumjs-util.js 와 fee delegation RLP encode, decode를 이용한 방법
Fee Delegation Transaction을 지원하기 위해 제공되는 FeeDelegateDecode.js, FeeDelegateEncode.js를 이용하고, 기존 web3.js를 사용하여 Fee Delegation Transaction 기능을 사용할 수 있습니다.
첫 번째로, node js를 설치합니다. https://nodejs.org/ko/download
두 번째로, web3.js, ethereumjs-util.js를 설치합니다.
세 번째로, 제공된 FeeDelegateDecode.js,FeeDelegateEncode.js, FeeDelegateSampleCode.js를 같은 폴더에 넣습니다.
마지막으로, node 명령어를 이용하여 FeeDelegateSampleCode.js를 실행합니다.
주의
wallet address와 privateKey를 사용 가능한 값으로 변경해야 합니다.
자세한 내용은 제공된 sample code를 참조하시면 됩니다.
sample code : FeeDelegateSampleCode.js
go-wemix : https://github.com/wemixarchive/go-wemix