From 3a65715e094e8313dbb2b91c03c422ee205efc27 Mon Sep 17 00:00:00 2001 From: "moxey.eth" Date: Sat, 17 Dec 2022 17:19:23 +1100 Subject: [PATCH 1/3] docs: fetchTransactionReceipt --- .../actions/public/fetchTransactionReceipt.md | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 site/docs/actions/public/fetchTransactionReceipt.md diff --git a/site/docs/actions/public/fetchTransactionReceipt.md b/site/docs/actions/public/fetchTransactionReceipt.md new file mode 100644 index 0000000000..bf9c003a04 --- /dev/null +++ b/site/docs/actions/public/fetchTransactionReceipt.md @@ -0,0 +1,58 @@ +# fetchTransactionReceipt + +Returns the transaction receipt given a transaction hash. + +## Import + +```ts +import { fetchTransactionReceipt } from 'viem' +``` + +## Usage + +```ts +import { fetchTransactionReceipt } from 'viem' +import { publicClient } from '.' + +const transaction = await fetchTransactionReceipt(publicClient, { // [!code focus:99] + hash: '0x4ca7ee652d57678f26e887c149ab0735f41de37bcad58c9f6d3ed5824f15b74d' +}) +/** + * { + * blockHash: '0xaf1dadb8a98f1282e8f7b42cc3da8847bfa2cf4e227b8220403ae642e1173088', + * blockNumber: 15132008n, + * from: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266', + * ... + * status: 'success', + * } + */ +``` + +## Returns + +[`TransactionReceipt`](/TODO) + +The transaction receipt. + +## Configuration + +### hash + +- **Type:** `'0x${string}'` + +A transaction hash. + +```ts +const transaction = await fetchTransactionReceipt(publicClient, { + hash: '0x4ca7ee652d57678f26e887c149ab0735f41de37bcad58c9f6d3ed5824f15b74d' // [!code focus] +}) +``` + + +## Notes + +- A [Transaction Receipt](/TODO) is not to be confused with a [Transaction](/TODO).a Transaction Receipt is the **confirmation** that the transaction has been processed and included in a block on the blockchain, whereas a Transaction is a **message** sent by an account that is broadcast to the network. You can fetch a Transaction using [`fetchTransaction`](/TODO). + +## Example + +TODO \ No newline at end of file From ca56ba0deca14948f4a9e960f1b0e8872dfd5085 Mon Sep 17 00:00:00 2001 From: "moxey.eth" Date: Sat, 17 Dec 2022 18:58:15 +1100 Subject: [PATCH 2/3] feat: fetchTransactionReceipt --- packages/core/src/actions/index.ts | 8 +- .../fetchTransactionReceipt.test.ts | 154 ++++++++++++++++++ .../transaction/fetchTransactionReceipt.ts | 35 ++++ .../src/actions/transaction/index.test.ts | 1 + .../core/src/actions/transaction/index.ts | 6 + packages/core/src/chains.test.ts | 4 + packages/core/src/chains.ts | 13 +- .../src/{utils/unit => }/constants.test.ts | 5 + .../core/src/{utils/unit => }/constants.ts | 6 + packages/core/src/index.ts | 9 +- packages/core/src/types/rpc.ts | 9 +- packages/core/src/types/transaction.ts | 15 +- packages/core/src/types/utils.ts | 9 + packages/core/src/utils/formatters/block.ts | 5 +- packages/core/src/utils/formatters/format.ts | 5 +- .../core/src/utils/formatters/index.test.ts | 5 - packages/core/src/utils/formatters/index.ts | 2 +- .../core/src/utils/formatters/log.test.ts | 79 +++++++++ packages/core/src/utils/formatters/log.ts | 12 ++ .../src/utils/formatters/transaction.test.ts | 12 +- .../core/src/utils/formatters/transaction.ts | 17 +- .../formatters/transactionReceipt.test.ts | 151 +++++++++++++++++ .../utils/formatters/transactionReceipt.ts | 54 ++++++ packages/core/src/utils/index.test.ts | 17 -- packages/core/src/utils/index.ts | 4 - packages/core/src/utils/unit/etherToValue.ts | 2 +- packages/core/src/utils/unit/gweiToValue.ts | 2 +- packages/core/src/utils/unit/index.test.ts | 12 -- packages/core/src/utils/unit/index.ts | 1 - packages/core/src/utils/unit/valueAsEther.ts | 2 +- packages/core/src/utils/unit/valueAsGwei.ts | 2 +- 31 files changed, 580 insertions(+), 78 deletions(-) create mode 100644 packages/core/src/actions/transaction/fetchTransactionReceipt.test.ts create mode 100644 packages/core/src/actions/transaction/fetchTransactionReceipt.ts rename packages/core/src/{utils/unit => }/constants.test.ts (77%) rename packages/core/src/{utils/unit => }/constants.ts (60%) create mode 100644 packages/core/src/utils/formatters/log.test.ts create mode 100644 packages/core/src/utils/formatters/log.ts create mode 100644 packages/core/src/utils/formatters/transactionReceipt.test.ts create mode 100644 packages/core/src/utils/formatters/transactionReceipt.ts diff --git a/packages/core/src/actions/index.ts b/packages/core/src/actions/index.ts index 8b0ed16382..e22537dc63 100644 --- a/packages/core/src/actions/index.ts +++ b/packages/core/src/actions/index.ts @@ -22,10 +22,16 @@ export type { export { mine, setBalance } from './test' export type { MineArgs, SetBalanceArgs } from './test' -export { fetchTransaction, sendTransaction } from './transaction' +export { + fetchTransaction, + fetchTransactionReceipt, + sendTransaction, +} from './transaction' export type { FetchTransactionArgs, FetchTransactionResponse, + FetchTransactionReceiptArgs, + FetchTransactionReceiptResponse, SendTransactionArgs, SendTransactionResponse, } from './transaction' diff --git a/packages/core/src/actions/transaction/fetchTransactionReceipt.test.ts b/packages/core/src/actions/transaction/fetchTransactionReceipt.test.ts new file mode 100644 index 0000000000..b2f2d1ad20 --- /dev/null +++ b/packages/core/src/actions/transaction/fetchTransactionReceipt.test.ts @@ -0,0 +1,154 @@ +import { assertType, expect, test } from 'vitest' + +import { publicClient } from '../../../test' +import { celo, defineTransactionReceipt, localhost } from '../../chains' +import { createPublicClient, http } from '../../clients' +import type { TransactionReceipt } from '../../types' + +import { fetchTransactionReceipt } from './fetchTransactionReceipt' + +test('fetches transaction receipt', async () => { + const receipt = await fetchTransactionReceipt(publicClient, { + hash: '0xa4b1f606b66105fa45cb5db23d2f6597075701e7f0e2367f4e6a39d17a8cf98b', + }) + assertType(receipt) + expect(receipt).toMatchInlineSnapshot(` + { + "blockHash": "0x89644bbd5c8d682a2e9611170e6c1f02573d866d286f006cbf517eec7254ec2d", + "blockNumber": 15131999n, + "contractAddress": null, + "cumulativeGasUsed": 5814407n, + "effectiveGasPrice": 11789405161n, + "from": "0xa152f8bb749c55e9943a3a0a3111d18ee2b3f94e", + "gasUsed": 37976n, + "logs": [ + { + "address": "0x15d4c048f83bd7e37d49ea4c83a07267ec4203da", + "blockHash": "0x89644bbd5c8d682a2e9611170e6c1f02573d866d286f006cbf517eec7254ec2d", + "blockNumber": 15131999n, + "data": "0x0000000000000000000000000000000000000000000000000000002b3b6fb3d0", + "logIndex": 108n, + "removed": false, + "topics": [ + "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", + "0x000000000000000000000000a00f99bc38b1ecda1fd70eaa1cd31d576a9f46b0", + "0x000000000000000000000000f16e9b0d03470827a95cdfd0cb8a8a3b46969b91", + ], + "transactionHash": "0xa4b1f606b66105fa45cb5db23d2f6597075701e7f0e2367f4e6a39d17a8cf98b", + "transactionIndex": 69n, + }, + { + "address": "0x15d4c048f83bd7e37d49ea4c83a07267ec4203da", + "blockHash": "0x89644bbd5c8d682a2e9611170e6c1f02573d866d286f006cbf517eec7254ec2d", + "blockNumber": 15131999n, + "data": "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffd4c4904c2f", + "logIndex": 109n, + "removed": false, + "topics": [ + "0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925", + "0x000000000000000000000000a00f99bc38b1ecda1fd70eaa1cd31d576a9f46b0", + "0x000000000000000000000000a152f8bb749c55e9943a3a0a3111d18ee2b3f94e", + ], + "transactionHash": "0xa4b1f606b66105fa45cb5db23d2f6597075701e7f0e2367f4e6a39d17a8cf98b", + "transactionIndex": 69n, + }, + ], + "logsBloom": "0x08000000000000000000000000000000000000000000000000001000002000000000000000000000000000000000000000000000080000000000000000200000000000000000000000000008400000000000000000000000000000000000100000000000000000000040000008000000000004000000000000000010000000000000000000000000000000000000000000000000000000000000000000000004020000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000002090000000000000000000000000000000000000000000000000000000000000", + "status": "success", + "to": "0x15d4c048f83bd7e37d49ea4c83a07267ec4203da", + "transactionHash": "0xa4b1f606b66105fa45cb5db23d2f6597075701e7f0e2367f4e6a39d17a8cf98b", + "transactionIndex": 69, + "type": "eip1559", + } + `) +}) + +test('chain w/ custom block type', async () => { + const client = createPublicClient({ + chain: { + ...celo, + rpcUrls: localhost.rpcUrls, + formatters: { + transactionReceipt: defineTransactionReceipt({ + exclude: ['effectiveGasPrice'], + format: () => ({ + foo: 'bar' as const, + }), + }), + }, + }, + transport: http(), + }) + const receipt = await fetchTransactionReceipt(client, { + hash: '0xa4b1f606b66105fa45cb5db23d2f6597075701e7f0e2367f4e6a39d17a8cf98b', + }) + + assertType< + Omit & { + foo: 'bar' + } + >(receipt) + + expect(receipt).toMatchInlineSnapshot(` + { + "blockHash": "0x89644bbd5c8d682a2e9611170e6c1f02573d866d286f006cbf517eec7254ec2d", + "blockNumber": 15131999n, + "contractAddress": null, + "cumulativeGasUsed": 5814407n, + "foo": "bar", + "from": "0xa152f8bb749c55e9943a3a0a3111d18ee2b3f94e", + "gasUsed": 37976n, + "logs": [ + { + "address": "0x15d4c048f83bd7e37d49ea4c83a07267ec4203da", + "blockHash": "0x89644bbd5c8d682a2e9611170e6c1f02573d866d286f006cbf517eec7254ec2d", + "blockNumber": 15131999n, + "data": "0x0000000000000000000000000000000000000000000000000000002b3b6fb3d0", + "logIndex": 108n, + "removed": false, + "topics": [ + "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", + "0x000000000000000000000000a00f99bc38b1ecda1fd70eaa1cd31d576a9f46b0", + "0x000000000000000000000000f16e9b0d03470827a95cdfd0cb8a8a3b46969b91", + ], + "transactionHash": "0xa4b1f606b66105fa45cb5db23d2f6597075701e7f0e2367f4e6a39d17a8cf98b", + "transactionIndex": 69n, + }, + { + "address": "0x15d4c048f83bd7e37d49ea4c83a07267ec4203da", + "blockHash": "0x89644bbd5c8d682a2e9611170e6c1f02573d866d286f006cbf517eec7254ec2d", + "blockNumber": 15131999n, + "data": "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffd4c4904c2f", + "logIndex": 109n, + "removed": false, + "topics": [ + "0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925", + "0x000000000000000000000000a00f99bc38b1ecda1fd70eaa1cd31d576a9f46b0", + "0x000000000000000000000000a152f8bb749c55e9943a3a0a3111d18ee2b3f94e", + ], + "transactionHash": "0xa4b1f606b66105fa45cb5db23d2f6597075701e7f0e2367f4e6a39d17a8cf98b", + "transactionIndex": 69n, + }, + ], + "logsBloom": "0x08000000000000000000000000000000000000000000000000001000002000000000000000000000000000000000000000000000080000000000000000200000000000000000000000000008400000000000000000000000000000000000100000000000000000000040000008000000000004000000000000000010000000000000000000000000000000000000000000000000000000000000000000000004020000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000002090000000000000000000000000000000000000000000000000000000000000", + "status": "success", + "to": "0x15d4c048f83bd7e37d49ea4c83a07267ec4203da", + "transactionHash": "0xa4b1f606b66105fa45cb5db23d2f6597075701e7f0e2367f4e6a39d17a8cf98b", + "transactionIndex": 69, + "type": "eip1559", + } + `) +}) + +test('throws if transaction not found', async () => { + await expect( + fetchTransactionReceipt(publicClient, { + hash: '0xa4b1f606b66105fa45cb5db23d2f6597075701e7f0e2367f4e6a39d17a8cf98a', + }), + ).rejects.toThrowErrorMatchingInlineSnapshot(` + "Transaction with hash \\"0xa4b1f606b66105fa45cb5db23d2f6597075701e7f0e2367f4e6a39d17a8cf98a\\" could not be found. + + Details: transaction not found + Version: viem@1.0.2" + `) +}) diff --git a/packages/core/src/actions/transaction/fetchTransactionReceipt.ts b/packages/core/src/actions/transaction/fetchTransactionReceipt.ts new file mode 100644 index 0000000000..ba4481ad73 --- /dev/null +++ b/packages/core/src/actions/transaction/fetchTransactionReceipt.ts @@ -0,0 +1,35 @@ +import type { Chain } from '../../chains' +import type { PublicClient } from '../../clients' +import type { Data } from '../../types' +import { format } from '../../utils' +import type { + FormattedTransactionReceipt, + TransactionReceiptFormatter, +} from '../../utils/formatters/transactionReceipt' +import { formatTransactionReceipt } from '../../utils/formatters/transactionReceipt' +import { TransactionNotFoundError } from './fetchTransaction' + +export type FetchTransactionReceiptArgs = { + /** The hash of the transaction. */ + hash: Data +} + +export type FetchTransactionReceiptResponse = + FormattedTransactionReceipt> + +export async function fetchTransactionReceipt( + client: PublicClient, + { hash }: FetchTransactionReceiptArgs, +) { + const receipt = await client.request({ + method: 'eth_getTransactionReceipt', + params: [hash], + }) + + if (!receipt) throw new TransactionNotFoundError({ hash }) + + return format(receipt, { + formatter: + client.chain?.formatters?.transactionReceipt || formatTransactionReceipt, + }) as FetchTransactionReceiptResponse +} diff --git a/packages/core/src/actions/transaction/index.test.ts b/packages/core/src/actions/transaction/index.test.ts index d68f513fa1..9d16b17fa0 100644 --- a/packages/core/src/actions/transaction/index.test.ts +++ b/packages/core/src/actions/transaction/index.test.ts @@ -6,6 +6,7 @@ test('exports actions', () => { expect(actions).toMatchInlineSnapshot(` { "fetchTransaction": [Function], + "fetchTransactionReceipt": [Function], "sendTransaction": [Function], } `) diff --git a/packages/core/src/actions/transaction/index.ts b/packages/core/src/actions/transaction/index.ts index 01e617d20d..fc7a0f5b03 100644 --- a/packages/core/src/actions/transaction/index.ts +++ b/packages/core/src/actions/transaction/index.ts @@ -4,6 +4,12 @@ export type { FetchTransactionResponse, } from './fetchTransaction' +export { fetchTransactionReceipt } from './fetchTransactionReceipt' +export type { + FetchTransactionReceiptArgs, + FetchTransactionReceiptResponse, +} from './fetchTransactionReceipt' + export { sendTransaction } from './sendTransaction' export type { SendTransactionArgs, diff --git a/packages/core/src/chains.test.ts b/packages/core/src/chains.test.ts index 9d87095ca8..86375929ad 100644 --- a/packages/core/src/chains.test.ts +++ b/packages/core/src/chains.test.ts @@ -260,7 +260,11 @@ test('exports chains', () => { }, }, }, + "defineBlock": [Function], "defineChain": [Function], + "defineTransaction": [Function], + "defineTransactionReceipt": [Function], + "defineTransactionRequest": [Function], "fantom": { "blockExplorers": { "default": { diff --git a/packages/core/src/chains.ts b/packages/core/src/chains.ts index 3c34cef921..b2537e1617 100644 --- a/packages/core/src/chains.ts +++ b/packages/core/src/chains.ts @@ -29,8 +29,10 @@ import type { Quantity, RpcBlock, RpcTransaction, + RpcTransactionReceipt, RpcTransactionRequest, Transaction, + TransactionReceipt, TransactionRequest, } from './types' import { @@ -38,6 +40,7 @@ import { formatTransaction, formatTransactionRequest, } from './utils' +import { formatTransactionReceipt } from './utils/formatters/transactionReceipt' export type Formatter = ( value: TSource & { [key: string]: unknown }, @@ -46,6 +49,7 @@ export type Formatter = ( export type Formatters = { block?: Formatter transaction?: Formatter + transactionReceipt?: Formatter transactionRequest?: Formatter } @@ -94,11 +98,14 @@ function defineFormatter, TFormatted>({ } } -const defineBlock = defineFormatter({ format: formatBlock }) -const defineTransaction = defineFormatter({ format: formatTransaction }) -const defineTransactionRequest = defineFormatter({ +export const defineBlock = defineFormatter({ format: formatBlock }) +export const defineTransaction = defineFormatter({ format: formatTransaction }) +export const defineTransactionRequest = defineFormatter({ format: formatTransactionRequest, }) +export const defineTransactionReceipt = defineFormatter({ + format: formatTransactionReceipt, +}) export const arbitrumGoerli = defineChain(arbitrumGoerli_) export const arbitrum = defineChain(arbitrum_) diff --git a/packages/core/src/utils/unit/constants.test.ts b/packages/core/src/constants.test.ts similarity index 77% rename from packages/core/src/utils/unit/constants.test.ts rename to packages/core/src/constants.test.ts index d545ff6503..980b58fa70 100644 --- a/packages/core/src/utils/unit/constants.test.ts +++ b/packages/core/src/constants.test.ts @@ -13,6 +13,11 @@ test('exports constants', () => { "ether": -9, "wei": 9, }, + "transactionType": { + "0x0": "legacy", + "0x1": "eip2930", + "0x2": "eip1559", + }, "weiUnits": { "ether": -18, "gwei": -9, diff --git a/packages/core/src/utils/unit/constants.ts b/packages/core/src/constants.ts similarity index 60% rename from packages/core/src/utils/unit/constants.ts rename to packages/core/src/constants.ts index 885c6cbe53..a3310b2776 100644 --- a/packages/core/src/utils/unit/constants.ts +++ b/packages/core/src/constants.ts @@ -10,3 +10,9 @@ export const weiUnits = { ether: -18, gwei: -9, } + +export const transactionType = { + '0x0': 'legacy', + '0x1': 'eip2930', + '0x2': 'eip1559', +} as const diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 342d50cea9..c946917848 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -6,6 +6,8 @@ export type { FetchBlockResponse, FetchTransactionArgs, FetchTransactionResponse, + FetchTransactionReceiptArgs, + FetchTransactionReceiptResponse, MineArgs, SendTransactionArgs, SendTransactionResponse, @@ -22,6 +24,7 @@ export { fetchBlock, fetchBlockNumber, fetchTransaction, + fetchTransactionReceipt, mine, requestAccounts, sendTransaction, @@ -60,6 +63,8 @@ export { webSocket, } from './clients' +export { etherUnits, gweiUnits, transactionType, weiUnits } from './constants' + export type { Address, AccessList, @@ -123,17 +128,13 @@ export { checksumAddress, displayToValue, etherToValue, - etherUnits, formatBlock, formatTransaction, formatTransactionRequest, gweiToValue, - gweiUnits, hexToNumber, numberToHex, - transactionType, valueAsEther, valueAsGwei, valueToDisplay, - weiUnits, } from './utils' diff --git a/packages/core/src/types/rpc.ts b/packages/core/src/types/rpc.ts index 3f15b4eba5..60c15e3507 100644 --- a/packages/core/src/types/rpc.ts +++ b/packages/core/src/types/rpc.ts @@ -11,6 +11,8 @@ import type { export type Index = `0x${string}` export type Quantity = `0x${string}` +export type Status = '0x0' | '0x1' +export type TransactionType = '0x0' | '0x1' | '0x2' export type RpcBlock = Block export type RpcBlockNumber = BlockNumber @@ -19,7 +21,12 @@ export type RpcUncle = Uncle export type RpcFeeHistory = FeeHistory export type RpcFeeValues = FeeValues export type RpcLog = Log -export type RpcTransactionReceipt = TransactionReceipt +export type RpcTransactionReceipt = TransactionReceipt< + Quantity, + Index, + Status, + TransactionType +> export type RpcTransactionRequest = TransactionRequest export type RpcTransaction = | TransactionLegacy diff --git a/packages/core/src/types/transaction.ts b/packages/core/src/types/transaction.ts index 91cd376181..dd854a5493 100644 --- a/packages/core/src/types/transaction.ts +++ b/packages/core/src/types/transaction.ts @@ -1,11 +1,20 @@ +import type { transactionType } from '../constants' import type { Address } from './address' import type { Data } from './data' import type { FeeValuesEIP1559, FeeValuesLegacy } from './fee' import type { Log } from './log' +import type { ValueOf } from './utils' export type AccessList = Array<{ address: Address; storageKeys: Array }> -export type TransactionReceipt = { +export type TransactionType = ValueOf + +export type TransactionReceipt< + TQuantity = bigint, + TIndex = number, + TStatus = 'success' | 'reverted', + TType = TransactionType, +> = { /** Hash of block containing this transaction */ blockHash: Data /** Number of block containing this transaction */ @@ -25,13 +34,15 @@ export type TransactionReceipt = { /** Logs bloom filter */ logsBloom: Data /** `1` if this transaction was successful or `0` if it failed */ - status: 0 | 1 + status: TStatus /** Transaction recipient or `null` if deploying a contract */ to: Address | null /** Hash of this transaction */ transactionHash: Data /** Index of this transaction in the block */ transactionIndex: TIndex + /** Transaction type */ + type: TType } export type TransactionBase = { diff --git a/packages/core/src/types/utils.ts b/packages/core/src/types/utils.ts index 5e3b2e08c5..e283887f96 100644 --- a/packages/core/src/types/utils.ts +++ b/packages/core/src/types/utils.ts @@ -34,3 +34,12 @@ export type OptionalNullable = { * => { a?: string, b: number } */ export type PartialBy = Omit & Partial> + +/** + * @description Creates a type that extracts the values of T. + * + * @example + * ValueOf<{ a: string, b: number }> + * => string | number + */ +export type ValueOf = T[keyof T] diff --git a/packages/core/src/utils/formatters/block.ts b/packages/core/src/utils/formatters/block.ts index ad9d934fbe..70e004ff05 100644 --- a/packages/core/src/utils/formatters/block.ts +++ b/packages/core/src/utils/formatters/block.ts @@ -1,10 +1,11 @@ -import type { Chain, Formatter } from '../../chains' +import type { Chain, Formatter, Formatters } from '../../chains' import type { Block, RpcBlock } from '../../types' import type { ExtractFormatter, Formatted } from './format' export type BlockFormatter = ExtractFormatter< TChain, - 'block' + 'block', + NonNullable > export type FormattedBlock< diff --git a/packages/core/src/utils/formatters/format.ts b/packages/core/src/utils/formatters/format.ts index fdbf785518..f9aa92eede 100644 --- a/packages/core/src/utils/formatters/format.ts +++ b/packages/core/src/utils/formatters/format.ts @@ -4,7 +4,10 @@ import type { OptionalNullable } from '../../types' export type ExtractFormatter< TChain extends Chain, TKey extends keyof NonNullable, -> = NonNullable[TKey] + TFallbackFormatter extends Formatter = Formatter, +> = NonNullable[TKey] extends NonNullable + ? NonNullable[TKey] + : TFallbackFormatter export type FormatOptions = { formatter: Formatter diff --git a/packages/core/src/utils/formatters/index.test.ts b/packages/core/src/utils/formatters/index.test.ts index f6255f3a95..59d96b6566 100644 --- a/packages/core/src/utils/formatters/index.test.ts +++ b/packages/core/src/utils/formatters/index.test.ts @@ -9,11 +9,6 @@ test('exports formatters', () => { "formatBlock": [Function], "formatTransaction": [Function], "formatTransactionRequest": [Function], - "transactionType": { - "0x0": "legacy", - "0x1": "eip2930", - "0x2": "eip1559", - }, } `) }) diff --git a/packages/core/src/utils/formatters/index.ts b/packages/core/src/utils/formatters/index.ts index 352a785125..546d271f10 100644 --- a/packages/core/src/utils/formatters/index.ts +++ b/packages/core/src/utils/formatters/index.ts @@ -5,7 +5,7 @@ export type { ExtractFormatter, FormatOptions, Formatted } from './format' export { format } from './format' export type { FormattedTransaction, TransactionFormatter } from './transaction' -export { formatTransaction, transactionType } from './transaction' +export { formatTransaction } from './transaction' export type { FormattedTransactionRequest, diff --git a/packages/core/src/utils/formatters/log.test.ts b/packages/core/src/utils/formatters/log.test.ts new file mode 100644 index 0000000000..e1ee9ae0bd --- /dev/null +++ b/packages/core/src/utils/formatters/log.test.ts @@ -0,0 +1,79 @@ +import { expect, test } from 'vitest' + +import { formatLog } from './log' + +test('formats', () => { + expect( + formatLog({ + address: '0x15d4c048f83bd7e37d49ea4c83a07267ec4203da', + blockHash: + '0x89644bbd5c8d682a2e9611170e6c1f02573d866d286f006cbf517eec7254ec2d', + blockNumber: '0xe6e55f', + data: '0x0000000000000000000000000000000000000000000000000000002b3b6fb3d0', + logIndex: '0x6c', + removed: false, + topics: [ + '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef', + '0x000000000000000000000000a00f99bc38b1ecda1fd70eaa1cd31d576a9f46b0', + '0x000000000000000000000000f16e9b0d03470827a95cdfd0cb8a8a3b46969b91', + ], + transactionHash: + '0xa4b1f606b66105fa45cb5db23d2f6597075701e7f0e2367f4e6a39d17a8cf98b', + transactionIndex: '0x45', + }), + ).toMatchInlineSnapshot(` + { + "address": "0x15d4c048f83bd7e37d49ea4c83a07267ec4203da", + "blockHash": "0x89644bbd5c8d682a2e9611170e6c1f02573d866d286f006cbf517eec7254ec2d", + "blockNumber": 15131999n, + "data": "0x0000000000000000000000000000000000000000000000000000002b3b6fb3d0", + "logIndex": 108n, + "removed": false, + "topics": [ + "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", + "0x000000000000000000000000a00f99bc38b1ecda1fd70eaa1cd31d576a9f46b0", + "0x000000000000000000000000f16e9b0d03470827a95cdfd0cb8a8a3b46969b91", + ], + "transactionHash": "0xa4b1f606b66105fa45cb5db23d2f6597075701e7f0e2367f4e6a39d17a8cf98b", + "transactionIndex": 69n, + } + `) +}) + +test('nullish values', () => { + expect( + formatLog({ + address: '0x15d4c048f83bd7e37d49ea4c83a07267ec4203da', + blockHash: + '0x89644bbd5c8d682a2e9611170e6c1f02573d866d286f006cbf517eec7254ec2d', + blockNumber: undefined, + data: '0x0000000000000000000000000000000000000000000000000000002b3b6fb3d0', + logIndex: undefined, + removed: false, + topics: [ + '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef', + '0x000000000000000000000000a00f99bc38b1ecda1fd70eaa1cd31d576a9f46b0', + '0x000000000000000000000000f16e9b0d03470827a95cdfd0cb8a8a3b46969b91', + ], + transactionHash: + '0xa4b1f606b66105fa45cb5db23d2f6597075701e7f0e2367f4e6a39d17a8cf98b', + transactionIndex: undefined, + }), + ).toMatchInlineSnapshot(` + { + "address": "0x15d4c048f83bd7e37d49ea4c83a07267ec4203da", + "blockHash": "0x89644bbd5c8d682a2e9611170e6c1f02573d866d286f006cbf517eec7254ec2d", + "blockNumber": null, + "data": "0x0000000000000000000000000000000000000000000000000000002b3b6fb3d0", + "logIndex": null, + "removed": false, + "topics": [ + "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", + "0x000000000000000000000000a00f99bc38b1ecda1fd70eaa1cd31d576a9f46b0", + "0x000000000000000000000000f16e9b0d03470827a95cdfd0cb8a8a3b46969b91", + ], + "transactionHash": "0xa4b1f606b66105fa45cb5db23d2f6597075701e7f0e2367f4e6a39d17a8cf98b", + "transactionIndex": null, + } + `) +}) diff --git a/packages/core/src/utils/formatters/log.ts b/packages/core/src/utils/formatters/log.ts new file mode 100644 index 0000000000..f47a803a41 --- /dev/null +++ b/packages/core/src/utils/formatters/log.ts @@ -0,0 +1,12 @@ +import type { RpcLog } from '../../types' + +export function formatLog(log: Partial) { + return { + ...log, + blockNumber: log.blockNumber ? BigInt(log.blockNumber) : null, + logIndex: log.logIndex ? BigInt(log.logIndex) : null, + transactionIndex: log.transactionIndex + ? BigInt(log.transactionIndex) + : null, + } +} diff --git a/packages/core/src/utils/formatters/transaction.test.ts b/packages/core/src/utils/formatters/transaction.test.ts index d11cb68a8f..ba6930c113 100644 --- a/packages/core/src/utils/formatters/transaction.test.ts +++ b/packages/core/src/utils/formatters/transaction.test.ts @@ -1,16 +1,6 @@ import { expect, test } from 'vitest' -import { formatTransaction, transactionType } from './transaction' - -test('transactionType', () => { - expect(transactionType).toMatchInlineSnapshot(` - { - "0x0": "legacy", - "0x1": "eip2930", - "0x2": "eip1559", - } - `) -}) +import { formatTransaction } from './transaction' test('legacy transaction', () => { expect( diff --git a/packages/core/src/utils/formatters/transaction.ts b/packages/core/src/utils/formatters/transaction.ts index d65f8656a1..6e1f2cdaa2 100644 --- a/packages/core/src/utils/formatters/transaction.ts +++ b/packages/core/src/utils/formatters/transaction.ts @@ -1,21 +1,20 @@ -import type { Chain, Formatter } from '../../chains' +import type { Chain, Formatter, Formatters } from '../../chains' import type { RpcTransaction, Transaction } from '../../types' -import type { ExtractFormatter, Formatted } from './format' +import { transactionType } from '../../constants' import { hexToNumber } from '../number' +import type { ExtractFormatter, Formatted } from './format' export type TransactionFormatter = - ExtractFormatter + ExtractFormatter< + TChain, + 'transaction', + NonNullable + > export type FormattedTransaction< TFormatter extends Formatter | undefined = Formatter, > = Formatted -export const transactionType = { - '0x0': 'legacy', - '0x1': 'eip2930', - '0x2': 'eip1559', -} as const - export function formatTransaction(transaction: Partial) { const transaction_ = { ...transaction, diff --git a/packages/core/src/utils/formatters/transactionReceipt.test.ts b/packages/core/src/utils/formatters/transactionReceipt.test.ts new file mode 100644 index 0000000000..bed76ec526 --- /dev/null +++ b/packages/core/src/utils/formatters/transactionReceipt.test.ts @@ -0,0 +1,151 @@ +import { expect, test } from 'vitest' + +import { formatTransactionReceipt } from './transactionReceipt' + +test('formats', () => { + expect( + formatTransactionReceipt({ + blockHash: + '0x89644bbd5c8d682a2e9611170e6c1f02573d866d286f006cbf517eec7254ec2d', + blockNumber: '0xe6e55f', + contractAddress: null, + cumulativeGasUsed: '0x58b887', + effectiveGasPrice: '0x2beb40be9', + from: '0xa152f8bb749c55e9943a3a0a3111d18ee2b3f94e', + gasUsed: '0x9458', + logs: [ + { + address: '0x15d4c048f83bd7e37d49ea4c83a07267ec4203da', + blockHash: + '0x89644bbd5c8d682a2e9611170e6c1f02573d866d286f006cbf517eec7254ec2d', + blockNumber: '0xe6e55f', + data: '0x0000000000000000000000000000000000000000000000000000002b3b6fb3d0', + logIndex: '0x6c', + removed: false, + topics: [ + '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef', + '0x000000000000000000000000a00f99bc38b1ecda1fd70eaa1cd31d576a9f46b0', + '0x000000000000000000000000f16e9b0d03470827a95cdfd0cb8a8a3b46969b91', + ], + transactionHash: + '0xa4b1f606b66105fa45cb5db23d2f6597075701e7f0e2367f4e6a39d17a8cf98b', + transactionIndex: '0x45', + }, + { + address: '0x15d4c048f83bd7e37d49ea4c83a07267ec4203da', + blockHash: + '0x89644bbd5c8d682a2e9611170e6c1f02573d866d286f006cbf517eec7254ec2d', + blockNumber: '0xe6e55f', + data: '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffd4c4904c2f', + logIndex: '0x6d', + removed: false, + topics: [ + '0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925', + '0x000000000000000000000000a00f99bc38b1ecda1fd70eaa1cd31d576a9f46b0', + '0x000000000000000000000000a152f8bb749c55e9943a3a0a3111d18ee2b3f94e', + ], + transactionHash: + '0xa4b1f606b66105fa45cb5db23d2f6597075701e7f0e2367f4e6a39d17a8cf98b', + transactionIndex: '0x45', + }, + ], + logsBloom: + '0x08000000000000000000000000000000000000000000000000001000002000000000000000000000000000000000000000000000080000000000000000200000000000000000000000000008400000000000000000000000000000000000100000000000000000000040000008000000000004000000000000000010000000000000000000000000000000000000000000000000000000000000000000000004020000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000002090000000000000000000000000000000000000000000000000000000000000', + status: '0x1', + to: '0x15d4c048f83bd7e37d49ea4c83a07267ec4203da', + transactionHash: + '0xa4b1f606b66105fa45cb5db23d2f6597075701e7f0e2367f4e6a39d17a8cf98b', + transactionIndex: '0x45', + type: '0x2', + }), + ).toMatchInlineSnapshot(` + { + "blockHash": "0x89644bbd5c8d682a2e9611170e6c1f02573d866d286f006cbf517eec7254ec2d", + "blockNumber": 15131999n, + "contractAddress": null, + "cumulativeGasUsed": 5814407n, + "effectiveGasPrice": 11789405161n, + "from": "0xa152f8bb749c55e9943a3a0a3111d18ee2b3f94e", + "gasUsed": 37976n, + "logs": [ + { + "address": "0x15d4c048f83bd7e37d49ea4c83a07267ec4203da", + "blockHash": "0x89644bbd5c8d682a2e9611170e6c1f02573d866d286f006cbf517eec7254ec2d", + "blockNumber": 15131999n, + "data": "0x0000000000000000000000000000000000000000000000000000002b3b6fb3d0", + "logIndex": 108n, + "removed": false, + "topics": [ + "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", + "0x000000000000000000000000a00f99bc38b1ecda1fd70eaa1cd31d576a9f46b0", + "0x000000000000000000000000f16e9b0d03470827a95cdfd0cb8a8a3b46969b91", + ], + "transactionHash": "0xa4b1f606b66105fa45cb5db23d2f6597075701e7f0e2367f4e6a39d17a8cf98b", + "transactionIndex": 69n, + }, + { + "address": "0x15d4c048f83bd7e37d49ea4c83a07267ec4203da", + "blockHash": "0x89644bbd5c8d682a2e9611170e6c1f02573d866d286f006cbf517eec7254ec2d", + "blockNumber": 15131999n, + "data": "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffd4c4904c2f", + "logIndex": 109n, + "removed": false, + "topics": [ + "0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925", + "0x000000000000000000000000a00f99bc38b1ecda1fd70eaa1cd31d576a9f46b0", + "0x000000000000000000000000a152f8bb749c55e9943a3a0a3111d18ee2b3f94e", + ], + "transactionHash": "0xa4b1f606b66105fa45cb5db23d2f6597075701e7f0e2367f4e6a39d17a8cf98b", + "transactionIndex": 69n, + }, + ], + "logsBloom": "0x08000000000000000000000000000000000000000000000000001000002000000000000000000000000000000000000000000000080000000000000000200000000000000000000000000008400000000000000000000000000000000000100000000000000000000040000008000000000004000000000000000010000000000000000000000000000000000000000000000000000000000000000000000004020000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000002090000000000000000000000000000000000000000000000000000000000000", + "status": "success", + "to": "0x15d4c048f83bd7e37d49ea4c83a07267ec4203da", + "transactionHash": "0xa4b1f606b66105fa45cb5db23d2f6597075701e7f0e2367f4e6a39d17a8cf98b", + "transactionIndex": 69, + "type": "eip1559", + } + `) +}) + +test('nullish values', () => { + expect( + formatTransactionReceipt({ + blockHash: + '0x89644bbd5c8d682a2e9611170e6c1f02573d866d286f006cbf517eec7254ec2d', + blockNumber: undefined, + contractAddress: null, + cumulativeGasUsed: undefined, + effectiveGasPrice: undefined, + from: '0xa152f8bb749c55e9943a3a0a3111d18ee2b3f94e', + gasUsed: undefined, + logs: undefined, + logsBloom: + '0x08000000000000000000000000000000000000000000000000001000002000000000000000000000000000000000000000000000080000000000000000200000000000000000000000000008400000000000000000000000000000000000100000000000000000000040000008000000000004000000000000000010000000000000000000000000000000000000000000000000000000000000000000000004020000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000002090000000000000000000000000000000000000000000000000000000000000', + status: undefined, + to: '0x15d4c048f83bd7e37d49ea4c83a07267ec4203da', + transactionHash: + '0xa4b1f606b66105fa45cb5db23d2f6597075701e7f0e2367f4e6a39d17a8cf98b', + transactionIndex: undefined, + type: undefined, + }), + ).toMatchInlineSnapshot(` + { + "blockHash": "0x89644bbd5c8d682a2e9611170e6c1f02573d866d286f006cbf517eec7254ec2d", + "blockNumber": null, + "contractAddress": null, + "cumulativeGasUsed": null, + "effectiveGasPrice": null, + "from": "0xa152f8bb749c55e9943a3a0a3111d18ee2b3f94e", + "gasUsed": null, + "logs": null, + "logsBloom": "0x08000000000000000000000000000000000000000000000000001000002000000000000000000000000000000000000000000000080000000000000000200000000000000000000000000008400000000000000000000000000000000000100000000000000000000040000008000000000004000000000000000010000000000000000000000000000000000000000000000000000000000000000000000004020000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000002090000000000000000000000000000000000000000000000000000000000000", + "status": null, + "to": "0x15d4c048f83bd7e37d49ea4c83a07267ec4203da", + "transactionHash": "0xa4b1f606b66105fa45cb5db23d2f6597075701e7f0e2367f4e6a39d17a8cf98b", + "transactionIndex": null, + "type": null, + } + `) +}) diff --git a/packages/core/src/utils/formatters/transactionReceipt.ts b/packages/core/src/utils/formatters/transactionReceipt.ts new file mode 100644 index 0000000000..81f5c22d28 --- /dev/null +++ b/packages/core/src/utils/formatters/transactionReceipt.ts @@ -0,0 +1,54 @@ +import type { Chain, Formatter, Formatters } from '../../chains' +import { transactionType } from '../../constants' +import type { RpcTransactionReceipt, TransactionReceipt } from '../../types' +import { hexToNumber } from '../number' +import type { ExtractFormatter, Formatted } from './format' +import { formatLog } from './log' + +export type TransactionReceiptFormatter = + ExtractFormatter< + TChain, + 'transactionReceipt', + NonNullable + > + +export type FormattedTransactionReceipt< + TFormatter extends Formatter | undefined = Formatter, +> = Formatted + +const statuses = { + '0x0': 'reverted', + '0x1': 'success', +} as const + +export function formatTransactionReceipt( + transactionReceipt: Partial, +) { + return { + ...transactionReceipt, + blockNumber: transactionReceipt.blockNumber + ? BigInt(transactionReceipt.blockNumber) + : null, + cumulativeGasUsed: transactionReceipt.cumulativeGasUsed + ? BigInt(transactionReceipt.cumulativeGasUsed) + : null, + effectiveGasPrice: transactionReceipt.effectiveGasPrice + ? BigInt(transactionReceipt.effectiveGasPrice) + : null, + gasUsed: transactionReceipt.gasUsed + ? BigInt(transactionReceipt.gasUsed) + : null, + logs: transactionReceipt.logs + ? transactionReceipt.logs.map(formatLog) + : null, + transactionIndex: transactionReceipt.transactionIndex + ? hexToNumber(transactionReceipt.transactionIndex) + : null, + status: transactionReceipt.status + ? statuses[transactionReceipt.status] + : null, + type: transactionReceipt.type + ? transactionType[transactionReceipt.type] + : null, + } as TransactionReceipt +} diff --git a/packages/core/src/utils/index.test.ts b/packages/core/src/utils/index.test.ts index fcba1ae873..2a8ab37850 100644 --- a/packages/core/src/utils/index.test.ts +++ b/packages/core/src/utils/index.test.ts @@ -26,19 +26,11 @@ test('exports utils', () => { "checksumAddress": [Function], "displayToValue": [Function], "etherToValue": [Function], - "etherUnits": { - "gwei": 9, - "wei": 18, - }, "format": [Function], "formatBlock": [Function], "formatTransaction": [Function], "formatTransactionRequest": [Function], "gweiToValue": [Function], - "gweiUnits": { - "ether": -9, - "wei": 9, - }, "hexToNumber": [Function], "numberToHex": [Function], "rpc": { @@ -46,18 +38,9 @@ test('exports utils', () => { "webSocket": [Function], "webSocketAsync": [Function], }, - "transactionType": { - "0x0": "legacy", - "0x1": "eip2930", - "0x2": "eip1559", - }, "valueAsEther": [Function], "valueAsGwei": [Function], "valueToDisplay": [Function], - "weiUnits": { - "ether": -18, - "gwei": -9, - }, } `) }) diff --git a/packages/core/src/utils/index.ts b/packages/core/src/utils/index.ts index abebeae664..82e3e53d0d 100644 --- a/packages/core/src/utils/index.ts +++ b/packages/core/src/utils/index.ts @@ -34,7 +34,6 @@ export { formatBlock, formatTransaction, formatTransactionRequest, - transactionType, } from './formatters' export { hexToNumber, numberToHex } from './number' @@ -44,11 +43,8 @@ export { HttpRequestError, RpcError, TimeoutError, rpc } from './rpc' export { displayToValue, etherToValue, - etherUnits, gweiToValue, - gweiUnits, valueAsEther, valueAsGwei, valueToDisplay, - weiUnits, } from './unit' diff --git a/packages/core/src/utils/unit/etherToValue.ts b/packages/core/src/utils/unit/etherToValue.ts index 439bd5a8b4..38152fb8a2 100644 --- a/packages/core/src/utils/unit/etherToValue.ts +++ b/packages/core/src/utils/unit/etherToValue.ts @@ -1,4 +1,4 @@ -import { etherUnits } from './constants' +import { etherUnits } from '../../constants' import { displayToValue } from './displayToValue' export function etherToValue(ether: `${number}`, unit: 'wei' | 'gwei' = 'wei') { diff --git a/packages/core/src/utils/unit/gweiToValue.ts b/packages/core/src/utils/unit/gweiToValue.ts index 91b7ed4239..1aba8e8127 100644 --- a/packages/core/src/utils/unit/gweiToValue.ts +++ b/packages/core/src/utils/unit/gweiToValue.ts @@ -1,4 +1,4 @@ -import { gweiUnits } from './constants' +import { gweiUnits } from '../../constants' import { displayToValue } from './displayToValue' export function gweiToValue(ether: `${number}`, unit: 'wei' = 'wei') { diff --git a/packages/core/src/utils/unit/index.test.ts b/packages/core/src/utils/unit/index.test.ts index 9e68b5bf8a..facf82fda8 100644 --- a/packages/core/src/utils/unit/index.test.ts +++ b/packages/core/src/utils/unit/index.test.ts @@ -7,22 +7,10 @@ test('exports value utils', () => { { "displayToValue": [Function], "etherToValue": [Function], - "etherUnits": { - "gwei": 9, - "wei": 18, - }, "gweiToValue": [Function], - "gweiUnits": { - "ether": -9, - "wei": 9, - }, "valueAsEther": [Function], "valueAsGwei": [Function], "valueToDisplay": [Function], - "weiUnits": { - "ether": -18, - "gwei": -9, - }, } `) }) diff --git a/packages/core/src/utils/unit/index.ts b/packages/core/src/utils/unit/index.ts index 144829a40a..390f8a93d3 100644 --- a/packages/core/src/utils/unit/index.ts +++ b/packages/core/src/utils/unit/index.ts @@ -1,4 +1,3 @@ -export { etherUnits, gweiUnits, weiUnits } from './constants' export { displayToValue } from './displayToValue' export { etherToValue } from './etherToValue' export { gweiToValue } from './gweiToValue' diff --git a/packages/core/src/utils/unit/valueAsEther.ts b/packages/core/src/utils/unit/valueAsEther.ts index 8c9b1f8125..ef41ed44e5 100644 --- a/packages/core/src/utils/unit/valueAsEther.ts +++ b/packages/core/src/utils/unit/valueAsEther.ts @@ -1,4 +1,4 @@ -import { etherUnits } from './constants' +import { etherUnits } from '../../constants' import { valueToDisplay } from './valueToDisplay' export function valueAsEther(wei: bigint, unit: 'wei' | 'gwei' = 'wei') { diff --git a/packages/core/src/utils/unit/valueAsGwei.ts b/packages/core/src/utils/unit/valueAsGwei.ts index 170c9b28ed..2cca872acc 100644 --- a/packages/core/src/utils/unit/valueAsGwei.ts +++ b/packages/core/src/utils/unit/valueAsGwei.ts @@ -1,4 +1,4 @@ -import { gweiUnits } from './constants' +import { gweiUnits } from '../../constants' import { valueToDisplay } from './valueToDisplay' export function valueAsGwei(wei: bigint, unit: 'wei' = 'wei') { From a8f880e4ecd4a5b0d8f10a9f1f2dba3350a9f908 Mon Sep 17 00:00:00 2001 From: "moxey.eth" Date: Sat, 17 Dec 2022 19:00:59 +1100 Subject: [PATCH 3/3] benchmark: fetchTransactionReceipt --- playgrounds/benchmark/suite.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/playgrounds/benchmark/suite.ts b/playgrounds/benchmark/suite.ts index 3b4336952b..bb65016a90 100644 --- a/playgrounds/benchmark/suite.ts +++ b/playgrounds/benchmark/suite.ts @@ -4,6 +4,7 @@ import { fetchBlock, fetchBlockNumber, fetchTransaction, + fetchTransactionReceipt, sendTransaction, } from 'viem/actions' import { createClient, http } from 'viem/clients' @@ -59,7 +60,7 @@ const formatter = new providers.Formatter() export const getSuite = ({ url }: { url: string }): Suite => { const viemClient = createClient({ chain: mainnet, transport: http({ url }) }) - const ethersProvider = new ethers.providers.JsonRpcProvider(url) + const ethersProvider = new ethers.providers.StaticJsonRpcProvider(url) return [ { title: 'current block number', @@ -134,6 +135,22 @@ export const getSuite = ({ url }: { url: string }): Suite => { }, }, }, + { + title: 'get txn receipt', + key: 'getTransactionReceipt', + fns: { + viem: async () => { + await fetchTransactionReceipt(viemClient, { + hash: '0x493b3ce4b88a2b432c85f75ab18b1d54ac37d59659c2c4a41514c4c6f4d6a87f', + }) + }, + ethers: async () => { + await ethersProvider.getTransactionReceipt( + '0x493b3ce4b88a2b432c85f75ab18b1d54ac37d59659c2c4a41514c4c6f4d6a87f', + ) + }, + }, + }, { title: 'send txn', key: 'sendTransaction',