diff --git a/api/api.go b/api/api.go index 6eb97cfd..ced9f6cd 100644 --- a/api/api.go +++ b/api/api.go @@ -25,7 +25,6 @@ import ( ) const EthNamespace = "eth" -const defaultGasPrice = 8049999872 // TODO: Fetch these from flow-go/fvm/evm/emulator/config.go var ( @@ -211,7 +210,7 @@ func (s *BlockChainAPI) FeeHistory( // eth_gasPrice (returns the gas price) // GasPrice returns a suggestion for a gas price for legacy transactions. func (s *BlockChainAPI) GasPrice(ctx context.Context) (*hexutil.Big, error) { - return (*hexutil.Big)(big.NewInt(defaultGasPrice)), nil + return (*hexutil.Big)(s.config.GasPrice), nil } // eth_maxPriorityFeePerGas diff --git a/api/api_test.go b/api/api_test.go index 8a69d396..35ca246e 100644 --- a/api/api_test.go +++ b/api/api_test.go @@ -177,10 +177,17 @@ func TestBlockChainAPI(t *testing.T) { }) t.Run("GasPrice", func(t *testing.T) { + config := &api.Config{ + ChainID: api.FlowEVMTestnetChainID, + Coinbase: common.HexToAddress("0xf02c1c8e6114b1dbe8937a39260b5b0a374432bb"), + GasPrice: big.NewInt(5049999872), + } + blockchainAPI := api.NewBlockChainAPI(config, store, flowClient) + gasPrice, err := blockchainAPI.GasPrice(context.Background()) require.NoError(t, err) - assert.Equal(t, gasPrice, (*hexutil.Big)(big.NewInt(8049999872))) + assert.Equal(t, gasPrice, (*hexutil.Big)(big.NewInt(5049999872))) }) t.Run("MaxPriorityFeePerGas", func(t *testing.T) { diff --git a/api/config.go b/api/config.go index 73e5771c..8f7d7e3e 100644 --- a/api/config.go +++ b/api/config.go @@ -6,6 +6,8 @@ import ( "github.com/ethereum/go-ethereum/common" ) +var DefaultGasPrice = big.NewInt(8049999872) + // TODO(m-Peter) Add more config options, such as: // - host // - port @@ -15,4 +17,5 @@ import ( type Config struct { ChainID *big.Int Coinbase common.Address + GasPrice *big.Int } diff --git a/api/server_test.go b/api/server_test.go index 19c0af99..8836ab16 100644 --- a/api/server_test.go +++ b/api/server_test.go @@ -40,6 +40,7 @@ func TestServerJSONRPCOveHTTPHandler(t *testing.T) { config := &api.Config{ ChainID: api.FlowEVMTestnetChainID, Coinbase: common.HexToAddress("0xf02c1c8e6114b1dbe8937a39260b5b0a374432bb"), + GasPrice: api.DefaultGasPrice, } blockchainAPI := api.NewBlockChainAPI(config, store, mockFlowClient) supportedAPIs := api.SupportedAPIs(blockchainAPI) @@ -230,6 +231,7 @@ func TestServerJSONRPCOveWebSocketHandler(t *testing.T) { config := &api.Config{ ChainID: api.FlowEVMTestnetChainID, Coinbase: common.HexToAddress("0xf02c1c8e6114b1dbe8937a39260b5b0a374432bb"), + GasPrice: api.DefaultGasPrice, } flowClient, err := api.NewFlowClient(grpc.EmulatorHost) require.NoError(t, err) diff --git a/cmd/server/main.go b/cmd/server/main.go index 6b105995..9fc90183 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -4,6 +4,7 @@ import ( "context" "flag" "fmt" + "math/big" "runtime" "time" @@ -33,13 +34,17 @@ var evmEventTypes = []string{ func main() { var network, coinbase string + var gasPrice int64 flag.StringVar(&network, "network", "testnet", "network to connect the gateway to") flag.StringVar(&coinbase, "coinbase", coinbaseAddr, "coinbase address to use for fee collection") + flag.Int64Var(&gasPrice, "gasPrice", api.DefaultGasPrice.Int64(), "gas price for transactions") flag.Parse() - config := &api.Config{} - config.Coinbase = common.HexToAddress(coinbase) + config := &api.Config{ + Coinbase: common.HexToAddress(coinbase), + GasPrice: big.NewInt(gasPrice), + } if network == "testnet" { config.ChainID = api.FlowEVMTestnetChainID } else if network == "mainnet" {