Skip to content

Commit

Permalink
Ethereum: small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
welldan97 committed Jul 26, 2024
1 parent b1ac024 commit 832bc5a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 25 deletions.
12 changes: 6 additions & 6 deletions book/build-your-staking-dapp/ethereum/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ import { useWalletClient } from 'wagmi'

const { data: walletClient } = useWalletClient()

// Prepare the transaction and estimate the gas fees
const request = await walletClient.prepareTransactionRequest(tx)

// Sign and send the transaction
Expand All @@ -207,12 +208,13 @@ import { BrowserProvider } from 'ethers'
const provider = new BrowserProvider(window.ethereum)
const signer = await provider.getSigner()

// Estimate gas fees
const feeData = await provider.getFeeData()
const gasLimit = await provider.estimateGas(stakeTx2)
const gasLimit = await provider.estimateGas(tx)

// Sign and send the transaction
const { hash } = await signer.sendTransaction({
...stakeTx2,
...tx,
// Optional: Set the gas limit and fees
gasLimit: gasLimit,
maxFeePerGas: feeData.maxFeePerGas,
Expand Down Expand Up @@ -246,10 +248,8 @@ const { signedTx } = await staker.sign({
signer,
signerAddress: '0x70aEe8a9099ebADB186C2D530F72CF5dC7FE6B30',
tx,
fees: {
baseFeeMultiplier: 2, // Optional: Multiplier for the base fee per gas
defaultPriorityFee: '2' // Optional: Override for the maxPriorityFeePerGas
}
baseFeeMultiplier: 2, // Optional: Multiplier for the base fee per gas
defaultPriorityFee: '2' // Optional: Override for the maxPriorityFeePerGas
})
```

Expand Down
5 changes: 2 additions & 3 deletions book/docs/classes/ethereum_src.EthereumStaker.md
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,8 @@ Signs a transaction using the provided signer.
| `params.signer` | `Signer` | A signer instance. |
| `params.signerAddress` | \`0x$\{string}\` | The address of the signer |
| `params.tx` | [`Transaction`](../interfaces/ethereum_src.Transaction.md) | The transaction to sign |
| `params.fees?` | `Object` | (Optional) The fees to include in the transaction |
| `params.fees.baseFeeMultiplier?` | `number` | - |
| `params.fees.defaultPriorityFee?` | `string` | - |
| `params.baseFeeMultiplier?` | `number` | (Optional) The multiplier for fees, which is used to manage fee fluctuations, is applied to the base fee per gas from the latest block to determine the final `maxFeePerGas`. The default value is 1.2. |
| `params.defaultPriorityFee?` | `string` | (Optional) This overrides the the `maxPriorityFeePerGas` estimated by the RPC. |

### Returns

Expand Down
34 changes: 18 additions & 16 deletions packages/ethereum/src/staker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,31 +418,33 @@ export class EthereumStaker {
* @param params.signer - A signer instance.
* @param params.signerAddress - The address of the signer
* @param params.tx - The transaction to sign
* @param params.fees - (Optional) The fees to include in the transaction
* @param params.fees.baseFeeMultiplier - (Optional) The multiplier for fees, which is used to manage fee fluctuations, is applied to the base fee per gas from the latest block to determine the final `maxFeePerGas`. The default value is 1.2.
* @param params.fees.defaultPriorityFee - (Optional) This overrides the the `maxPriorityFeePerGas` estimated by the RPC.
* @param params.baseFeeMultiplier - (Optional) The multiplier for fees, which is used to manage fee fluctuations, is applied to the base fee per gas from the latest block to determine the final `maxFeePerGas`. The default value is 1.2.
* @param params.defaultPriorityFee - (Optional) This overrides the the `maxPriorityFeePerGas` estimated by the RPC.
*
* @returns A promise that resolves to an object containing the signed transaction.
*/
async sign (params: {
signer: Signer
signerAddress: Hex
tx: Transaction
fees?: {
baseFeeMultiplier?: number
defaultPriorityFee?: string
}
baseFeeMultiplier?: number
defaultPriorityFee?: string
}): Promise<{ signedTx: Hex }> {
const { signer, signerAddress, tx: tx, fees } = params
const { signer, signerAddress, tx: tx, baseFeeMultiplier, defaultPriorityFee } = params

const baseChain = this.connector.chain

const baseFees = baseChain.fees ?? {}
const fees = {
...baseFees,
baseFeeMultiplier: baseFeeMultiplier ?? baseFees.baseFeeMultiplier,
defaultPriorityFee:
defaultPriorityFee === undefined ? baseFees.defaultPriorityFee : this.parseEther(defaultPriorityFee)
}

const chain: Chain = {
...this.connector.chain,
fees: fees
? {
baseFeeMultiplier: fees.baseFeeMultiplier,
defaultPriorityFee:
fees.defaultPriorityFee === undefined ? undefined : this.parseEther(fees.defaultPriorityFee)
}
: undefined
...baseChain,
fees
}
const client = createWalletClient({
chain,
Expand Down

0 comments on commit 832bc5a

Please sign in to comment.