[SDK] @TODO: the returned hash did not match #814
Replies: 4 comments 8 replies
-
It seems like you're encountering an issue where the transaction hash returned by the Here are a few steps you can take to troubleshoot and potentially resolve this issue:
If these steps do not resolve the issue, consider providing more details such as the exact error message and transaction details to the ZKsync developers community for further assistance. Your feedback helps us serve you better. If this fully addresses your question, please give it a thumbs up. If it doesn't, please give it a thumbs down. This will inform the community and team so we can improve our support. |
Beta Was this translation helpful? Give feedback.
-
Hi, this seems to be a bug in zksync-ethers. Please tell me the exact version of zksync-ethers you are using? Could you also provide a full reproduction example? I believe it may matter how you are calling zksync-ethers to send the transaction and this is not shown in the provided code example. |
Beta Was this translation helpful? Give feedback.
-
The EIP712 transaction is not constructed correctly and that is why hashes don't match. Here is the updated example for minimal changes that works on Sepolia: const provider = Provider.getDefaultProvider(types.Network.Sepolia);
const PRIVATE_KEY = process.env.PRIVATE_KEY;
const wallet = new Wallet(PRIVATE_KEY, provider);
function serializePaymasterTx(
{transaction, signature}: { transaction: types.TransactionLike; signature: string; }
) {
return utils.serializeEip712(
{
...transaction,
customData: {...transaction.customData, customSignature: signature},
},
signature
);
}
async function sendTransaction(transaction: types.TransactionLike) {
const signer = new EIP712Signer(new ethers.Wallet(PRIVATE_KEY), Number((await provider.getNetwork()).chainId));
const signature = await signer.sign(transaction)
const rawTransaction = serializePaymasterTx({
transaction,
signature,
});
return await provider.broadcastTransaction(rawTransaction);
}
const tokenAddress = '0x927488F48ffbc32112F1fF721759649A89721F8F'; // Crown token which can be minted for free
const paymasterAddress = '0x13D0D8550769f59aa241a41897D4859c87f7Dd46'; // Paymaster for Crown token
const tx = await sendTransaction({
chainId: (await provider.getNetwork()).chainId,
from: wallet.address,
to: '0x81E9D85b65E9CC8618D85A1110e4b1DF63fA30d9',
value: ethers.parseEther('0.01'),
nonce: await wallet.getNonce(),
gasLimit: 200_000n,
maxFeePerGas: 250_000_000_000n,
customData: {
paymasterParams: utils.getPaymasterParams(paymasterAddress, {
type: 'ApprovalBased',
token: tokenAddress,
minimalAllowance: 1,
innerInput: new Uint8Array(),
})
}
})
const receipt = await tx.wait();
console.log(receipt); output:
The easiest way is to utilize EIP712Signer. If that does not work for you, there is also static method Eip712Signer.getSignedDigest that returns the hash of the typed data. You just need to sign the hash to get the signature of the typed data. |
Beta Was this translation helpful? Give feedback.
-
I have created a full reproduction project: It created a basic Send transaction and uses zksync paymaster api The "wrong hash" error is reproduced: @cytadela8 @danijelTxFusion Please check it out |
Beta Was this translation helpful? Give feedback.
-
Team or Project
No response
Select the SDK
JavaScript
Environment
Mainnet
Issue Description
This is literally an error returned by the lib:
https://github.com/zksync-sdk/zksync-ethers/blob/dcbb6636e26656283e954b31f288f51bc25b9639/src/provider.ts#L996
Well thanks for the detailed explanation. Why doesn't it match?
And how come node successfully accepted such transaction?
I faced similar error in
ethers@v5
before: #508Now I updated to
ethers@v6
and I have this error again.Expected Behavior
¯\_(ツ)_/¯
Code Example
Something like this:
Repo Link (Optional)
No response
Beta Was this translation helpful? Give feedback.
All reactions