|
6 | 6 | import dotenv |
7 | 7 |
|
8 | 8 | from pyinjective.async_client import AsyncClient |
9 | | -from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE |
| 9 | +from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT |
10 | 10 | from pyinjective.core.network import Network |
11 | 11 | from pyinjective.orderhash import OrderHashManager |
12 | 12 | from pyinjective.transaction import Transaction |
@@ -111,7 +111,11 @@ async def main() -> None: |
111 | 111 | .with_account_num(client.get_number()) |
112 | 112 | .with_chain_id(network.chain_id) |
113 | 113 | ) |
114 | | - gas_price = GAS_PRICE |
| 114 | + |
| 115 | + gas_price = await client.current_chain_gas_price() |
| 116 | + # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted |
| 117 | + gas_price = int(gas_price * 1.1) |
| 118 | + |
115 | 119 | base_gas = 85000 |
116 | 120 | gas_limit = base_gas + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation |
117 | 121 | gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0") |
@@ -148,7 +152,11 @@ async def main() -> None: |
148 | 152 | .with_account_num(client.get_number()) |
149 | 153 | .with_chain_id(network.chain_id) |
150 | 154 | ) |
151 | | - gas_price = GAS_PRICE |
| 155 | + |
| 156 | + gas_price = await client.current_chain_gas_price() |
| 157 | + # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted |
| 158 | + gas_price = int(gas_price * 1.1) |
| 159 | + |
152 | 160 | base_gas = 85000 |
153 | 161 | gas_limit = base_gas + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation |
154 | 162 | gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0") |
@@ -240,7 +248,11 @@ async def main() -> None: |
240 | 248 | .with_account_num(client.get_number()) |
241 | 249 | .with_chain_id(network.chain_id) |
242 | 250 | ) |
243 | | - gas_price = GAS_PRICE |
| 251 | + |
| 252 | + gas_price = await client.current_chain_gas_price() |
| 253 | + # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted |
| 254 | + gas_price = int(gas_price * 1.1) |
| 255 | + |
244 | 256 | base_gas = 85000 |
245 | 257 | gas_limit = base_gas + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation |
246 | 258 | gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0") |
|
0 commit comments