Recognize "0" as a legacy transaction type in serializeTransaction #1549
-
Describe the bug
Seems the source of the error is this check which assumes transactions will have Reproduction steps const ethers = require('ethers')
const main = async () => {
const endpoint = 'https://mainnet.infura.io/v3/whatever'
const provider = new ethers.providers.JsonRpcProvider(endpoint)
const block = await provider.getBlockWithTransactions(46147)
const transaction = block.transactions[0]
console.log(ethers.utils.serializeTransaction({
type: transaction.type,
chainId: transaction.chainId,
nonce: transaction.nonce,
gasPrice: transaction.gasPrice,
gasLimit: transaction.gasLimit,
to: transaction.to,
value: transaction.value,
data: transaction.data
})) // Error!
}
main() Environment: |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hmmm after digging a little further it seems like I'm not supposed to be using undefined which will still pass because undefined == null .
|
Beta Was this translation helpful? Give feedback.
-
This is intentional; you should not use type For your purposes, you should probably use You could do something like |
Beta Was this translation helpful? Give feedback.
This is intentional; you should not use type
0
, as it is not actually reserved in the EIP (so theoretically you could have a future transaction envelope version0
which has some other behaviour). I've asked as well for type0x19
to be reserved, but the EIP authors would prefer that be moved to some other registry. But for now, I think it is safe to assume0x00
and0x19
are considered reserved from an application point of view, but that isn't safe at the library level.For your purposes, you should probably use
null
, but if your project has the TypeScript flagstrict
configured, you will need to useundefined
(either will work, but I had intended for people to usenull
). In v6, the library…