github.com/ethereum-optimism/optimism@v1.7.2/packages/sdk/src/interfaces/l2-provider.ts (about) 1 import { 2 Provider, 3 TransactionRequest, 4 TransactionResponse, 5 Block, 6 BlockWithTransactions, 7 } from '@ethersproject/abstract-provider' 8 import { BigNumber } from 'ethers' 9 10 /** 11 * JSON transaction representation when returned by L2Geth nodes. This is simply an extension to 12 * the standard transaction response type. You do NOT need to use this type unless you care about 13 * having typed access to L2-specific fields. 14 */ 15 export interface L2Transaction extends TransactionResponse { 16 l1BlockNumber: number 17 l1TxOrigin: string 18 queueOrigin: string 19 rawTransaction: string 20 } 21 22 /** 23 * JSON block representation when returned by L2Geth nodes. Just a normal block but with 24 * an added stateRoot field. 25 */ 26 export interface L2Block extends Block { 27 stateRoot: string 28 } 29 30 /** 31 * JSON block representation when returned by L2Geth nodes. Just a normal block but with 32 * L2Transaction objects instead of the standard transaction response object. 33 */ 34 export interface L2BlockWithTransactions extends BlockWithTransactions { 35 stateRoot: string 36 transactions: [L2Transaction] 37 } 38 39 /** 40 * Represents an extended version of an normal ethers Provider that returns additional L2 info and 41 * has special functions for L2-specific interactions. 42 */ 43 export type L2Provider<TProvider extends Provider> = TProvider & { 44 /** 45 * Gets the current L1 (data) gas price. 46 * 47 * @returns Current L1 data gas price in wei. 48 */ 49 getL1GasPrice(): Promise<BigNumber> 50 51 /** 52 * Estimates the L1 (data) gas required for a transaction. 53 * 54 * @param tx Transaction to estimate L1 gas for. 55 * @returns Estimated L1 gas. 56 */ 57 estimateL1Gas(tx: TransactionRequest): Promise<BigNumber> 58 59 /** 60 * Estimates the L1 (data) gas cost for a transaction in wei by multiplying the estimated L1 gas 61 * cost by the current L1 gas price. 62 * 63 * @param tx Transaction to estimate L1 gas cost for. 64 * @returns Estimated L1 gas cost. 65 */ 66 estimateL1GasCost(tx: TransactionRequest): Promise<BigNumber> 67 68 /** 69 * Estimates the L2 (execution) gas cost for a transaction in wei by multiplying the estimated L1 70 * gas cost by the current L2 gas price. This is a simple multiplication of the result of 71 * getGasPrice and estimateGas for the given transaction request. 72 * 73 * @param tx Transaction to estimate L2 gas cost for. 74 * @returns Estimated L2 gas cost. 75 */ 76 estimateL2GasCost(tx: TransactionRequest): Promise<BigNumber> 77 78 /** 79 * Estimates the total gas cost for a transaction in wei by adding the estimated the L1 gas cost 80 * and the estimated L2 gas cost. 81 * 82 * @param tx Transaction to estimate total gas cost for. 83 * @returns Estimated total gas cost. 84 */ 85 estimateTotalGasCost(tx: TransactionRequest): Promise<BigNumber> 86 87 /** 88 * Internal property to determine if a provider is a L2Provider 89 * You are likely looking for the isL2Provider function 90 */ 91 _isL2Provider: true 92 }