@dedot/contracts 0.18.4 → 0.18.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cjs/errors.js CHANGED
@@ -16,6 +16,31 @@ const formatDispatchError = (err, moduleError) => {
16
16
  return `Dispatch error: ${JSON.stringify(err)}`;
17
17
  }
18
18
  };
19
+ /**
20
+ * Formats a Solidity contract error message.
21
+ * If the error is the standard Solidity 'Error(string message)' pattern,
22
+ * extract and return the message string directly.
23
+ * Otherwise, return a formatted error name.
24
+ *
25
+ * @param details - The Solidity error result details.
26
+ * @returns A formatted error message string.
27
+ */
28
+ const formatSolErrorMessage = (details) => {
29
+ if (!details) {
30
+ return 'Unknown Error';
31
+ }
32
+ // Check if this is the standard Solidity Error(string) pattern
33
+ const isSolidityError = details.errorName === 'Error' &&
34
+ details.abiItem.inputs.length === 1 &&
35
+ details.abiItem.inputs[0]?.name === 'message' &&
36
+ details.abiItem.inputs[0]?.type === 'string';
37
+ if (isSolidityError && details.args && details.args.length > 0) {
38
+ // Extract the message from args[0]
39
+ return String(details.args[0]);
40
+ }
41
+ // Default format for other errors
42
+ return `Error: ${details.errorName}`;
43
+ };
19
44
  /**
20
45
  * Represents an error that occurred during the instantiation of a smart contract.
21
46
  * This class extends the base `DedotError` and includes a `raw` property of type `ContractInstantiateResult`.
@@ -220,7 +245,7 @@ class SolContractInstantiateError extends ContractInstantiateError {
220
245
  this.message = message;
221
246
  }
222
247
  else if (details) {
223
- this.message = `Error: ${details.errorName}`;
248
+ this.message = formatSolErrorMessage(details);
224
249
  }
225
250
  }
226
251
  }
@@ -243,7 +268,7 @@ class SolContractExecutionError extends ContractExecutionError {
243
268
  this.message = message;
244
269
  }
245
270
  else if (details) {
246
- this.message = `Error: ${details.errorName}`;
271
+ this.message = formatSolErrorMessage(details);
247
272
  }
248
273
  }
249
274
  }
@@ -83,8 +83,8 @@ class SolConstructorTxExecutor extends index_js_2.SolDeployerExecutor {
83
83
  return;
84
84
  const executor = new SolConstructorQueryExecutor_js_1.SolConstructorQueryExecutor(this.client, // --
85
85
  this.registry, this.code, {
86
- defaultCaller: signerAddress,
87
86
  ...this.options,
87
+ defaultCaller: signerAddress,
88
88
  });
89
89
  const { raw: { gasRequired, storageDeposit }, } = await executor.doExecute('new')(...params);
90
90
  // Replace the params with gas limit and storage deposit limit
@@ -37,8 +37,8 @@ class SolTxExecutor extends SolContractExecutor_js_1.SolContractExecutor {
37
37
  return;
38
38
  const executor = new SolQueryExecutor_js_1.SolQueryExecutor(this.client, // --
39
39
  this.registry, this.address, {
40
- defaultCaller: signerAddress,
41
40
  ...this.options,
41
+ defaultCaller: signerAddress,
42
42
  });
43
43
  const { raw } = await executor.doExecute(name)(...params);
44
44
  const { gasRequired, storageDeposit } = raw;
package/errors.js CHANGED
@@ -13,6 +13,31 @@ const formatDispatchError = (err, moduleError) => {
13
13
  return `Dispatch error: ${JSON.stringify(err)}`;
14
14
  }
15
15
  };
16
+ /**
17
+ * Formats a Solidity contract error message.
18
+ * If the error is the standard Solidity 'Error(string message)' pattern,
19
+ * extract and return the message string directly.
20
+ * Otherwise, return a formatted error name.
21
+ *
22
+ * @param details - The Solidity error result details.
23
+ * @returns A formatted error message string.
24
+ */
25
+ const formatSolErrorMessage = (details) => {
26
+ if (!details) {
27
+ return 'Unknown Error';
28
+ }
29
+ // Check if this is the standard Solidity Error(string) pattern
30
+ const isSolidityError = details.errorName === 'Error' &&
31
+ details.abiItem.inputs.length === 1 &&
32
+ details.abiItem.inputs[0]?.name === 'message' &&
33
+ details.abiItem.inputs[0]?.type === 'string';
34
+ if (isSolidityError && details.args && details.args.length > 0) {
35
+ // Extract the message from args[0]
36
+ return String(details.args[0]);
37
+ }
38
+ // Default format for other errors
39
+ return `Error: ${details.errorName}`;
40
+ };
16
41
  /**
17
42
  * Represents an error that occurred during the instantiation of a smart contract.
18
43
  * This class extends the base `DedotError` and includes a `raw` property of type `ContractInstantiateResult`.
@@ -211,7 +236,7 @@ export class SolContractInstantiateError extends ContractInstantiateError {
211
236
  this.message = message;
212
237
  }
213
238
  else if (details) {
214
- this.message = `Error: ${details.errorName}`;
239
+ this.message = formatSolErrorMessage(details);
215
240
  }
216
241
  }
217
242
  }
@@ -233,7 +258,7 @@ export class SolContractExecutionError extends ContractExecutionError {
233
258
  this.message = message;
234
259
  }
235
260
  else if (details) {
236
- this.message = `Error: ${details.errorName}`;
261
+ this.message = formatSolErrorMessage(details);
237
262
  }
238
263
  }
239
264
  }
@@ -80,8 +80,8 @@ export class SolConstructorTxExecutor extends SolDeployerExecutor {
80
80
  return;
81
81
  const executor = new SolConstructorQueryExecutor(this.client, // --
82
82
  this.registry, this.code, {
83
- defaultCaller: signerAddress,
84
83
  ...this.options,
84
+ defaultCaller: signerAddress,
85
85
  });
86
86
  const { raw: { gasRequired, storageDeposit }, } = await executor.doExecute('new')(...params);
87
87
  // Replace the params with gas limit and storage deposit limit
@@ -34,8 +34,8 @@ export class SolTxExecutor extends SolContractExecutor {
34
34
  return;
35
35
  const executor = new SolQueryExecutor(this.client, // --
36
36
  this.registry, this.address, {
37
- defaultCaller: signerAddress,
38
37
  ...this.options,
38
+ defaultCaller: signerAddress,
39
39
  });
40
40
  const { raw } = await executor.doExecute(name)(...params);
41
41
  const { gasRequired, storageDeposit } = raw;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dedot/contracts",
3
- "version": "0.18.4",
3
+ "version": "0.18.6",
4
4
  "description": "Delightful ink! Contract APIs",
5
5
  "author": "Tung Vu <tung@dedot.dev>",
6
6
  "homepage": "https://dedot.dev",
@@ -18,10 +18,10 @@
18
18
  "test": "npx vitest --watch=false"
19
19
  },
20
20
  "dependencies": {
21
- "@dedot/api": "0.18.4",
22
- "@dedot/codecs": "0.18.4",
23
- "@dedot/types": "0.18.4",
24
- "@dedot/utils": "0.18.4",
21
+ "@dedot/api": "0.18.6",
22
+ "@dedot/codecs": "0.18.6",
23
+ "@dedot/types": "0.18.6",
24
+ "@dedot/utils": "0.18.6",
25
25
  "viem": "^2.37.7"
26
26
  },
27
27
  "publishConfig": {
@@ -32,7 +32,7 @@
32
32
  "node": ">=18"
33
33
  },
34
34
  "license": "Apache-2.0",
35
- "gitHead": "ccfe55a98b0a7244b7fc0974c269f2c90b2a1f4d",
35
+ "gitHead": "2ff0200696aa2e42505d30369fe84b2416838791",
36
36
  "module": "./index.js",
37
37
  "types": "./index.d.ts",
38
38
  "exports": {