Skip to content

Commit 84c0ea1

Browse files
committed
docs: update readme
1 parent b581451 commit 84c0ea1

File tree

1 file changed

+30
-14
lines changed

1 file changed

+30
-14
lines changed

README.md

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,23 +50,39 @@ After creating the instance, you can repeatedly use the `decode` method througho
5050
try {
5151
// Send a transaction that will revert
5252
} catch (err) {
53-
const decodedError: DecodedError = errorDecoder.decode(err)
53+
const decodedError: decodedError = await errorDecoder.decode(err)
5454
console.log(`Revert reason: ${decodedError.reason}`)
5555
}
5656
```
5757

58-
The `DecodedError` object is the result of the decoded error, which contains the following properties for handling errors:
58+
### Decoded Error
5959

60-
| Property | Value Type | Remarks |
61-
| ----------- | ---------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
62-
| `type` | `ErrorType` | The type of the error. For eg, a revert due to custom error will have `ErrorType.CustomError`. |
63-
| `reason` | `string \| null` | The decoded error message, or `null` if error is unknown or has no message. |
64-
| `data` | `string \| null` | The raw data bytes returned from the contract error, or `null` if error is unknown or empty. |
65-
| `args` | `Array` | The parameter values of the error if exists. For custom errors, the `args` will always be empty if no ABI or interface is supplied for decoding. |
66-
| `name` | `string \| null` | The name of the error. This can be used to identify the custom error emitted. For eg, `InvalidTokenSwap`. If no ABI is supplied for custom error, this will be the selector hex. `null` if error is `EmptyError`. |
67-
| `selector` | `string \| null` | The hexidecimal value of the selector. `null` if error is `EmptyError`. |
68-
| `signature` | `string \| null` | The signature of the error. `null` if error is `EmptyError` or no specified ABI for custom error. |
69-
| `fragment` | `string \| null` | The ABI fragment of the error. `null` if error is `EmptyError` or no specified ABI for custom error. |
60+
The `DecodedError` object is the result of the decoded error, which contains the following properties for handling the error occurred:
61+
62+
| Property | Value Type | Remarks |
63+
| ----------- | ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
64+
| `type` | `ErrorType` | The type of the error. See [Error Types](#error-types). |
65+
| `reason` | `string \| null` | The decoded error message, or `null` if error is unknown or has no message. |
66+
| `data` | `string \| null` | The raw data bytes returned from the contract error, or `null` if error is unknown or empty. |
67+
| `args` | `Array` | The parameter values of the error if exists. For custom errors, the `args` will always be empty if no ABI or interface is supplied for decoding. |
68+
| `name` | `string \| null` | The name of the error. This can be used to identify the custom error emitted. If no ABI is supplied for custom error, this will be the selector hex. If error is `RpcError`, this will be the error code. `null` if error is `EmptyError`. |
69+
| `selector` | `string \| null` | The hexidecimal value of the selector. `null` if error is `EmptyError`. |
70+
| `signature` | `string \| null` | The signature of the error. `null` if error is `EmptyError` or no specified ABI for custom error. |
71+
| `fragment` | `string \| null` | The ABI fragment of the error. `null` if error is `EmptyError` or no specified ABI for custom error. |
72+
73+
### Error Types
74+
75+
These are the possible `ErrorType` that could be returned for the `type` property in the `DecodedError` object:
76+
77+
| Type | Description |
78+
| --------------------------- | ----------------------------------------- |
79+
| `ErrorType.EmptyError` | Contract reverted without reason provided |
80+
| `ErrorType.RevertError` | Contract reverted with reason provided |
81+
| `ErrorType.PanicError` | Contract reverted due to a panic error |
82+
| `ErrorType.CustomError` | Contract reverted due to a custom error |
83+
| `ErrorType.UserRejectError` | User rejected the transaction |
84+
| `ErrorType.RpcError` | An error from the JSON RPC |
85+
| `ErrorType.UnknownError` | An unknown error was thrown |
7086

7187
## Examples
7288

@@ -132,7 +148,7 @@ try {
132148
const tx = await MyCustomErrorContract.swap('0xabcd', 123)
133149
await tx.wait()
134150
} catch (err) {
135-
const decodedError = errorDecoder.decode(err)
151+
const decodedError = await errorDecoder.decode(err)
136152
const reason = customReasonMapper(decodedError)
137153
// Prints "Invalid swap with token contract address 0xabcd."
138154
console.log('Custom error reason:', reason)
@@ -168,7 +184,7 @@ const errorDecoder = ErrorDecoder.create([myContractAbi, externalContractAbi])
168184

169185
try {...} catch (err) {
170186
// It's aware of errors from MyContract, ExternalContract and ExternalContract errors emitted from MyContract.
171-
const decodedError = errorDecoder.decode(err)
187+
const decodedError = await errorDecoder.decode(err)
172188
// ...
173189
}
174190
```

0 commit comments

Comments
 (0)