You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Dispatch errors are not properly forwarded from typechain-polkadot. The query will pass if the transaction is valid but then the dispatch error is not properly unpacked, resulting in the unhelpful
{"message":"Module"}
Checking polkadot apps shows
system.ExtrinsicFailed
An extrinsic failed.
dispatchError: SpRuntimeDispatchError
{
Module: {
index: 8
error: 0x06000000
}
}
type
contracts.ContractNotFound
It seems like there is no way to access the dispatch error from typechain polkadot. I can assign the transaction result to a const but it is never populated as the error is thrown within typechain-polkadot
const txResult = await tasks.contract.tx.myFunction(...myArgs) // txResult is never populated
Instead I have to catch the error from the transaction
try {
const txResult = await tasks.contract.tx.myFunction(...myArgs) // txResult is never populated
} catch (err) {
logger.error(JSON.stringify(err)) // the module error appears here
}
Decode the dispatch error before throwing the error so that the relevant error message is thrown when the user uses try-catch
or
Not throw an error and pass through the raw error information to the user. The user would then have to decode the error with the registry.
// Convert a dispatch error to a readable message
export function getDispatchError(dispatchError: DispatchError): string {
if (dispatchError.isModule) {
try {
const mod = dispatchError.asModule
const error = dispatchError.registry.findMetaError(mod)
...
}
Personally, I prefer option 1 as option 2 is what polkadot-js does and it leaves a lot of complexity to the smart contract developer.
Maybe there is an option 3. which is
Decode the error and not throw, simply passing passing back the decoded error in result.error, again allowing the user to decide when to throw.
The text was updated successfully, but these errors were encountered:
Hi,
Dispatch errors are not properly forwarded from typechain-polkadot. The query will pass if the transaction is valid but then the dispatch error is not properly unpacked, resulting in the unhelpful
Checking polkadot apps shows
It seems like there is no way to access the dispatch error from typechain polkadot. I can assign the transaction result to a const but it is never populated as the error is thrown within typechain-polkadot
Instead I have to catch the error from the transaction
Logger output only gives
Therefore, you either need to
or
Personally, I prefer option 1 as option 2 is what polkadot-js does and it leaves a lot of complexity to the smart contract developer.
Maybe there is an option 3. which is
result.error
, again allowing the user to decide when to throw.The text was updated successfully, but these errors were encountered: