안녕하세요. wallet API 중 아래 "키를 이용한 데이터 서명"을 이용하여, transaction 에 sign 을 하고자 합니다. 과정에서 어려움이 있어 도움을 청합니다.
-
api 결과값으로 받은 signedData 를 eth_sendRawTransaction 을 통해 전송하려 하는데, 결과값을 그대로 이용해도 무방한가요? 결과적으로 web3js 의
web3.eth.accounts.signTransaction
가 주는 결과값과 동일한 값이 필요합니다. -
api 가 32 byte 로 제한된 데이터를 파라미터로 받고 있는데, 이를 위해 transaction object 을 올바르게변환하는 방법이 궁금합니다. 아래는 현재 테스트 중인 코드 예시입니다.
import { Transaction as EthereumTx } from 'ethereumjs-tx';
const getTx = async () => {
const Web3 = await import('web3').then((a) => a.Web3);
const tokenContract = new web3.eth.Contract(ERC20_TRANSFER_ABI, CONTRACT_ADDRESS);
const txData = tokenContract.methods.transfer(recipientAddr, TRANSFER_VALUE).encodeABI();
const rawTx = {
from: senderAddress,
to: CONTRACT_ADDRESS,
chainId: 8217,
gas: 300000,
gasPrice: 25000000000,
data: txData,
nonce: 10, // next nonce
};
const ethereumTx = new EthereumTx(rawTx);
// 1. const hexData = '0x' + ethereumTx.serialize().toString('hex');
// 2. const hexData2 = '0x' + ethereumTx.hash(true).toString('hex');
// 3. ...rlp encode?
};