Commit 64bc3500 authored by Ori Pomerantz's avatar Ori Pomerantz Committed by kf

feat(sdk): Make it easier to get transaction estimates

Description:

Instead of adding all the transaction fields, have serialize only add the fields we need.

This lets developers use the code pattern:

```js
const txReq = await greeter.populateTransaction.setGreeting(greeting)
const tx = await signer.populateTransaction(txReq)
provider.estimateL1Gas(tx)
```

Instead of the more error prone:

```js
const txReq = await greeter.populateTransaction.setGreeting(greeting)
const tx = await signer.populateTransaction(txReq)
delete tx.from
delete tx.chainId
provider.estimateL1Gas(tx)
```
parent 35b65c96
...@@ -48,7 +48,11 @@ export const estimateL1Gas = async ( ...@@ -48,7 +48,11 @@ export const estimateL1Gas = async (
const gpo = connectGasPriceOracle(l2Provider) const gpo = connectGasPriceOracle(l2Provider)
return gpo.getL1GasUsed( return gpo.getL1GasUsed(
serialize({ serialize({
...tx, data: tx.data,
to: tx.to,
gasPrice: tx.gasPrice,
type: tx.type,
gasLimit: tx.gasLimit,
nonce: toNumber(tx.nonce as NumberLike), nonce: toNumber(tx.nonce as NumberLike),
}) })
) )
...@@ -68,7 +72,11 @@ export const estimateL1GasCost = async ( ...@@ -68,7 +72,11 @@ export const estimateL1GasCost = async (
const gpo = connectGasPriceOracle(l2Provider) const gpo = connectGasPriceOracle(l2Provider)
return gpo.getL1Fee( return gpo.getL1Fee(
serialize({ serialize({
...tx, data: tx.data,
to: tx.to,
gasPrice: tx.gasPrice,
type: tx.type,
gasLimit: tx.gasLimit,
nonce: toNumber(tx.nonce as NumberLike), nonce: toNumber(tx.nonce as NumberLike),
}) })
) )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment