1

I have a pending signed tx object received through subscribe on pending transactions in js. I need to build raw tx data to be able to send it directly to the network, but the following code does not seem to work (knowing that txFields.from is the signer):

const sig = ethers.utils.splitSignature(sigFields);
const rawTx = ethers.utils.serializeTransaction(txFields, sig);
assertEq(await ethers.utils.verifyMessage(rawTx, sig), txFields.from, 'Invalid signer');

Is there anything wrong with this code?

1 Answer 1

0

The problem was with the content of txFields and sigFields. I succeeded to solve it as follows:

const txFields = {
    chainId: parseInt(tx.chainId, 16),
    gasPrice: Number(tx.gasPrice),
    nonce: tx.nonce,
    to: tx.to,
    type: tx.type,
    value: tx.value
} as any;
if (tx.accessList) {
    txFields.accessList = tx.accessList;
}
if (tx.gas) {
    txFields.gasLimit = tx.gas;
}
if (tx.maxFeePerGas) {
    txFields.maxFeePerGas = tx.maxFeePerGas;
}
if (tx.maxPriorityFeePerGas) {
    txFields.maxPriorityFeePerGas = tx.maxPriorityFeePerGas;
}
if (tx.data || tx.input) {
    txFields.data = tx.data || tx.input;
}
if (!tx.type) {
    txFields.value = ethers.BigNumber.from(tx.value);
}
const sigFields = {
    r: tx.r,
    s: tx.s,
    v: parseInt(tx.v, 16)
} as any;

const sig = ethers.utils.splitSignature(sigFields);
const rawSignedTx = ethers.utils.serializeTransaction(txFields, sig);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.