Skip to content

Commit

Permalink
tweak(experimental): getCallsStatus -> getCallsReceipt
Browse files Browse the repository at this point in the history
  • Loading branch information
jxom committed Apr 3, 2024
1 parent 7b0bfbb commit 8416fd1
Show file tree
Hide file tree
Showing 15 changed files with 70 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
description: Returns the status and receipts of a call batch.
---

# getCallsStatus
# getCallsReceipt

Returns the status and receipts of a call batch that was sent via `sendCalls`.

[Read more.](https://github.com/ethereum/EIPs/blob/1d759f24e6552a516091bb1fe3361d9ca44d085c/EIPS/eip-5792.md#wallet_getcallsstatus)
[Read more.](https://github.com/ethereum/EIPs/blob/815028dc634463e1716fc5ce44c019a6040f0bef/EIPS/eip-5792.md#wallet_getcallsreceipt)

:::warning[Warning]
This is an experimental action that is not supported in most wallets. It is recommended to have a fallback mechanism if using this in production.
Expand All @@ -19,7 +19,7 @@ This is an experimental action that is not supported in most wallets. It is reco
```ts twoslash [example.ts]
import { walletClient } from './config'

const { status, receipts } = await walletClient.getCallsStatus({ // [!code focus:99]
const { status, receipts } = await walletClient.getCallsReceipt({ // [!code focus:99]
id: '0x1234567890abcdef',
})
```
Expand All @@ -43,7 +43,7 @@ export const [account] = await walletClient.getAddresses()

## Returns

`WalletGetCallsStatusReturnType`
`WalletGetCallsReceiptReturnType`

Status and receipts of the calls.

Expand Down
2 changes: 1 addition & 1 deletion site/pages/experimental/actions/getCapabilities.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ description: Extract capabilities that a connected wallet supports.

Extract capabilities (grouped by chain ID) that a connected wallet supports (e.g. paymasters, session keys, etc).

[Read more.](https://github.com/ethereum/EIPs/blob/1d759f24e6552a516091bb1fe3361d9ca44d085c/EIPS/eip-5792.md#wallet_getcapabilities)
[Read more.](https://github.com/ethereum/EIPs/blob/815028dc634463e1716fc5ce44c019a6040f0bef/EIPS/eip-5792.md#wallet_getcapabilities)

:::warning[Warning]
This is an experimental action that is not supported in most wallets. It is recommended to have a fallback mechanism if using this in production.
Expand Down
6 changes: 3 additions & 3 deletions site/pages/experimental/actions/sendCalls.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ description: Sign and broadcast a batch of calls to the network.

Requests for the wallet to sign and broadcast a batch of calls (transactions) to the network.

[Read more.](https://github.com/ethereum/EIPs/blob/1d759f24e6552a516091bb1fe3361d9ca44d085c/EIPS/eip-5792.md#wallet_sendcalls)
[Read more.](https://github.com/ethereum/EIPs/blob/815028dc634463e1716fc5ce44c019a6040f0bef/EIPS/eip-5792.md#wallet_sendcalls)

:::warning[Warning]
This is an experimental action that is not supported in most wallets. It is recommended to have a fallback mechanism if using this in production.
Expand Down Expand Up @@ -56,7 +56,7 @@ Notes:

- `account` and `chain` are top level properties as all calls should be sent by the same account and chain.
- Properties of `calls` items are only those shared by all transaction types (e.g. `data`, `to`, `value`). The Wallet should handle other required properties like gas & fees.
- [Read `wallet_sendCalls` on EIP-5792.](https://github.com/ethereum/EIPs/blob/1d759f24e6552a516091bb1fe3361d9ca44d085c/EIPS/eip-5792.md#wallet_sendcalls)
- [Read `wallet_sendCalls` on EIP-5792.](https://github.com/ethereum/EIPs/blob/815028dc634463e1716fc5ce44c019a6040f0bef/EIPS/eip-5792.md#wallet_sendcalls)

### Account Hoisting

Expand Down Expand Up @@ -105,7 +105,7 @@ export const walletClient = createWalletClient({

`string`

The identifier can be any arbitrary string. The only requirement is that for a given session, consumers should be able to call `getCallsStatus` with this identifier to retreive a batch call status and call receipts.
The identifier can be any arbitrary string. The only requirement is that for a given session, consumers should be able to call `getCallsReceipt` with this identifier to retreive a batch call status and call receipts.

## Parameters

Expand Down
6 changes: 3 additions & 3 deletions site/pages/experimental/actions/writeContracts.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ description: Sign and broadcast a batch of write contract calls to the network.

Requests for the wallet to sign and broadcast a batch of write contract calls (transactions) to the network.

[Read more.](https://github.com/ethereum/EIPs/blob/1d759f24e6552a516091bb1fe3361d9ca44d085c/EIPS/eip-5792.md#wallet_sendcalls)
[Read more.](https://github.com/ethereum/EIPs/blob/815028dc634463e1716fc5ce44c019a6040f0bef/EIPS/eip-5792.md#wallet_sendcalls)

:::warning[Warning]
This is an experimental action that is not supported in most wallets. It is recommended to have a fallback mechanism if using this in production.
Expand Down Expand Up @@ -72,7 +72,7 @@ Notes:

- Internally calls [`sendCalls`](/experimental/actions/writeContracts)
- `account` and `chain` are top level properties as all calls should be sent by the same account and chain.
- [Read `wallet_sendCalls` on EIP-5792.](https://github.com/ethereum/EIPs/blob/1d759f24e6552a516091bb1fe3361d9ca44d085c/EIPS/eip-5792.md#wallet_sendcalls)
- [Read `wallet_sendCalls` on EIP-5792.](https://github.com/ethereum/EIPs/blob/815028dc634463e1716fc5ce44c019a6040f0bef/EIPS/eip-5792.md#wallet_sendcalls)

### Account Hoisting

Expand Down Expand Up @@ -138,7 +138,7 @@ export const walletClient = createWalletClient({

`string`

The identifier can be any arbitrary string. The only requirement is that for a given session, consumers should be able to call `getCallsStatus` with this identifier to retreive a batch call status and call receipts.
The identifier can be any arbitrary string. The only requirement is that for a given session, consumers should be able to call `getCallsReceipt` with this identifier to retreive a batch call status and call receipts.

## Parameters

Expand Down
2 changes: 1 addition & 1 deletion site/pages/experimental/client.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ To use the experimental functionality of Viem, you must extend your existing (or

### `walletActionsEip5792`

A suite of [EIP-5792 Wallet Actions](https://github.com/ethereum/EIPs/blob/1d759f24e6552a516091bb1fe3361d9ca44d085c/EIPS/eip-5792.md) for suited for development with wallet's that support batch transactions.
A suite of [EIP-5792 Wallet Actions](https://github.com/ethereum/EIPs/blob/815028dc634463e1716fc5ce44c019a6040f0bef/EIPS/eip-5792.md) for suited for development with wallet's that support batch transactions.

```ts
import { createPublicClient, createWalletClient, http } from 'viem'
Expand Down
4 changes: 2 additions & 2 deletions site/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1013,8 +1013,8 @@ export const sidebar = {
text: 'EIP-5792',
items: [
{
text: 'getCallsStatus',
link: '/experimental/actions/getCallsStatus',
text: 'getCallsReceipt',
link: '/experimental/actions/getCallsReceipt',
},
{
text: 'getCapabilities',
Expand Down
2 changes: 1 addition & 1 deletion src/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

### Patch Changes

- [#2053](https://github.com/wevm/viem/pull/2053) [`e53fe120b9c15dde3e50eda794e261f320bf52bc`](https://github.com/wevm/viem/commit/e53fe120b9c15dde3e50eda794e261f320bf52bc) Thanks [@jxom](https://github.com/jxom)! - Added experimental support for [EIP-5792 `wallet_` methods](https://github.com/ethereum/EIPs/blob/1d759f24e6552a516091bb1fe3361d9ca44d085c/EIPS/eip-5792.md).
- [#2053](https://github.com/wevm/viem/pull/2053) [`e53fe120b9c15dde3e50eda794e261f320bf52bc`](https://github.com/wevm/viem/commit/e53fe120b9c15dde3e50eda794e261f320bf52bc) Thanks [@jxom](https://github.com/jxom)! - Added experimental support for [EIP-5792 `wallet_` methods](https://github.com/ethereum/EIPs/blob/815028dc634463e1716fc5ce44c019a6040f0bef/EIPS/eip-5792.md).

- [#2052](https://github.com/wevm/viem/pull/2052) [`445ec244c7be329eb26048102d282bac9bf23506`](https://github.com/wevm/viem/commit/445ec244c7be329eb26048102d282bac9bf23506) Thanks [@maggo](https://github.com/maggo)! - Added WebSocket RPC URL on Degen chain.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import { mainnet } from '../../chains/index.js'
import { createClient } from '../../clients/createClient.js'
import { custom } from '../../clients/transports/custom.js'
import { RpcRequestError } from '../../errors/request.js'
import type { WalletGetCallsStatusReceipt } from '../../types/eip1193.js'
import type { WalletCallReceipt } from '../../types/eip1193.js'
import type { Hex } from '../../types/misc.js'
import { getHttpRpcClient, parseEther } from '../../utils/index.js'
import { uid } from '../../utils/uid.js'
import { getCallsStatus } from './getCallsStatus.js'
import { getCallsReceipt } from './getCallsReceipt.js'
import { sendCalls } from './sendCalls.js'

type Uid = string
Expand All @@ -27,7 +27,7 @@ const getClient = ({

const rpcClient = getHttpRpcClient(localHttpUrl)

if (method === 'wallet_getCallsStatus') {
if (method === 'wallet_getCallsReceipt') {
const hashes = calls.get(params)
if (!hashes) return null
const receipts = await Promise.all(
Expand All @@ -52,7 +52,7 @@ const getClient = ({
logs: result.logs,
status: result.status,
transactionHash: result.transactionHash,
} satisfies WalletGetCallsStatusReceipt
} satisfies WalletCallReceipt
}),
)
return { status: 'CONFIRMED', receipts }
Expand Down Expand Up @@ -118,7 +118,7 @@ test('default', async () => {

await mine(testClient, { blocks: 1 })

const { status, receipts } = await getCallsStatus(client, { id })
const { status, receipts } = await getCallsReceipt(client, { id })
expect(status).toMatchInlineSnapshot(`"CONFIRMED"`)
expect(receipts![0].blockHash).toBeDefined()
expect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,50 @@ import type { Transport } from '../../clients/transports/createTransport.js'
import type { ErrorType } from '../../errors/utils.js'
import type { Account } from '../../types/account.js'
import type { Chain } from '../../types/chain.js'
import type { WalletGetCallsStatusReturnType } from '../../types/eip1193.js'
import type { WalletGetCallsReceiptReturnType } from '../../types/eip1193.js'
import type { Prettify } from '../../types/utils.js'
import type { RequestErrorType } from '../../utils/buildRequest.js'
import { hexToBigInt } from '../../utils/encoding/fromHex.js'
import { receiptStatuses } from '../../utils/formatters/transactionReceipt.js'

export type GetCallsStatusParameters = { id: string }
export type GetCallsReceiptParameters = { id: string }

export type GetCallsStatusReturnType = Prettify<
WalletGetCallsStatusReturnType<bigint, 'success' | 'reverted'>
export type GetCallsReceiptReturnType = Prettify<
WalletGetCallsReceiptReturnType<bigint, 'success' | 'reverted'>
>

export type GetCallsStatusErrorType = RequestErrorType | ErrorType
export type GetCallsReceiptErrorType = RequestErrorType | ErrorType

/**
* Returns the status of a call batch that was sent via `sendCalls`.
*
* - Docs: https://viem.sh/experimental/actions/getCallsStatus
* - JSON-RPC Methods: [`wallet_getCallsStatus`](https://eips.ethereum.org/EIPS/eip-5792)
* - Docs: https://viem.sh/experimental/actions/getCallsReceipt
* - JSON-RPC Methods: [`wallet_getCallsReceipt`](https://eips.ethereum.org/EIPS/eip-5792)
*
* @param client - Client to use
* @returns Status of the calls. {@link GetCallsStatusReturnType}
* @returns Status of the calls. {@link GetCallsReceiptReturnType}
*
* @example
* import { createWalletClient, custom } from 'viem'
* import { mainnet } from 'viem/chains'
* import { getCallsStatus } from 'viem/wallet'
* import { getCallsReceipt } from 'viem/wallet'
*
* const client = createWalletClient({
* chain: mainnet,
* transport: custom(window.ethereum),
* })
* const { receipts, status } = await getCallsStatus(client, { id: '0xdeadbeef' })
* const { receipts, status } = await getCallsReceipt(client, { id: '0xdeadbeef' })
*/
export async function getCallsStatus<
export async function getCallsReceipt<
chain extends Chain | undefined,
account extends Account | undefined = undefined,
>(
client: Client<Transport, chain, account>,
parameters: GetCallsStatusParameters,
): Promise<GetCallsStatusReturnType> {
parameters: GetCallsReceiptParameters,
): Promise<GetCallsReceiptReturnType> {
const { id } = parameters
const { receipts, status } = await client.request({
method: 'wallet_getCallsStatus',
method: 'wallet_getCallsReceipt',
params: id,
})
return {
Expand Down
10 changes: 5 additions & 5 deletions src/experimental/actions/writeContracts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import { mainnet } from '../../chains/index.js'
import { createClient } from '../../clients/createClient.js'
import { custom } from '../../clients/transports/custom.js'
import { RpcRequestError } from '../../errors/request.js'
import type { WalletGetCallsStatusReceipt } from '../../types/eip1193.js'
import type { WalletCallReceipt } from '../../types/eip1193.js'
import type { Hex } from '../../types/misc.js'
import { getHttpRpcClient } from '../../utils/index.js'
import { uid } from '../../utils/uid.js'
import { getCallsStatus } from './getCallsStatus.js'
import { getCallsReceipt } from './getCallsReceipt.js'
import { writeContracts } from './writeContracts.js'

type Uid = string
Expand All @@ -28,7 +28,7 @@ const getClient = ({

const rpcClient = getHttpRpcClient(localHttpUrl)

if (method === 'wallet_getCallsStatus') {
if (method === 'wallet_getCallsReceipt') {
const hashes = calls.get(params)
if (!hashes) return null
const receipts = await Promise.all(
Expand All @@ -54,7 +54,7 @@ const getClient = ({
logs: result.logs,
status: result.status,
transactionHash: result.transactionHash,
} satisfies WalletGetCallsStatusReceipt
} satisfies WalletCallReceipt
}),
)
return { status: 'CONFIRMED', receipts }
Expand Down Expand Up @@ -158,7 +158,7 @@ test('default', async () => {

await mine(testClient, { blocks: 3 })

const { receipts } = await getCallsStatus(client, { id: id_ })
const { receipts } = await getCallsReceipt(client, { id: id_ })

expect(
receipts?.map((receipt) => ({
Expand Down
10 changes: 6 additions & 4 deletions src/experimental/decorators/eip5792.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const client = createClient({
},
}
if (method === 'wallet_sendCalls') return '0x1'
if (method === 'wallet_getCallsStatus')
if (method === 'wallet_getCallsReceipt')
return {
status: 'CONFIRMED',
receipts: [
Expand All @@ -50,7 +50,7 @@ const client = createClient({
test('default', async () => {
expect(walletActionsEip5792()(client)).toMatchInlineSnapshot(`
{
"getCallsStatus": [Function],
"getCallsReceipt": [Function],
"getCapabilities": [Function],
"sendCalls": [Function],
"writeContracts": [Function],
Expand Down Expand Up @@ -79,8 +79,10 @@ describe('smoke test', () => {
`)
})

test('getCallsStatus', async () => {
expect(await client.getCallsStatus({ id: '0x123' })).toMatchInlineSnapshot(`
test('getCallsReceipt', async () => {
expect(
await client.getCallsReceipt({ id: '0x123' }),
).toMatchInlineSnapshot(`
{
"receipts": [
{
Expand Down
24 changes: 12 additions & 12 deletions src/experimental/decorators/eip5792.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import type { Transport } from '../../clients/transports/createTransport.js'
import type { Account } from '../../types/account.js'
import type { Chain } from '../../types/chain.js'
import {
type GetCallsStatusParameters,
type GetCallsStatusReturnType,
getCallsStatus,
} from '../actions/getCallsStatus.js'
type GetCallsReceiptParameters,
type GetCallsReceiptReturnType,
getCallsReceipt,
} from '../actions/getCallsReceipt.js'
import {
type GetCapabilitiesReturnType,
getCapabilities,
Expand All @@ -29,11 +29,11 @@ export type WalletActionsEip5792<
/**
* Returns the status of a call batch that was sent via `sendCalls`.
*
* - Docs: https://viem.sh/experimental/actions/getCallsStatus
* - JSON-RPC Methods: [`wallet_getCallsStatus`](https://eips.ethereum.org/EIPS/eip-5792)
* - Docs: https://viem.sh/experimental/actions/getCallsReceipt
* - JSON-RPC Methods: [`wallet_getCallsReceipt`](https://eips.ethereum.org/EIPS/eip-5792)
*
* @param client - Client to use
* @returns Status of the calls. {@link GetCallsStatusReturnType}
* @returns Status of the calls. {@link GetCallsReceiptReturnType}
*
* @example
* import { createWalletClient, custom } from 'viem'
Expand All @@ -45,11 +45,11 @@ export type WalletActionsEip5792<
* transport: custom(window.ethereum),
* }).extend(walletActionsEip5792())
*
* const { receipts, status } = await client.getCallsStatus({ id: '0xdeadbeef' })
* const { receipts, status } = await client.getCallsReceipt({ id: '0xdeadbeef' })
*/
getCallsStatus: (
parameters: GetCallsStatusParameters,
) => Promise<GetCallsStatusReturnType>
getCallsReceipt: (
parameters: GetCallsReceiptParameters,
) => Promise<GetCallsReceiptReturnType>
/**
* Extract capabilities that a connected wallet supports (e.g. paymasters, session keys, etc).
*
Expand Down Expand Up @@ -191,7 +191,7 @@ export function walletActionsEip5792() {
client: Client<transport, chain, account>,
): WalletActionsEip5792<chain, account> => {
return {
getCallsStatus: (parameters) => getCallsStatus(client, parameters),
getCallsReceipt: (parameters) => getCallsReceipt(client, parameters),
getCapabilities: () => getCapabilities(client),
sendCalls: (parameters) => sendCalls(client, parameters),
writeContracts: (parameters) => writeContracts(client, parameters),
Expand Down
10 changes: 5 additions & 5 deletions src/experimental/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ export {
sendCalls,
} from './actions/sendCalls.js'
export {
type GetCallsStatusErrorType,
type GetCallsStatusParameters,
type GetCallsStatusReturnType,
getCallsStatus,
} from './actions/getCallsStatus.js'
type GetCallsReceiptErrorType,
type GetCallsReceiptParameters,
type GetCallsReceiptReturnType,
getCallsReceipt,
} from './actions/getCallsReceipt.js'
export {
type WriteContractsErrorType,
type WriteContractsParameters,
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1001,8 +1001,8 @@ export type {
TestRpcSchema,
WalletCapabilities,
WalletCapabilitiesRecord,
WalletGetCallsStatusReceipt,
WalletGetCallsStatusReturnType,
WalletCallReceipt,
WalletGetCallsReceiptReturnType,
WalletSendCallsParameters,
WalletPermissionCaveat,
WalletPermission,
Expand Down
Loading

0 comments on commit 8416fd1

Please sign in to comment.