diff --git a/.changeset/witty-yaks-count.md b/.changeset/witty-yaks-count.md new file mode 100644 index 0000000000..cce214694e --- /dev/null +++ b/.changeset/witty-yaks-count.md @@ -0,0 +1,5 @@ +--- +"viem": patch +--- + +Fixed issue where the `transactionRequest` formatter would supply redundant properties. diff --git a/src/op-stack/actions/depositTransaction.test.ts b/src/op-stack/actions/depositTransaction.test.ts index dd35d76c1f..a7de5d6a70 100644 --- a/src/op-stack/actions/depositTransaction.test.ts +++ b/src/op-stack/actions/depositTransaction.test.ts @@ -312,7 +312,7 @@ test('error: small gas', async () => { [ContractFunctionExecutionError: Transaction creation failed. URL: http://localhost - Request body: {"method":"eth_estimateGas","params":[{"from":"0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266","data":"0xe9e05c42000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb9226600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005208000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000","gas":"0x45","to":"0x49048044D57e1C92A77f79988d21Fa8fAF74E97e"}]} + Request body: {"method":"eth_estimateGas","params":[{"data":"0xe9e05c42000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb9226600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005208000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000","from":"0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266","gas":"0x45","to":"0x49048044D57e1C92A77f79988d21Fa8fAF74E97e"}]} Estimate Gas Arguments: from: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266 diff --git a/src/op-stack/actions/finalizeWithdrawal.test.ts b/src/op-stack/actions/finalizeWithdrawal.test.ts index 9e2446c67d..0db8511ddc 100644 --- a/src/op-stack/actions/finalizeWithdrawal.test.ts +++ b/src/op-stack/actions/finalizeWithdrawal.test.ts @@ -114,7 +114,7 @@ test('error: small gas', async () => { [ContractFunctionExecutionError: Transaction creation failed. URL: http://localhost - Request body: {"method":"eth_estimateGas","params":[{"from":"0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266","data":"0x8c3152e900000000000000000000000000000000000000000000000000000000000000200001000000000000000000000000000000000000000000000000000000002d51000000000000000000000000420000000000000000000000000000000000000700000000000000000000000025ace71c97b33cc4729cf772ae268934f7ab5fa1000000000000000000000000000000000000000000000004c7fa16770649c8fc000000000000000000000000000000000000000000000000000000000004638800000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000001a4d764ad0b0001000000000000000000000000000000000000000000000000000000002d51000000000000000000000000420000000000000000000000000000000000001000000000000000000000000099c9fc46f92e8a1c0dec1b1747d010903e884be1000000000000000000000000000000000000000000000004c7fa16770649c8fc000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000a41635f5fd000000000000000000000000160d7aa81e6fc30210aeb915c3bb1f55bfa86b37000000000000000000000000160d7aa81e6fc30210aeb915c3bb1f55bfa86b37000000000000000000000000000000000000000000000004c7fa16770649c8fc000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","gas":"0x45","to":"0xbEb5Fc579115071764c7423A4f12eDde41f106Ed"}]} + Request body: {"method":"eth_estimateGas","params":[{"data":"0x8c3152e900000000000000000000000000000000000000000000000000000000000000200001000000000000000000000000000000000000000000000000000000002d51000000000000000000000000420000000000000000000000000000000000000700000000000000000000000025ace71c97b33cc4729cf772ae268934f7ab5fa1000000000000000000000000000000000000000000000004c7fa16770649c8fc000000000000000000000000000000000000000000000000000000000004638800000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000001a4d764ad0b0001000000000000000000000000000000000000000000000000000000002d51000000000000000000000000420000000000000000000000000000000000001000000000000000000000000099c9fc46f92e8a1c0dec1b1747d010903e884be1000000000000000000000000000000000000000000000004c7fa16770649c8fc000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000a41635f5fd000000000000000000000000160d7aa81e6fc30210aeb915c3bb1f55bfa86b37000000000000000000000000160d7aa81e6fc30210aeb915c3bb1f55bfa86b37000000000000000000000000000000000000000000000004c7fa16770649c8fc000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","from":"0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266","gas":"0x45","to":"0xbEb5Fc579115071764c7423A4f12eDde41f106Ed"}]} Estimate Gas Arguments: from: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266 diff --git a/src/op-stack/actions/initiateWithdrawal.test.ts b/src/op-stack/actions/initiateWithdrawal.test.ts index bf966930a6..e93c3d0cb4 100644 --- a/src/op-stack/actions/initiateWithdrawal.test.ts +++ b/src/op-stack/actions/initiateWithdrawal.test.ts @@ -105,7 +105,7 @@ test('error: insufficient funds', async () => { [ContractFunctionExecutionError: Transaction creation failed. URL: http://localhost - Request body: {"method":"eth_estimateGas","params":[{"from":"0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266","data":"0xc2b3e5ac000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266000000000000000000000000000000000000000000000000000000000000520800000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000004deadbeef00000000000000000000000000000000000000000000000000000000","gas":"0x45","to":"0x4200000000000000000000000000000000000016","value":"0x43c33c1937564800000"}]} + Request body: {"method":"eth_estimateGas","params":[{"data":"0xc2b3e5ac000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266000000000000000000000000000000000000000000000000000000000000520800000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000004deadbeef00000000000000000000000000000000000000000000000000000000","from":"0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266","gas":"0x45","to":"0x4200000000000000000000000000000000000016","value":"0x43c33c1937564800000"}]} Estimate Gas Arguments: from: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266 @@ -142,7 +142,7 @@ test('error: small gas', async () => { [ContractFunctionExecutionError: Transaction creation failed. URL: http://localhost - Request body: {"method":"eth_estimateGas","params":[{"from":"0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266","data":"0xc2b3e5ac000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266000000000000000000000000000000000000000000000000000000000000520800000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000004deadbeef00000000000000000000000000000000000000000000000000000000","gas":"0x45","to":"0x4200000000000000000000000000000000000016","value":"0xde0b6b3a7640000"}]} + Request body: {"method":"eth_estimateGas","params":[{"data":"0xc2b3e5ac000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266000000000000000000000000000000000000000000000000000000000000520800000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000004deadbeef00000000000000000000000000000000000000000000000000000000","from":"0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266","gas":"0x45","to":"0x4200000000000000000000000000000000000016","value":"0xde0b6b3a7640000"}]} Estimate Gas Arguments: from: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266 diff --git a/src/utils/formatters/transactionRequest.test.ts b/src/utils/formatters/transactionRequest.test.ts index c5ce0e9bd2..412ddb86c0 100644 --- a/src/utils/formatters/transactionRequest.test.ts +++ b/src/utils/formatters/transactionRequest.test.ts @@ -139,6 +139,30 @@ test('eip4844 transaction', () => { "value": "0x1", } `) + + expect( + formatTransactionRequest({ + ...base, + blobs: [Uint8Array.from([0xab, 0xc])], + from: '0x0000000000000000000000000000000000000000', + maxFeePerBlobGas: 69n, + type: 'eip4844', + } as TransactionRequestEIP4844), + ).toMatchInlineSnapshot(` + { + "blobs": [ + "0xab0c", + ], + "data": "0x1", + "from": "0x0000000000000000000000000000000000000000", + "gas": "0x4234584", + "maxFeePerBlobGas": "0x45", + "nonce": "0x1", + "to": "0x1", + "type": "0x3", + "value": "0x1", + } + `) }) test('nullish gas', () => { @@ -151,7 +175,6 @@ test('nullish gas', () => { { "data": "0x1", "from": "0x1", - "gas": undefined, "nonce": "0x1", "to": "0x1", "value": "0x1", @@ -170,7 +193,6 @@ test('nullish gasPrice', () => { "data": "0x1", "from": "0x1", "gas": "0x4234584", - "gasPrice": undefined, "nonce": "0x1", "to": "0x1", "value": "0x1", @@ -189,7 +211,6 @@ test('nullish maxFeePerGas', () => { "data": "0x1", "from": "0x1", "gas": "0x4234584", - "maxFeePerGas": undefined, "nonce": "0x1", "to": "0x1", "value": "0x1", @@ -208,7 +229,6 @@ test('nullish maxPriorityFeePerGas', () => { "data": "0x1", "from": "0x1", "gas": "0x4234584", - "maxPriorityFeePerGas": undefined, "nonce": "0x1", "to": "0x1", "value": "0x1", @@ -227,7 +247,6 @@ test('nullish nonce', () => { "data": "0x1", "from": "0x1", "gas": "0x4234584", - "nonce": undefined, "to": "0x1", "value": "0x1", } @@ -247,7 +266,6 @@ test('nullish value', () => { "gas": "0x4234584", "nonce": "0x1", "to": "0x1", - "value": undefined, } `) }) diff --git a/src/utils/formatters/transactionRequest.ts b/src/utils/formatters/transactionRequest.ts index f515b87f34..4f8474338e 100644 --- a/src/utils/formatters/transactionRequest.ts +++ b/src/utils/formatters/transactionRequest.ts @@ -30,13 +30,19 @@ export type FormatTransactionRequestErrorType = ErrorType export function formatTransactionRequest( request: ExactPartial, ) { - const rpcRequest = { ...request } as RpcTransactionRequest + const rpcRequest = {} as RpcTransactionRequest - if ( - typeof request.blobs !== 'undefined' && - typeof request.blobs[0] !== 'string' - ) - rpcRequest.blobs = (request.blobs as ByteArray[]).map((x) => bytesToHex(x)) + if (typeof request.accessList !== 'undefined') + rpcRequest.accessList = request.accessList + if (typeof request.blobs !== 'undefined') { + if (typeof request.blobs[0] !== 'string') + rpcRequest.blobs = (request.blobs as ByteArray[]).map((x) => + bytesToHex(x), + ) + else rpcRequest.blobs = request.blobs + } + if (typeof request.data !== 'undefined') rpcRequest.data = request.data + if (typeof request.from !== 'undefined') rpcRequest.from = request.from if (typeof request.gas !== 'undefined') rpcRequest.gas = numberToHex(request.gas) if (typeof request.gasPrice !== 'undefined') @@ -49,6 +55,7 @@ export function formatTransactionRequest( rpcRequest.maxPriorityFeePerGas = numberToHex(request.maxPriorityFeePerGas) if (typeof request.nonce !== 'undefined') rpcRequest.nonce = numberToHex(request.nonce) + if (typeof request.to !== 'undefined') rpcRequest.to = request.to if (typeof request.type !== 'undefined') rpcRequest.type = rpcTransactionType[request.type] if (typeof request.value !== 'undefined')