diff --git a/packages/transaction-controller/src/TransactionController.test.ts b/packages/transaction-controller/src/TransactionController.test.ts index ef09825195b..321733851fd 100644 --- a/packages/transaction-controller/src/TransactionController.test.ts +++ b/packages/transaction-controller/src/TransactionController.test.ts @@ -99,8 +99,18 @@ jest.mock('@metamask/eth-query', () => }, getTransactionReceipt: (_hash: any, callback: any) => { const txs: any = [ - { transactionHash: '1337', gasUsed: '0x5208', status: '0x1' }, - { transactionHash: '1111', gasUsed: '0x1108', status: '0x0' }, + { + transactionHash: '1337', + gasUsed: '0x5208', + status: '0x1', + transactionIndex: 1337, + }, + { + transactionHash: '1111', + gasUsed: '0x1108', + status: '0x0', + transactionIndex: 1111, + }, ]; const tx: any = txs.find( (element: any) => element.transactionHash === _hash, @@ -1258,6 +1268,7 @@ describe('TransactionController', () => { const transactionMeta = controller.state.transactions[0]; expect(transactionMeta.verifiedOnBlockchain).toBe(true); expect(transactionMeta.transaction.gasUsed).toBe('0x5208'); + expect(transactionMeta.txReceipt?.transactionIndex).toBe(1337); }); }); diff --git a/packages/transaction-controller/src/TransactionController.ts b/packages/transaction-controller/src/TransactionController.ts index cd8c8a0706e..fa048e2c2d8 100644 --- a/packages/transaction-controller/src/TransactionController.ts +++ b/packages/transaction-controller/src/TransactionController.ts @@ -1157,6 +1157,7 @@ export class TransactionController extends BaseController< meta.verifiedOnBlockchain = true; meta.transaction.gasUsed = txReceipt.gasUsed; + meta.txReceipt = txReceipt; // According to the Web3 docs: // TRUE if the transaction was successful, FALSE if the EVM reverted the transaction. diff --git a/packages/transaction-controller/src/types.ts b/packages/transaction-controller/src/types.ts index 80afe79bc0a..743a97ca852 100644 --- a/packages/transaction-controller/src/types.ts +++ b/packages/transaction-controller/src/types.ts @@ -14,6 +14,7 @@ import type { Hex } from '@metamask/utils'; * @property time - Timestamp associated with this transaction * @property toSmartContract - Whether transaction recipient is a smart contract * @property transaction - Underlying Transaction object + * @property txReceipt - Transaction receipt * @property transactionHash - Hash of a successful transaction * @property blockNumber - Number of the block where the transaction has been included */ @@ -42,6 +43,7 @@ type TransactionMetaBase = { blockNumber?: string; deviceConfirmedOn?: WalletDevice; verifiedOnBlockchain?: boolean; + txReceipt?: TransactionReceipt; }; /** @@ -99,6 +101,65 @@ export interface Transaction { estimateGasError?: string; } +/** + * Standard data concerning a transaction processed by the blockchain. + */ +export interface TransactionReceipt { + /** + * The block hash of the block that this transaction was included in. + */ + blockHash?: string; + + /** + * The block number of the block that this transaction was included in. + */ + blockNumber?: string; + + /** + * Effective gas price the transaction was charged at. + */ + effectiveGasPrice?: string; + + /** + * Gas used in the transaction. + */ + gasUsed?: string; + + /** + * Total used gas in hex. + */ + l1Fee?: string; + + /** + * All the logs emitted by this transaction. + */ + logs?: Log[]; + + /** + * The status of the transaction. + */ + status?: string; + + /** + * The index of this transaction in the list of transactions included in the block this transaction was mined in. + */ + transactionIndex?: number; +} + +/** + * Represents an event that has been included in a transaction using the EVM `LOG` opcode. + */ +export interface Log { + /** + * Address of the contract that generated log. + */ + address?: string; + /** + * List of topics for log. + */ + topics?: string; +} + /** * The configuration required to fetch transaction data from a RemoteTransactionSource. */