Skip to content
Discussion options

You must be logged in to vote

Hey @wew6d48g! UPD: See end of this post.

Down below I wrote examples of getting gas using the Oracle example and with substraction padding. Honestly, I'm confused about the formula myself lol. I hope someone will explain. You should also use RLP encoding for Tx.

package main

import (
	"context"
	"log"

	"github.com/ethereum/go-ethereum/common"
	"github.com/ethereum/go-ethereum/ethclient"
)

func getL1GasUsed(txBytes []byte) int {
	totalGas := 0
	for _, b := range txBytes {
		if b == 0 {
			totalGas += 4
		} else {
			totalGas += 16
		}
	}
	unsigned := totalGas + 188
	return unsigned + (68 * 16)
}

func main() {
	client, err := ethclient.Dial("https://rpc.ankr.com/optimism")
	if err != nil

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
3 replies
@wew6d48g
Comment options

@cryptosvinarnik
Comment options

@cryptosvinarnik
Comment options

Answer selected by wew6d48g
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
app-development discussion-metrics Used by Github Action to gather discussion metrics on the question and answer section.
2 participants