Skip to content

Commit

Permalink
Merge branch 'wevm:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
nikola-bozin-txfusion authored May 20, 2024
2 parents f16e19f + 438ecff commit 339431b
Show file tree
Hide file tree
Showing 121 changed files with 5,346 additions and 1,129 deletions.
5 changes: 5 additions & 0 deletions .changeset/friendly-tools-fry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"viem": patch
---

Fixed hanging `waitForTransactionReceipt`
3 changes: 1 addition & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ VITE_ACCOUNT_PRIVATE_KEY=
VITE_ANVIL_FORK_URL=
VITE_ANVIL_FORK_URL_OPTIMISM=
VITE_BATCH_JSON_RPC=false
VITE_BATCH_MULTICALL=false
VITE_NETWORK_TRANSPORT_MODE=http
VITE_BATCH_MULTICALL=false
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ node_modules
tsconfig*.tsbuildinfo
wagmi
**/trusted-setups/**/*.txt
.idea

# local env files
.env
Expand Down
Binary file modified bun.lockb
Binary file not shown.
26 changes: 26 additions & 0 deletions site/pages/docs/actions/public/estimateGas.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,32 @@ const gas = await publicClient.estimateGas({
})
```

### stateOverride (optional)

- **Type:** [`StateOverride`](/docs/glossary/types#stateoverride)

The state override set is an optional address-to-state mapping, where each entry specifies some state to be ephemerally overridden prior to executing the call.

```ts
const data = await publicClient.estimateGas({
account,
data: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
stateOverride: [ // [!code focus]
{ // [!code focus]
address: '0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC', // [!code focus]
balance: parseEther('1'), // [!code focus]
stateDiff: [ // [!code focus]
{ // [!code focus]
slot: '0x3ea2f1d0abf3fc66cf29eebb70cbd4e7fe762ef8a09bcc06c8edf641230afec0', // [!code focus]
value: '0x00000000000000000000000000000000000000000000000000000000000001a4', // [!code focus]
}, // [!code focus]
], // [!code focus]
} // [!code focus]
], // [!code focus]
})
```

## JSON-RPC Methods

[`eth_estimateGas`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_estimategas)
11 changes: 8 additions & 3 deletions site/pages/op-stack/actions/proveWithdrawal.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ Internally performs a contract write to the [`proveWithdrawalTransaction` functi
:::code-group

```ts [example.ts]
import { account, publicClientL2, walletClientL1 } from './config'
import { account, publicClientL1, publicClientL2, walletClientL1 } from './config'

const receipt = await getTransactionReceipt(publicClientL2, {
hash: '0xbbdd0957a82a057a76b5f093de251635ac4ddc6e2d0c4aa7fbf82d73e4e11039',
})

const [withdrawal] = getWithdrawals(receipt)
const output = await walletClientL1.getL2Output({
const output = await publicClientL1.getL2Output({
l2BlockNumber: receipt.blockNumber,
targetChain: publicClientL2.chain,
})
Expand All @@ -39,7 +39,12 @@ const hash = await walletClientL1.proveWithdrawal(args) // [!code hl]
import { createPublicClient, createWalletClient, custom, http } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'
import { mainnet, optimism } from 'viem/chains'
import { publicActionsL2, walletActionsL1 } from 'viem/op-stack'
import { publicActionsL1, publicActionsL2, walletActionsL1 } from 'viem/op-stack'

export const publicClientL1 = createPublicClient({
chain: optimism,
transport: http()
}).extend(publicActionsL1())

export const walletClientL1 = createWalletClient({
chain: mainnet,
Expand Down
198 changes: 198 additions & 0 deletions site/pages/zksync/actions/estimateFee.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
---
description: Returns an estimated Fee for requested transaction.
---

# estimateFee

Returns an estimated Fee for requested transaction.

## Usage

:::code-group

```ts [example.ts]
import { client } from './config'

const fee = await client.estimateFee({
account: '0x636A122e48079f750d44d13E5b39804227E1467e',
to: "0xa61464658AfeAf65CccaaFD3a512b69A83B77618",
value: 0n
});
```

```ts [config.ts]
import { createPublicClient, http } from 'viem'
import { zkSync } from 'viem/chains'
import { publicActionsL2 } from 'viem/zksync'

export const client = createPublicClient({
chain: zkSync,
transport: http(),
}).extend(publicActionsL2())
```
:::

## Returns

`Fee`

The fee values.

## Parameters

### account

- **Type:** `Account | Address`

The Account to send the transaction from.

Accepts a [JSON-RPC Account](/docs/clients/wallet#json-rpc-accounts) or [Local Account (Private Key, etc)](/docs/clients/wallet#local-accounts-private-key-mnemonic-etc).

```ts
const fee = await walletClient.estimateFee({
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266', // [!code focus]
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
value: 1000000000000000000n
})
```

### to

- **Type:** `0x${string}`

The transaction recipient or contract address.

```ts
const fee = await walletClient.estimateFee({
account,
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8', // [!code focus]
value: 1000000000000000000n,
nonce: 69
})
```

### data (optional)

- **Type:** `0x${string}`

A contract hashed method call with encoded args.

```ts
const fee = await walletClient.estimateFee({
data: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', // [!code focus]
account,
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
value: 1000000000000000000n
})
```

### gasPrice (optional)

- **Type:** `bigint`

The price (in wei) to pay per gas. Only applies to [Legacy Transactions](/docs/glossary/terms#legacy-transaction).

```ts
const fee = await walletClient.estimateFee({
account,
gasPrice: parseGwei('20'), // [!code focus]
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
value: 1000000000000000000n
})
```

### nonce (optional)

- **Type:** `number`

Unique number identifying this transaction.

```ts
const fee = await walletClient.estimateFee({
account,
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
value: 1000000000000000000n,
nonce: 69 // [!code focus]
})
```

### value (optional)

- **Type:** `bigint`

Value in wei sent with this transaction.

```ts
const fee = await walletClient.estimateFee({
account,
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
value: parseEther('1'), // [!code focus]
nonce: 69
})
```

### gasPerPubdata (optional)

- **Type:** `bigint`

The amount of gas for publishing one byte of data on Ethereum.

```ts
const fee = await walletClient.estimateFee({
account,
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
gasPerPubdata: 50000, // [!code focus]
nonce: 69,
value: 1000000000000000000n
})
```

### factoryDeps (optional)

- **Type:** `[0x${string}]`

Contains bytecode of the deployed contract.

```ts
const fee = await walletClient.estimateFee({
account,
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
factoryDeps: ['0xcde...'], // [!code focus]
nonce: 69,
value: 1000000000000000000n
})
```

### paymaster (optional)

- **Type:** `Account | Address`

Address of the paymaster account that will pay the fees. The `paymasterInput` field is required with this one.

```ts
const fee = await walletClient.estimateFee({
account,
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
paymaster: '0x4B5DF730c2e6b28E17013A1485E5d9BC41Efe021', // [!code focus]
paymasterInput: '0x8c5a...' // [!code focus]
nonce: 69,
value: 1000000000000000000n
})
```

### paymasterInput (optional)

- **Type:** `0x${string}`

Input data to the paymaster. The `paymaster` field is required with this one.

```ts
const fee = await walletClient.estimateFee({
account,
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
paymaster: '0x4B5DF730c2e6b28E17013A1485E5d9BC41Efe021', // [!code focus]
paymasterInput: '0x8c5a...' // [!code focus]
nonce: 69,
value: 1000000000000000000n
})
```
Loading

0 comments on commit 339431b

Please sign in to comment.