-
-
Save rafaelescrich/fa3a28a9f531cbfc3feb4ed0b132340e to your computer and use it in GitHub Desktop.
Go estimate ethereum transaction gas limit and add 30% percent
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "context" | |
| "fmt" | |
| "log" | |
| ethereum "github.com/ethereum/go-ethereum" | |
| "github.com/ethereum/go-ethereum/common" | |
| "github.com/ethereum/go-ethereum/ethclient" | |
| ) | |
| func main() { | |
| client, err := ethclient.Dial("https://rinkeby.infura.io") | |
| if err != nil { | |
| log.Fatal(err) | |
| } | |
| tokenAddress := common.HexToAddress("0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1") | |
| estimatedGas, err := client.EstimateGas(context.Background(), ethereum.CallMsg{ | |
| To: &tokenAddress, | |
| Data: []byte{0}, | |
| }) | |
| if err != nil { | |
| log.Fatal(err) | |
| } | |
| gasLimit := int(float64(estimatedGas) * 1.30) | |
| fmt.Println(gasLimit) // 27305 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment