Skip to content

Commit

Permalink
Merge pull request #103 from bout3fiddy/fix/catch_staticfee_nw_keyerror
Browse files Browse the repository at this point in the history
fix: non-eip-1559 transactions
  • Loading branch information
charles-cooper authored Oct 25, 2023
2 parents 7fcca39 + c68148c commit eb39713
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions boa/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def get_gas_price(self) -> int:
return self._gas_price
return to_int(self._rpc.fetch("eth_gasPrice", []))

def get_fee_info(self) -> tuple[str, str, str, str]:
def get_eip1559_fee(self) -> tuple[str, str, str, str]:
# returns: base_fee, max_fee, max_priority_fee
reqs = [
("eth_getBlockByNumber", ["pending", False]),
Expand All @@ -175,6 +175,9 @@ def get_fee_info(self) -> tuple[str, str, str, str]:
max_fee = to_hex(base_fee_estimate + to_int(max_priority_fee))
return to_hex(base_fee_estimate), max_priority_fee, max_fee, chain_id

def get_static_fee(self) -> tuple[str, str]:
return self._rpc.fetch_multi([("eth_gasPrice", []), ("eth_chainId", [])])

def _check_sender(self, address):
if address is None:
raise ValueError("No sender!")
Expand Down Expand Up @@ -367,12 +370,14 @@ def _send_txn(self, from_, to=None, gas=None, value=None, data=None):

try:
# eip-1559 txn
base_fee, max_priority_fee, max_fee, chain_id = self.get_fee_info()
(base_fee, max_priority_fee, max_fee, chain_id) = self.get_eip1559_fee()
tx_data["maxPriorityFeePerGas"] = max_priority_fee
tx_data["maxFeePerGas"] = max_fee
tx_data["chainId"] = chain_id
except RPCError:
tx_data["gasPrice"] = to_hex(self.get_gas_price())
except (RPCError, KeyError):
gas_price, chain_id = self.get_static_fee()
tx_data["gasPrice"] = gas_price
tx_data["chainId"] = chain_id

tx_data["nonce"] = self._get_nonce(from_)

Expand Down

0 comments on commit eb39713

Please sign in to comment.