@metamask/transaction-controller 60.4.0 → 60.5.0
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/CHANGELOG.md +16 -1
- package/dist/TransactionController.cjs +9 -45
- package/dist/TransactionController.cjs.map +1 -1
- package/dist/TransactionController.d.cts.map +1 -1
- package/dist/TransactionController.d.mts.map +1 -1
- package/dist/TransactionController.mjs +11 -47
- package/dist/TransactionController.mjs.map +1 -1
- package/dist/types.cjs +16 -0
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +16 -0
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +16 -0
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs +16 -0
- package/dist/types.mjs.map +1 -1
- package/dist/utils/first-time-interaction.cjs +77 -0
- package/dist/utils/first-time-interaction.cjs.map +1 -0
- package/dist/utils/first-time-interaction.d.cts +30 -0
- package/dist/utils/first-time-interaction.d.cts.map +1 -0
- package/dist/utils/first-time-interaction.d.mts +30 -0
- package/dist/utils/first-time-interaction.d.mts.map +1 -0
- package/dist/utils/first-time-interaction.mjs +73 -0
- package/dist/utils/first-time-interaction.mjs.map +1 -0
- package/dist/utils/transaction-type.cjs +22 -5
- package/dist/utils/transaction-type.cjs.map +1 -1
- package/dist/utils/transaction-type.d.cts +14 -0
- package/dist/utils/transaction-type.d.cts.map +1 -1
- package/dist/utils/transaction-type.d.mts +14 -0
- package/dist/utils/transaction-type.d.mts.map +1 -1
- package/dist/utils/transaction-type.mjs +20 -4
- package/dist/utils/transaction-type.mjs.map +1 -1
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction-type.cjs","sourceRoot":"","sources":["../../src/utils/transaction-type.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"transaction-type.cjs","sourceRoot":"","sources":["../../src/utils/transaction-type.ts"],"names":[],"mappings":";;;AAAA,4CAA4E;AAC5E,iEAAm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7BD,sDA6BC;AAED;;;;;GAKG;AACH,SAAS,aAAa,CAAC,IAAa;IAClC,OAAO,qBAAqB,CAAC,IAAc,EAAE;QAC3C,aAAa,EAAE,IAAI;KACpB,CAAuB,CAAC;AAC3B,CAAC;AAED;;;;;;GAMG;AACH,KAAK,UAAU,qBAAqB,CAClC,QAAkB,EAClB,OAAgB;IAKhB,IAAI,YAAY,CAAC;IACjB,IAAI;QACF,YAAY,GAAG,MAAM,IAAA,wBAAK,EAAC,QAAQ,EAAE,SAAS,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;QAC3D,WAAW;QACX,6DAA6D;KAC9D;IAAC,OAAO,KAAK,EAAE;QACd,YAAY,GAAG,IAAI,CAAC;KACrB;IAED,MAAM,iBAAiB,GAAG,YAAY;QACpC,CAAC,CAAC,YAAY,KAAK,IAAI;YACrB,YAAY,KAAK,KAAK;YACtB,CAAC,YAAY,CAAC,UAAU,CAAC,2BAAiB,CAAC;QAC7C,CAAC,CAAC,KAAK,CAAC;IACV,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,CAAC;AAC7C,CAAC","sourcesContent":["import { Interface, type TransactionDescription } from '@ethersproject/abi';\nimport { query } from '@metamask/controller-utils';\nimport type EthQuery from '@metamask/eth-query';\nimport {\n abiERC721,\n abiERC20,\n abiERC1155,\n abiFiatTokenV2,\n} from '@metamask/metamask-eth-abis';\n\nimport { DELEGATION_PREFIX } from './eip7702';\nimport type { InferTransactionTypeResult, TransactionParams } from '../types';\nimport { TransactionType } from '../types';\n\nexport const ESTIMATE_GAS_ERROR = 'eth_estimateGas rpc method error';\n\nconst ERC20Interface = new Interface(abiERC20);\nconst ERC721Interface = new Interface(abiERC721);\nconst ERC1155Interface = new Interface(abiERC1155);\nconst USDCInterface = new Interface(abiFiatTokenV2);\n\n/**\n * Determines the type of the transaction by analyzing the txParams.\n * It will never return TRANSACTION_TYPE_CANCEL or TRANSACTION_TYPE_RETRY as these\n * represent specific events that we specify manually at transaction creation.\n *\n * @param txParams - Parameters for the transaction.\n * @param ethQuery - EthQuery instance.\n * @returns A object with the transaction type and the contract code response in Hex.\n */\nexport async function determineTransactionType(\n txParams: TransactionParams,\n ethQuery?: EthQuery,\n): Promise<InferTransactionTypeResult> {\n const { data, to } = txParams;\n\n if (data && !to) {\n return { type: TransactionType.deployContract, getCodeResponse: undefined };\n }\n\n let getCodeResponse;\n let isContractAddress = Boolean(data?.length);\n\n if (ethQuery) {\n const response = await readAddressAsContract(ethQuery, to);\n\n getCodeResponse = response.contractCode;\n isContractAddress = response.isContractAddress;\n }\n\n if (!isContractAddress) {\n return { type: TransactionType.simpleSend, getCodeResponse };\n }\n\n const hasValue = Number(txParams.value ?? '0') !== 0;\n\n const contractInteractionResult = {\n type: TransactionType.contractInteraction,\n getCodeResponse,\n };\n\n if (!data || hasValue) {\n return contractInteractionResult;\n }\n\n const name = getMethodName(data);\n\n if (!name) {\n return contractInteractionResult;\n }\n\n const tokenMethodName = [\n TransactionType.tokenMethodApprove,\n TransactionType.tokenMethodSetApprovalForAll,\n TransactionType.tokenMethodTransfer,\n TransactionType.tokenMethodTransferFrom,\n TransactionType.tokenMethodSafeTransferFrom,\n TransactionType.tokenMethodIncreaseAllowance,\n ].find(\n (methodName) => methodName.toLowerCase() === (name as string).toLowerCase(),\n );\n\n if (tokenMethodName) {\n return { type: tokenMethodName, getCodeResponse };\n }\n\n return contractInteractionResult;\n}\n\n/**\n * Parses transaction data using ABIs for three different token standards: ERC20, ERC721, ERC1155 and USDC.\n * The data will decode correctly if the transaction is an interaction with a contract that matches one of these\n * contract standards\n *\n * @param data - Encoded transaction data.\n * @param options - Options bag.\n * @param options.getMethodName - Whether to get the method name.\n * @returns A representation of an ethereum contract call.\n */\nexport function decodeTransactionData(\n data: string,\n options?: {\n getMethodName?: boolean;\n },\n): undefined | TransactionDescription | string {\n if (!data || data.length < 10) {\n return undefined;\n }\n\n const fourByte = data.substring(0, 10).toLowerCase();\n\n for (const iface of [\n ERC20Interface,\n ERC721Interface,\n ERC1155Interface,\n USDCInterface,\n ]) {\n try {\n if (options?.getMethodName) {\n return iface.getFunction(fourByte)?.name;\n }\n return iface.parseTransaction({ data });\n } catch {\n // Intentionally empty\n }\n }\n\n return undefined;\n}\n\n/**\n * Attempts to get the method name from the given transaction data.\n *\n * @param data - Encoded transaction data.\n * @returns The method name.\n */\nfunction getMethodName(data?: string): string | undefined {\n return decodeTransactionData(data as string, {\n getMethodName: true,\n }) as string | undefined;\n}\n\n/**\n * Reads an Ethereum address and determines if it is a contract address.\n *\n * @param ethQuery - The Ethereum query object used to interact with the Ethereum blockchain.\n * @param address - The Ethereum address.\n * @returns An object containing the contract code and a boolean indicating if it is a contract address.\n */\nasync function readAddressAsContract(\n ethQuery: EthQuery,\n address?: string,\n): Promise<{\n contractCode: string | null;\n isContractAddress: boolean;\n}> {\n let contractCode;\n try {\n contractCode = await query(ethQuery, 'getCode', [address]);\n // Not used\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n } catch (error) {\n contractCode = null;\n }\n\n const isContractAddress = contractCode\n ? contractCode !== '0x' &&\n contractCode !== '0x0' &&\n !contractCode.startsWith(DELEGATION_PREFIX)\n : false;\n return { contractCode, isContractAddress };\n}\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type TransactionDescription } from "@ethersproject/abi";
|
|
1
2
|
import type EthQuery from "@metamask/eth-query";
|
|
2
3
|
import type { InferTransactionTypeResult, TransactionParams } from "../types.cjs";
|
|
3
4
|
export declare const ESTIMATE_GAS_ERROR = "eth_estimateGas rpc method error";
|
|
@@ -11,4 +12,17 @@ export declare const ESTIMATE_GAS_ERROR = "eth_estimateGas rpc method error";
|
|
|
11
12
|
* @returns A object with the transaction type and the contract code response in Hex.
|
|
12
13
|
*/
|
|
13
14
|
export declare function determineTransactionType(txParams: TransactionParams, ethQuery?: EthQuery): Promise<InferTransactionTypeResult>;
|
|
15
|
+
/**
|
|
16
|
+
* Parses transaction data using ABIs for three different token standards: ERC20, ERC721, ERC1155 and USDC.
|
|
17
|
+
* The data will decode correctly if the transaction is an interaction with a contract that matches one of these
|
|
18
|
+
* contract standards
|
|
19
|
+
*
|
|
20
|
+
* @param data - Encoded transaction data.
|
|
21
|
+
* @param options - Options bag.
|
|
22
|
+
* @param options.getMethodName - Whether to get the method name.
|
|
23
|
+
* @returns A representation of an ethereum contract call.
|
|
24
|
+
*/
|
|
25
|
+
export declare function decodeTransactionData(data: string, options?: {
|
|
26
|
+
getMethodName?: boolean;
|
|
27
|
+
}): undefined | TransactionDescription | string;
|
|
14
28
|
//# sourceMappingURL=transaction-type.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction-type.d.cts","sourceRoot":"","sources":["../../src/utils/transaction-type.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"transaction-type.d.cts","sourceRoot":"","sources":["../../src/utils/transaction-type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,KAAK,sBAAsB,EAAE,2BAA2B;AAE5E,OAAO,KAAK,QAAQ,4BAA4B;AAShD,OAAO,KAAK,EAAE,0BAA0B,EAAE,iBAAiB,EAAE,qBAAiB;AAG9E,eAAO,MAAM,kBAAkB,qCAAqC,CAAC;AAOrE;;;;;;;;GAQG;AACH,wBAAsB,wBAAwB,CAC5C,QAAQ,EAAE,iBAAiB,EAC3B,QAAQ,CAAC,EAAE,QAAQ,GAClB,OAAO,CAAC,0BAA0B,CAAC,CAsDrC;AAED;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE;IACR,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB,GACA,SAAS,GAAG,sBAAsB,GAAG,MAAM,CAwB7C"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type TransactionDescription } from "@ethersproject/abi";
|
|
1
2
|
import type EthQuery from "@metamask/eth-query";
|
|
2
3
|
import type { InferTransactionTypeResult, TransactionParams } from "../types.mjs";
|
|
3
4
|
export declare const ESTIMATE_GAS_ERROR = "eth_estimateGas rpc method error";
|
|
@@ -11,4 +12,17 @@ export declare const ESTIMATE_GAS_ERROR = "eth_estimateGas rpc method error";
|
|
|
11
12
|
* @returns A object with the transaction type and the contract code response in Hex.
|
|
12
13
|
*/
|
|
13
14
|
export declare function determineTransactionType(txParams: TransactionParams, ethQuery?: EthQuery): Promise<InferTransactionTypeResult>;
|
|
15
|
+
/**
|
|
16
|
+
* Parses transaction data using ABIs for three different token standards: ERC20, ERC721, ERC1155 and USDC.
|
|
17
|
+
* The data will decode correctly if the transaction is an interaction with a contract that matches one of these
|
|
18
|
+
* contract standards
|
|
19
|
+
*
|
|
20
|
+
* @param data - Encoded transaction data.
|
|
21
|
+
* @param options - Options bag.
|
|
22
|
+
* @param options.getMethodName - Whether to get the method name.
|
|
23
|
+
* @returns A representation of an ethereum contract call.
|
|
24
|
+
*/
|
|
25
|
+
export declare function decodeTransactionData(data: string, options?: {
|
|
26
|
+
getMethodName?: boolean;
|
|
27
|
+
}): undefined | TransactionDescription | string;
|
|
14
28
|
//# sourceMappingURL=transaction-type.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction-type.d.mts","sourceRoot":"","sources":["../../src/utils/transaction-type.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"transaction-type.d.mts","sourceRoot":"","sources":["../../src/utils/transaction-type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,KAAK,sBAAsB,EAAE,2BAA2B;AAE5E,OAAO,KAAK,QAAQ,4BAA4B;AAShD,OAAO,KAAK,EAAE,0BAA0B,EAAE,iBAAiB,EAAE,qBAAiB;AAG9E,eAAO,MAAM,kBAAkB,qCAAqC,CAAC;AAOrE;;;;;;;;GAQG;AACH,wBAAsB,wBAAwB,CAC5C,QAAQ,EAAE,iBAAiB,EAC3B,QAAQ,CAAC,EAAE,QAAQ,GAClB,OAAO,CAAC,0BAA0B,CAAC,CAsDrC;AAED;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE;IACR,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB,GACA,SAAS,GAAG,sBAAsB,GAAG,MAAM,CAwB7C"}
|
|
@@ -58,26 +58,31 @@ export async function determineTransactionType(txParams, ethQuery) {
|
|
|
58
58
|
return contractInteractionResult;
|
|
59
59
|
}
|
|
60
60
|
/**
|
|
61
|
-
*
|
|
61
|
+
* Parses transaction data using ABIs for three different token standards: ERC20, ERC721, ERC1155 and USDC.
|
|
62
62
|
* The data will decode correctly if the transaction is an interaction with a contract that matches one of these
|
|
63
63
|
* contract standards
|
|
64
64
|
*
|
|
65
65
|
* @param data - Encoded transaction data.
|
|
66
|
+
* @param options - Options bag.
|
|
67
|
+
* @param options.getMethodName - Whether to get the method name.
|
|
66
68
|
* @returns A representation of an ethereum contract call.
|
|
67
69
|
*/
|
|
68
|
-
function
|
|
70
|
+
export function decodeTransactionData(data, options) {
|
|
69
71
|
if (!data || data.length < 10) {
|
|
70
72
|
return undefined;
|
|
71
73
|
}
|
|
72
74
|
const fourByte = data.substring(0, 10).toLowerCase();
|
|
73
|
-
for (const
|
|
75
|
+
for (const iface of [
|
|
74
76
|
ERC20Interface,
|
|
75
77
|
ERC721Interface,
|
|
76
78
|
ERC1155Interface,
|
|
77
79
|
USDCInterface,
|
|
78
80
|
]) {
|
|
79
81
|
try {
|
|
80
|
-
|
|
82
|
+
if (options?.getMethodName) {
|
|
83
|
+
return iface.getFunction(fourByte)?.name;
|
|
84
|
+
}
|
|
85
|
+
return iface.parseTransaction({ data });
|
|
81
86
|
}
|
|
82
87
|
catch {
|
|
83
88
|
// Intentionally empty
|
|
@@ -85,6 +90,17 @@ function getMethodName(data) {
|
|
|
85
90
|
}
|
|
86
91
|
return undefined;
|
|
87
92
|
}
|
|
93
|
+
/**
|
|
94
|
+
* Attempts to get the method name from the given transaction data.
|
|
95
|
+
*
|
|
96
|
+
* @param data - Encoded transaction data.
|
|
97
|
+
* @returns The method name.
|
|
98
|
+
*/
|
|
99
|
+
function getMethodName(data) {
|
|
100
|
+
return decodeTransactionData(data, {
|
|
101
|
+
getMethodName: true,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
88
104
|
/**
|
|
89
105
|
* Reads an Ethereum address and determines if it is a contract address.
|
|
90
106
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction-type.mjs","sourceRoot":"","sources":["../../src/utils/transaction-type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,
|
|
1
|
+
{"version":3,"file":"transaction-type.mjs","sourceRoot":"","sources":["../../src/utils/transaction-type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAA+B,2BAA2B;AAC5E,OAAO,EAAE,KAAK,EAAE,mCAAmC;AAEnD,OAAO,EACL,SAAS,EACT,QAAQ,EACR,UAAU,EACV,cAAc,EACf,oCAAoC;AAErC,OAAO,EAAE,iBAAiB,EAAE,sBAAkB;AAE9C,OAAO,EAAE,eAAe,EAAE,qBAAiB;AAE3C,MAAM,CAAC,MAAM,kBAAkB,GAAG,kCAAkC,CAAC;AAErE,MAAM,cAAc,GAAG,IAAI,SAAS,CAAC,QAAQ,CAAC,CAAC;AAC/C,MAAM,eAAe,GAAG,IAAI,SAAS,CAAC,SAAS,CAAC,CAAC;AACjD,MAAM,gBAAgB,GAAG,IAAI,SAAS,CAAC,UAAU,CAAC,CAAC;AACnD,MAAM,aAAa,GAAG,IAAI,SAAS,CAAC,cAAc,CAAC,CAAC;AAEpD;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAC5C,QAA2B,EAC3B,QAAmB;IAEnB,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,QAAQ,CAAC;IAE9B,IAAI,IAAI,IAAI,CAAC,EAAE,EAAE;QACf,OAAO,EAAE,IAAI,EAAE,eAAe,CAAC,cAAc,EA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,CAAC;IACV,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,CAAC;AAC7C,CAAC","sourcesContent":["import { Interface, type TransactionDescription } from '@ethersproject/abi';\nimport { query } from '@metamask/controller-utils';\nimport type EthQuery from '@metamask/eth-query';\nimport {\n abiERC721,\n abiERC20,\n abiERC1155,\n abiFiatTokenV2,\n} from '@metamask/metamask-eth-abis';\n\nimport { DELEGATION_PREFIX } from './eip7702';\nimport type { InferTransactionTypeResult, TransactionParams } from '../types';\nimport { TransactionType } from '../types';\n\nexport const ESTIMATE_GAS_ERROR = 'eth_estimateGas rpc method error';\n\nconst ERC20Interface = new Interface(abiERC20);\nconst ERC721Interface = new Interface(abiERC721);\nconst ERC1155Interface = new Interface(abiERC1155);\nconst USDCInterface = new Interface(abiFiatTokenV2);\n\n/**\n * Determines the type of the transaction by analyzing the txParams.\n * It will never return TRANSACTION_TYPE_CANCEL or TRANSACTION_TYPE_RETRY as these\n * represent specific events that we specify manually at transaction creation.\n *\n * @param txParams - Parameters for the transaction.\n * @param ethQuery - EthQuery instance.\n * @returns A object with the transaction type and the contract code response in Hex.\n */\nexport async function determineTransactionType(\n txParams: TransactionParams,\n ethQuery?: EthQuery,\n): Promise<InferTransactionTypeResult> {\n const { data, to } = txParams;\n\n if (data && !to) {\n return { type: TransactionType.deployContract, getCodeResponse: undefined };\n }\n\n let getCodeResponse;\n let isContractAddress = Boolean(data?.length);\n\n if (ethQuery) {\n const response = await readAddressAsContract(ethQuery, to);\n\n getCodeResponse = response.contractCode;\n isContractAddress = response.isContractAddress;\n }\n\n if (!isContractAddress) {\n return { type: TransactionType.simpleSend, getCodeResponse };\n }\n\n const hasValue = Number(txParams.value ?? '0') !== 0;\n\n const contractInteractionResult = {\n type: TransactionType.contractInteraction,\n getCodeResponse,\n };\n\n if (!data || hasValue) {\n return contractInteractionResult;\n }\n\n const name = getMethodName(data);\n\n if (!name) {\n return contractInteractionResult;\n }\n\n const tokenMethodName = [\n TransactionType.tokenMethodApprove,\n TransactionType.tokenMethodSetApprovalForAll,\n TransactionType.tokenMethodTransfer,\n TransactionType.tokenMethodTransferFrom,\n TransactionType.tokenMethodSafeTransferFrom,\n TransactionType.tokenMethodIncreaseAllowance,\n ].find(\n (methodName) => methodName.toLowerCase() === (name as string).toLowerCase(),\n );\n\n if (tokenMethodName) {\n return { type: tokenMethodName, getCodeResponse };\n }\n\n return contractInteractionResult;\n}\n\n/**\n * Parses transaction data using ABIs for three different token standards: ERC20, ERC721, ERC1155 and USDC.\n * The data will decode correctly if the transaction is an interaction with a contract that matches one of these\n * contract standards\n *\n * @param data - Encoded transaction data.\n * @param options - Options bag.\n * @param options.getMethodName - Whether to get the method name.\n * @returns A representation of an ethereum contract call.\n */\nexport function decodeTransactionData(\n data: string,\n options?: {\n getMethodName?: boolean;\n },\n): undefined | TransactionDescription | string {\n if (!data || data.length < 10) {\n return undefined;\n }\n\n const fourByte = data.substring(0, 10).toLowerCase();\n\n for (const iface of [\n ERC20Interface,\n ERC721Interface,\n ERC1155Interface,\n USDCInterface,\n ]) {\n try {\n if (options?.getMethodName) {\n return iface.getFunction(fourByte)?.name;\n }\n return iface.parseTransaction({ data });\n } catch {\n // Intentionally empty\n }\n }\n\n return undefined;\n}\n\n/**\n * Attempts to get the method name from the given transaction data.\n *\n * @param data - Encoded transaction data.\n * @returns The method name.\n */\nfunction getMethodName(data?: string): string | undefined {\n return decodeTransactionData(data as string, {\n getMethodName: true,\n }) as string | undefined;\n}\n\n/**\n * Reads an Ethereum address and determines if it is a contract address.\n *\n * @param ethQuery - The Ethereum query object used to interact with the Ethereum blockchain.\n * @param address - The Ethereum address.\n * @returns An object containing the contract code and a boolean indicating if it is a contract address.\n */\nasync function readAddressAsContract(\n ethQuery: EthQuery,\n address?: string,\n): Promise<{\n contractCode: string | null;\n isContractAddress: boolean;\n}> {\n let contractCode;\n try {\n contractCode = await query(ethQuery, 'getCode', [address]);\n // Not used\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n } catch (error) {\n contractCode = null;\n }\n\n const isContractAddress = contractCode\n ? contractCode !== '0x' &&\n contractCode !== '0x0' &&\n !contractCode.startsWith(DELEGATION_PREFIX)\n : false;\n return { contractCode, isContractAddress };\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/transaction-controller",
|
|
3
|
-
"version": "60.
|
|
3
|
+
"version": "60.5.0",
|
|
4
4
|
"description": "Stores transactions alongside their periodically updated statuses and manages interactions such as approval and cancellation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"@metamask/metamask-eth-abis": "^3.1.1",
|
|
61
61
|
"@metamask/nonce-tracker": "^6.0.0",
|
|
62
62
|
"@metamask/rpc-errors": "^7.0.2",
|
|
63
|
-
"@metamask/utils": "^11.8.
|
|
63
|
+
"@metamask/utils": "^11.8.1",
|
|
64
64
|
"async-mutex": "^0.5.0",
|
|
65
65
|
"bn.js": "^5.2.1",
|
|
66
66
|
"eth-method-registry": "^4.0.0",
|
|
@@ -74,10 +74,10 @@
|
|
|
74
74
|
"@metamask/approval-controller": "^7.1.3",
|
|
75
75
|
"@metamask/auto-changelog": "^3.4.4",
|
|
76
76
|
"@metamask/eth-block-tracker": "^12.0.1",
|
|
77
|
-
"@metamask/eth-json-rpc-provider": "^
|
|
77
|
+
"@metamask/eth-json-rpc-provider": "^5.0.0",
|
|
78
78
|
"@metamask/ethjs-provider-http": "^0.3.0",
|
|
79
79
|
"@metamask/gas-fee-controller": "^24.0.0",
|
|
80
|
-
"@metamask/network-controller": "^24.
|
|
80
|
+
"@metamask/network-controller": "^24.2.0",
|
|
81
81
|
"@metamask/remote-feature-flag-controller": "^1.7.0",
|
|
82
82
|
"@types/bn.js": "^5.1.5",
|
|
83
83
|
"@types/jest": "^27.4.1",
|