Rationale
The Bridge SC has been updated to return custom errors instead of just strings when the transaction reverts.
We cannot access the data returned by a revert error when estimating the gas through a MetaMask provider, so to get the error we need to do a call before the gas estimation to simulate a gas estimation and retrieve the raw data of the call.
- If
data is 0x the call has succeed, so we can proceed with the real tx.
- If
data is 4 bytes length the call reverted with a custom error, so we can proceed to decode it and show it to the users.
- If
data is more than 4 bytes length the call reverted with a string error so we can just proceed with the real tx and MetaMask will return the error. This scenario can happen if the Bridge UI calls another contract that doesn't return custom errors when it reverts.
Implementation
Quick example about how we should parse the custom errors:
// Simulates gas estimation
const callData = await ethers.provider.call({
from: userAddress,
to: bridgeSC,
data: txData
});
const customError = bridgeSC.interface.parseError(call)
Rationale
The Bridge SC has been updated to return custom errors instead of just strings when the transaction reverts.
We cannot access the data returned by a revert error when estimating the gas through a MetaMask provider, so to get the error we need to do a
callbefore the gas estimation to simulate a gas estimation and retrieve the raw data of the call.datais0xthe call has succeed, so we can proceed with the real tx.datais 4 bytes length the call reverted with a custom error, so we can proceed to decode it and show it to the users.datais more than 4 bytes length the call reverted with a string error so we can just proceed with the real tx and MetaMask will return the error. This scenario can happen if the Bridge UI calls another contract that doesn't return custom errors when it reverts.Implementation
Quick example about how we should parse the custom errors: