Handle errors when deploying contracts
Copy import {
isContractInstantiateDispatchError , isContractInstantiateLangError
} from "dedot/contracts" ;
import { FlipperContractApi } from "./flipper" ;
const ALICE = '...' ;
try {
// Dry-run contract construction
const dryRun = await deployer . query .new ( true , { caller : ALICE })
// ...
} catch (e : any ) {
if ( isContractInstantiateDispatchError < FlipperContractApi >(e)) {
// Getting a runtime level error (e.g: Module error, Overflow error ...)
const { dispatchError , raw } = e;
const errorMeta = client . registy .findErrorMeta (dispatchError);
// ...
}
if ( isContractInstantiateLangError < FlipperContractApi >(e)) {
const { langError , raw } = e;
console .log ( 'LangError' , langError);
}
// Other errors ...
}
Handle errors when interacting with contracts
Copy import {
isContractDispatchError , isContractLangError
} from "dedot/contracts" ;
import { FlipperContractApi } from "./flipper" ;
const ALICE = '...' ;
try {
// Dry-run mutable contract message
const dryRun = await contract . query .flip ({ caller : ALICE })
// ...
} catch (e : any ) {
if ( isContractDispatchError < FlipperContractApi >(e)) {
// Getting a runtime level error (e.g: Module error, Overflow error ...)
const { dispatchError , raw } = e;
const errorMeta = client . registy .findErrorMeta (dispatchError);
// ...
}
if ( isContractLangError < FlipperContractApi >(e)) {
const { langError , raw } = e;
console .log ( 'LangError' , langError);
}
// Other errors ...
}