0.0.1 • Published 5 months ago

@morph-l2/core-utils v0.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
5 months ago

@morph-l2/core-utils

What is this?

@morph-l2/core-utils contains the Morph Virtual Machine core utilities.

Getting started

Building and usage

After cloning and switching to the repository, install dependencies:

$ yarn

Use the following commands to build, use, test, and lint:

$ yarn build
$ yarn test
$ yarn lint

L2 Fees

TxGasLimit can be used to encode and decode the L2 Gas Limit locally.

import { TxGasLimit } from '@morph-l2/core-utils'
import { JsonRpcProvider } from 'ethers'

const L2Provider = new JsonRpcProvider('http://127.0.0.1:9545')
const L1Provider = new JsonRpcProvider('http://127.0.0.1:8545')

const l2GasLimit = await L2Provider.send('eth_estimateExecutionGas', [tx])
const l1GasPrice = await L1Provider.getGasPrice()

const encoded = TxGasLimit.encode({
  data: '0x',
  l1GasPrice,
  l2GasLimit,
  l2GasPrice: 10000000,
})

const decoded = TxGasLimit.decode(encoded)
assert(decoded.eq(gasLimit))

const estimate = await L2Provider.estimateGas()
assert(estimate.eq(encoded))