provider.getTransaction discussion (v5 vs v6 changes) #4553
Replies: 15 comments 1 reply
-
Can you please include the |
Beta Was this translation helpful? Give feedback.
-
Yes! of course! what a fast answer! anyway, i posted directly because this exact code is working with V5 but not on V6 and i would like to update my app raw: txHash: '0x65723d375b20024371f80b97d9e89e3260356546b5715263839d66d2f04fbdba', i also tried to don't serialize the transaction but result is the same.. transactions raw come from: switch (tx.type) { if (sign) transaction = transaction.sign(privateKey); const raw = '0x' + transaction.serialize().toString('hex') |
Beta Was this translation helpful? Give feedback.
-
I get I also get the correct hash in both v5 and v6: // v5
parseTransaction(data).hash
// "0x7ecbfd837a76a70d446beed59b3d8cbd75da7037611a5e0d8c0a382c43f7680e"
// v6
Transaction.from(data).hash
// "0x7ecbfd837a76a70d446beed59b3d8cbd75da7037611a5e0d8c0a382c43f7680e" I'm not quite sure what the above code is doing; are you using the EthereumJS library for that? I'm not super familiar with their API, but it looks like it. If you want to produce a signed transaction, you should be able to do something like: // Create a Transaction object; starts off unsigned
const txParams = { type, to, value, data }; // and such
const tx = Transaction.from(txParams);
// Or if you have the serialized transaction already
// const tx = Transaction.from(txData)
// Add a signature by signing the unsignedHash
tx.signature = signingKey.sign(tx.unsignedHash);
// The signed transaction hex:
tx.serialized If you provide concrete examples of the inputs and outputs, I can provide examples with the values interleaved. :) |
Beta Was this translation helpful? Give feedback.
-
Random note; in v6 the Transaction object is a live object; you can update explicit values and the derived values are getters that will automatically be updated: > t = new Transaction()
> t.unsignedSerialized
'0x02c98080808080808080c0'
> t.value = 123
> t.unsignedSerialized
'0x02c98080808080807b80c0'
> t.to = "0x1234567890123456789012345678901234567890"
> t.unsignedSerialized
'0x02dd80808080809412345678901234567890123456789012345678907b80c0'
> t.type = 1
> t.unsignedSerialized
'0x01dc808080809412345678901234567890123456789012345678907b80c0' |
Beta Was this translation helpful? Give feedback.
-
i imported both ethers v5 and v6 in the project.. and this is what i discovered hashes from mempool are different because txs are different, but the focus is on that V5 gives me always the same calculated keccak of tx hash from mempool and a tx read from V6 doesn't tx read from V5 provider (provider = new ethers.providers.WebSocketProvider(WSS);) tx read from V6 provider (provider = new ethers.WebSocketProvider(WSS);) when i get a raw transaction from provider created with V5 the keccak of: is the same as the hash i get from mempool, when i use the provider created with V6 is different. Keccak calc is the same for V5 and V6, verified. Something else is happening, the codebase is the same 😱 i'm trying to understand what is causing this difference digging more, but it's clear that there's a difference, i just still don't know what it is |
Beta Was this translation helpful? Give feedback.
-
Oh! Can you also make sure you update to the latest version, 6.10.0? There is an issue where nodes return different values for things in the mempool. One thing we noticed is that |
Beta Was this translation helpful? Give feedback.
-
Yes, i tried also with 6.10.0, i found the problem... i think that there's absolutely no bugs, it's just the type changed from V5 provider to V6, so passing the tx to ethereumjs is not valid anymore.. i didn't find this mentioned in the migration guide This is a V5 provider transaction from getTransaction method: this is V6: Same transaction of course, values are the same but structure is different.. i wonder if there is some method to get the tx in the old format, or i need to update my method to check the hash, maybe updating the ethereumjs lib |
Beta Was this translation helpful? Give feedback.
-
Oh, I see. My guess is because the various Signature properties (r, s, v, yParity, etc) are wrapped up in a separate const flatTx = Object.assign({ }, tx.toJSON(), tx.signature?.toJSON()); The other option, I wonder, is there a way to pass the |
Beta Was this translation helpful? Give feedback.
-
I tried both, the final solution is this (this is quick&dirty, just to test it) transaction is the TransactionResponse from pending event, it works like the old v5 response but, with the serialized i get undefined on transaction.serialized (using v6.10.0) anyway, i got one working solution, but i don't know if it's really optimized to make those operations or switch back to ethers-v5 and use the transaction as is.. (i need to scan 500-1000 txs every block) maybe there is a better way to accomplish the result |
Beta Was this translation helpful? Give feedback.
-
Oh! I think you don't have a For example: const provider = new ethers.InfuraProvider();
const txHash = "0xa8e82eed99f8266999decb5ee4ac0fed95ceb1519581d4d3c079c4029c775acc";
// This is just a response from the server; it has only had minor validation done and is a regular object
const txResp = await provider.getTransaction(txHash);
// This object is the fully live instance
const tx = Transaction.from(txResp);
console.log(tx.serialized);
// "0x02f8760183057889843b9aca00853c89352800830186a094b745a4f78f9c468cb9c8e4b74d039dc0ca2ecacb87e880f8a4ae401380c080a0fc739c87ecb5302390c056f7372f7c2b6aff0df3a3e987b154b07797b3ff49d0a07d1db03dede03327046d51d315b4b2a72b3f5ab988973fdf2eabdfa06e6d7c1f"
console.log(tx.serialized);
// "0xa8e82eed99f8266999decb5ee4ac0fed95ceb1519581d4d3c079c4029c775acc" Does that make sense? |
Beta Was this translation helpful? Give feedback.
-
yes, i wrote that is a TransactionResponse, anyway will try that also, but what's the performance gain using ethers-v6 in the project? is the Transaction.from() and expensive operation if i have to scan the mempool and analyze every tx? |
Beta Was this translation helpful? Give feedback.
-
Transaction.from is basically just doing what you were doing, copying over the values. But it computes derived values lazily, so it doesn’t compute anything you don’t need. There hasn’t been a v5 release in over a year. I am planning one to fix a few small things over the next week, so there will be a minor version bump of v5 soon, but using v6 will ensure you get the latest bug fixed and blockchain features. I haven’t done any benchmarks but v6 uses Nobel/BigInt for all internal operations while v5 uses elliptic/BN.js, so I would expect a much faster That said, v5 remains stable, which is why it hasn’t required any updates in a year. :) |
Beta Was this translation helpful? Give feedback.
-
I don't know why but passing the TransactionResponse object to Transaction.from i get an empty object, anyway it seems that the from() takes a few milliseconds to run, maybe it's better for me to keep the V5 until i sort out all the things, i'm in the middle of a refactoring, that's why i wanted to try out the V6 (i'm always happy to use the latest available versions) time: 3.8791000000055647 tx Transaction {} while converting with the object.assign seems a lot faster (and working!) As soon as i finish the refactoring i will test the whole code with v5 and v6 because it's important for me to have the fastest code possible |
Beta Was this translation helpful? Give feedback.
-
i changed the title so people don't get confused reading it |
Beta Was this translation helpful? Give feedback.
-
@NaliFinance The object isn't empty. The If you spot anything in the Transactin object you believe could be causing it to be slower too, please let me know. :) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Ethers Version
6.7.1
Search Terms
keccak v6
Describe the Problem
The keccak256 function gives a different result upgrading to v6
V6 code throw the exception.. what is changed from V5 to V6?
Code Snippet
Contract ABI
No response
Errors
No response
Environment
Ethereum (mainnet/ropsten/rinkeby/goerli), node.js (v12 or newer), Geth
Environment (Other)
No response
Beta Was this translation helpful? Give feedback.
All reactions