From 63575acbbea59f92c40a7332926b55a0fe91197d Mon Sep 17 00:00:00 2001
From: Abel Armoa <30988000+aarmoa@users.noreply.github.com>
Date: Mon, 7 Apr 2025 17:01:37 -0300
Subject: [PATCH 1/2] feat: added a documentation page for the new txfees
module
---
source/includes/_chainexchange.md | 9 ++++
source/includes/_txfees.md | 42 +++++++++++++++++++
source/index.html.md | 1 +
.../exchange/queryMarketBalanceResponse.json | 2 +-
.../json_tables/chain/txfees/eipBaseFee.json | 3 ++
.../chain/txfees/queryEipBaseFeeResponse.json | 3 ++
6 files changed, 59 insertions(+), 1 deletion(-)
create mode 100644 source/includes/_txfees.md
create mode 100644 source/json_tables/chain/txfees/eipBaseFee.json
create mode 100644 source/json_tables/chain/txfees/queryEipBaseFeeResponse.json
diff --git a/source/includes/_chainexchange.md b/source/includes/_chainexchange.md
index 3d41e195..5f643794 100644
--- a/source/includes/_chainexchange.md
+++ b/source/includes/_chainexchange.md
@@ -4605,6 +4605,15 @@ func main() {
| Parameter | Type | Description |
|---|
| balance | Decimal | The current market balance |
+
+
+**MarketBalance**
+
+
+| Parameter | Type | Description |
|---|
| market_id | String | ID of the market |
+| balance | Decimal | Current market balance |
+
+
## MarketBalances
diff --git a/source/includes/_txfees.md b/source/includes/_txfees.md
new file mode 100644
index 00000000..0955a4a1
--- /dev/null
+++ b/source/includes/_txfees.md
@@ -0,0 +1,42 @@
+# - Chain TXFees
+
+The txfees module for Injective provides the required functionality to support fee market as per EIP-1559.
+
+
+## GetEipBaseFee
+
+Retrieves the current chain gas price
+
+**IP rate limit group:** `chain`
+
+### Request Parameters
+> Request Example:
+
+
+
+
+
+
+
+No parameters
+
+### Response Parameters
+> Response Example:
+
+``` json
+{
+ "baseFee": {
+ "baseFee": "160000000000000000000000000"
+ }
+}
+```
+
+
+
+
+
+
+**EipBaseFee**
+
+
+
diff --git a/source/index.html.md b/source/index.html.md
index f8ff6f6d..1da4eb5d 100644
--- a/source/index.html.md
+++ b/source/index.html.md
@@ -46,6 +46,7 @@ includes:
- staking
- tendermint
- tokenfactory
+ - txfees
- wasm
- wasmx
- historicalqueries
diff --git a/source/json_tables/chain/exchange/queryMarketBalanceResponse.json b/source/json_tables/chain/exchange/queryMarketBalanceResponse.json
index 59fb0505..70926953 100644
--- a/source/json_tables/chain/exchange/queryMarketBalanceResponse.json
+++ b/source/json_tables/chain/exchange/queryMarketBalanceResponse.json
@@ -1,3 +1,3 @@
[
- {"Parameter": "balance", "Type": "Decimal", "Description": "The current market balance"}
+ {"Parameter": "balance", "Type": "MarketBalance", "Description": "The current market balance"}
]
\ No newline at end of file
diff --git a/source/json_tables/chain/txfees/eipBaseFee.json b/source/json_tables/chain/txfees/eipBaseFee.json
new file mode 100644
index 00000000..dcea7c04
--- /dev/null
+++ b/source/json_tables/chain/txfees/eipBaseFee.json
@@ -0,0 +1,3 @@
+[
+ {"Parameter": "base_fee", "Type": "Decimal", "Description": "The current chain gas price"}
+]
\ No newline at end of file
diff --git a/source/json_tables/chain/txfees/queryEipBaseFeeResponse.json b/source/json_tables/chain/txfees/queryEipBaseFeeResponse.json
new file mode 100644
index 00000000..945d01b3
--- /dev/null
+++ b/source/json_tables/chain/txfees/queryEipBaseFeeResponse.json
@@ -0,0 +1,3 @@
+[
+ {"Parameter": "base_fee", "Type": "EipBaseFee", "Description": "The current chain gas price"}
+]
\ No newline at end of file
From 782546ca0e2359847618ef6a1434113f065afa4e Mon Sep 17 00:00:00 2001
From: Abel Armoa <30988000+aarmoa@users.noreply.github.com>
Date: Sun, 20 Apr 2025 23:10:42 -0300
Subject: [PATCH 2/2] feat: updated changelog. Updated documentation about gas
heuristics estimator in Python SDK
---
source/includes/_account.md | 117 ++++++++----
source/includes/_auction.md | 26 ++-
source/includes/_authz.md | 68 +++++--
source/includes/_bank.md | 46 +++--
source/includes/_binaryoptions.md | 59 +++++--
source/includes/_broadcaster.md | 129 +++++++++++---
source/includes/_chainexchange.md | 88 +++++++--
source/includes/_changelog.md | 6 +
source/includes/_derivatives.md | 275 +++++++++++++++++++++++------
source/includes/_derivativesrpc.md | 2 +-
source/includes/_ibctransfer.md | 26 ++-
source/includes/_insurance.md | 21 ++-
source/includes/_oracle.md | 26 ++-
source/includes/_permissions.md | 134 +++++++++++---
source/includes/_portfoliorpc.md | 6 +-
source/includes/_spot.md | 165 +++++++++++++----
source/includes/_staking.md | 133 +++++++++++---
source/includes/_tokenfactory.md | 173 +++++++++++++++---
source/includes/_txfees.md | 95 +++++++++-
source/includes/_wasm.md | 7 +-
source/includes/_wasmx.md | 22 ++-
21 files changed, 1307 insertions(+), 317 deletions(-)
diff --git a/source/includes/_account.md b/source/includes/_account.md
index cd8cb328..c8c21c4c 100644
--- a/source/includes/_account.md
+++ b/source/includes/_account.md
@@ -20,7 +20,7 @@ import dotenv
from grpc import RpcError
from pyinjective.async_client import AsyncClient
-from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
+from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT
from pyinjective.core.network import Network
from pyinjective.transaction import Transaction
from pyinjective.wallet import PrivateKey
@@ -70,7 +70,10 @@ async def main() -> None:
return
# build tx
- gas_price = GAS_PRICE
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+
gas_limit = int(sim_res["gasInfo"]["gasUsed"]) + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
fee = [
@@ -107,16 +110,12 @@ import (
"time"
"cosmossdk.io/math"
-
- "github.com/InjectiveLabs/sdk-go/client"
-
- "github.com/InjectiveLabs/sdk-go/client/common"
-
+ rpchttp "github.com/cometbft/cometbft/rpc/client/http"
sdktypes "github.com/cosmos/cosmos-sdk/types"
exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types"
chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
- rpchttp "github.com/cometbft/cometbft/rpc/client/http"
+ "github.com/InjectiveLabs/sdk-go/client/common"
)
func main() {
@@ -153,13 +152,17 @@ func main() {
chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
- common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)
if err != nil {
panic(err)
}
+ gasPrice := chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
+
msg := &exchangetypes.MsgDeposit{
Sender: senderAddress.String(),
SubaccountId: "0xaf79152ac5df276d9a8e1e2e22822f9713474902000000000000000000000000",
@@ -185,6 +188,11 @@ func main() {
}
fmt.Println("gas fee:", gasFee, "INJ")
+
+ gasPrice = chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
}
```
@@ -312,7 +320,7 @@ import dotenv
from grpc import RpcError
from pyinjective.async_client import AsyncClient
-from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
+from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT
from pyinjective.core.network import Network
from pyinjective.transaction import Transaction
from pyinjective.wallet import PrivateKey
@@ -360,7 +368,10 @@ async def main() -> None:
return
# build tx
- gas_price = GAS_PRICE
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+
gas_limit = int(sim_res["gasInfo"]["gasUsed"]) + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
fee = [
@@ -398,7 +409,6 @@ import (
"cosmossdk.io/math"
- "github.com/InjectiveLabs/sdk-go/client"
"github.com/InjectiveLabs/sdk-go/client/common"
exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types"
@@ -443,13 +453,17 @@ func main() {
chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
- common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)
if err != nil {
panic(err)
}
+ gasPrice := chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
+
msg := &exchangetypes.MsgWithdraw{
Sender: senderAddress.String(),
SubaccountId: "0xaf79152ac5df276d9a8e1e2e22822f9713474902000000000000000000000000",
@@ -475,6 +489,11 @@ func main() {
}
fmt.Println("gas fee:", gasFee, "INJ")
+
+ gasPrice = chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
}
```
@@ -603,7 +622,7 @@ import dotenv
from grpc import RpcError
from pyinjective.async_client import AsyncClient
-from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
+from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT
from pyinjective.core.network import Network
from pyinjective.transaction import Transaction
from pyinjective.wallet import PrivateKey
@@ -658,7 +677,10 @@ async def main() -> None:
return
# build tx
- gas_price = GAS_PRICE
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+
gas_limit = int(sim_res["gasInfo"]["gasUsed"]) + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
fee = [
@@ -695,14 +717,12 @@ import (
"time"
"cosmossdk.io/math"
-
- "github.com/InjectiveLabs/sdk-go/client"
- "github.com/InjectiveLabs/sdk-go/client/common"
+ rpchttp "github.com/cometbft/cometbft/rpc/client/http"
+ sdktypes "github.com/cosmos/cosmos-sdk/types"
exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types"
chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
- rpchttp "github.com/cometbft/cometbft/rpc/client/http"
- sdktypes "github.com/cosmos/cosmos-sdk/types"
+ "github.com/InjectiveLabs/sdk-go/client/common"
)
func main() {
@@ -741,13 +761,17 @@ func main() {
chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
- common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)
if err != nil {
panic(err)
}
+ gasPrice := chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
+
msg := &exchangetypes.MsgSubaccountTransfer{
Sender: senderAddress.String(),
SourceSubaccountId: "0xaf79152ac5df276d9a8e1e2e22822f9713474902000000000000000000000000",
@@ -774,6 +798,11 @@ func main() {
}
fmt.Println("gas fee:", gasFee, "INJ")
+
+ gasPrice = chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
}
```
@@ -903,7 +932,7 @@ import dotenv
from grpc import RpcError
from pyinjective.async_client import AsyncClient
-from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
+from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT
from pyinjective.core.network import Network
from pyinjective.transaction import Transaction
from pyinjective.wallet import PrivateKey
@@ -958,7 +987,10 @@ async def main() -> None:
return
# build tx
- gas_price = GAS_PRICE
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+
gas_limit = int(sim_res["gasInfo"]["gasUsed"]) + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
fee = [
@@ -995,14 +1027,12 @@ import (
"time"
"cosmossdk.io/math"
-
- "github.com/InjectiveLabs/sdk-go/client"
- "github.com/InjectiveLabs/sdk-go/client/common"
+ rpchttp "github.com/cometbft/cometbft/rpc/client/http"
+ sdktypes "github.com/cosmos/cosmos-sdk/types"
exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types"
chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
- rpchttp "github.com/cometbft/cometbft/rpc/client/http"
- sdktypes "github.com/cosmos/cosmos-sdk/types"
+ "github.com/InjectiveLabs/sdk-go/client/common"
)
func main() {
@@ -1041,13 +1071,17 @@ func main() {
chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
- common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)
if err != nil {
panic(err)
}
+ gasPrice := chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
+
msg := &exchangetypes.MsgExternalTransfer{
Sender: senderAddress.String(),
SourceSubaccountId: "0xaf79152ac5df276d9a8e1e2e22822f9713474902000000000000000000000000",
@@ -1074,6 +1108,11 @@ func main() {
}
fmt.Println("gas fee:", gasFee, "INJ")
+
+ gasPrice = chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
}
```
@@ -1203,7 +1242,7 @@ import requests
from grpc import RpcError
from pyinjective.async_client import AsyncClient
-from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
+from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT
from pyinjective.core.network import Network
from pyinjective.transaction import Transaction
from pyinjective.wallet import PrivateKey
@@ -1263,7 +1302,10 @@ async def main() -> None:
return
# build tx
- gas_price = GAS_PRICE
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+
gas_limit = int(sim_res["gasInfo"]["gasUsed"]) + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
fee = [
@@ -1300,8 +1342,6 @@ import (
"time"
"cosmossdk.io/math"
-
- "github.com/InjectiveLabs/sdk-go/client"
"github.com/InjectiveLabs/sdk-go/client/common"
peggytypes "github.com/InjectiveLabs/sdk-go/chain/peggy/types"
@@ -1346,13 +1386,17 @@ func main() {
chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
- common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)
if err != nil {
panic(err)
}
+ gasPrice := chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
+
ethDest := "0xaf79152ac5df276d9a8e1e2e22822f9713474902"
amount := sdktypes.Coin{
@@ -1386,6 +1430,11 @@ func main() {
}
fmt.Println("gas fee:", gasFee, "INJ")
+
+ gasPrice = chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
}
```
diff --git a/source/includes/_auction.md b/source/includes/_auction.md
index 8f48b964..030dec50 100644
--- a/source/includes/_auction.md
+++ b/source/includes/_auction.md
@@ -19,7 +19,7 @@ import dotenv
from grpc import RpcError
from pyinjective.async_client import AsyncClient
-from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
+from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT
from pyinjective.core.network import Network
from pyinjective.transaction import Transaction
from pyinjective.wallet import PrivateKey
@@ -66,7 +66,10 @@ async def main() -> None:
return
# build tx
- gas_price = GAS_PRICE
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+
gas_limit = int(sim_res["gasInfo"]["gasUsed"]) + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
fee = [
@@ -103,14 +106,12 @@ import (
"time"
"cosmossdk.io/math"
-
- "github.com/InjectiveLabs/sdk-go/client"
- "github.com/InjectiveLabs/sdk-go/client/common"
+ rpchttp "github.com/cometbft/cometbft/rpc/client/http"
+ sdktypes "github.com/cosmos/cosmos-sdk/types"
auctiontypes "github.com/InjectiveLabs/sdk-go/chain/auction/types"
chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
- rpchttp "github.com/cometbft/cometbft/rpc/client/http"
- sdktypes "github.com/cosmos/cosmos-sdk/types"
+ "github.com/InjectiveLabs/sdk-go/client/common"
)
func main() {
@@ -149,13 +150,17 @@ func main() {
chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
- common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)
if err != nil {
panic(err)
}
+ gasPrice := chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
+
round := uint64(9355)
bidAmount := sdktypes.Coin{
Denom: "inj", Amount: math.NewInt(1000000000000000000), // 1 INJ
@@ -184,6 +189,11 @@ func main() {
}
fmt.Println("gas fee:", gasFee, "INJ")
+
+ gasPrice = chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
}
```
diff --git a/source/includes/_authz.md b/source/includes/_authz.md
index abb36e01..9be4710c 100644
--- a/source/includes/_authz.md
+++ b/source/includes/_authz.md
@@ -21,7 +21,7 @@ import dotenv
from grpc import RpcError
from pyinjective.async_client import AsyncClient
-from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
+from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT
from pyinjective.core.network import Network
from pyinjective.transaction import Transaction
from pyinjective.wallet import PrivateKey
@@ -88,7 +88,10 @@ async def main() -> None:
return
# build tx
- gas_price = GAS_PRICE
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+
gas_limit = int(sim_res["gasInfo"]["gasUsed"]) + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
fee = [
@@ -124,12 +127,10 @@ import (
"os"
"time"
- "github.com/InjectiveLabs/sdk-go/client"
-
- "github.com/InjectiveLabs/sdk-go/client/common"
+ rpchttp "github.com/cometbft/cometbft/rpc/client/http"
chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
- rpchttp "github.com/cometbft/cometbft/rpc/client/http"
+ "github.com/InjectiveLabs/sdk-go/client/common"
)
func main() {
@@ -168,13 +169,17 @@ func main() {
chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
- common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)
if err != nil {
panic(err)
}
+ gasPrice := chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
+
granter := senderAddress.String()
grantee := "inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r"
expireIn := time.Now().AddDate(1, 0, 0) // years months days
@@ -210,6 +215,11 @@ func main() {
}
fmt.Println("gas fee:", gasFee, "INJ")
+
+ gasPrice = chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
}
```
@@ -355,7 +365,7 @@ import dotenv
from grpc import RpcError
from pyinjective.async_client import AsyncClient
-from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
+from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT
from pyinjective.core.network import Network
from pyinjective.transaction import Transaction
from pyinjective.wallet import Address, PrivateKey
@@ -427,7 +437,10 @@ async def main() -> None:
print(unpacked_msg_res)
# build tx
- gas_price = GAS_PRICE
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+
gas_limit = int(sim_res["gasInfo"]["gasUsed"]) + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
fee = [
@@ -471,7 +484,6 @@ import (
"github.com/shopspring/decimal"
exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types"
- "github.com/InjectiveLabs/sdk-go/client"
chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
"github.com/InjectiveLabs/sdk-go/client/common"
)
@@ -524,7 +536,6 @@ func main() {
clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient)
txFactory := chainclient.NewTxFactory(clientCtx)
- txFactory = txFactory.WithGasPrices(client.DefaultGasPriceWithDenom)
chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
@@ -535,6 +546,11 @@ func main() {
panic(err)
}
+ gasPrice := chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
+
ctx := context.Background()
marketsAssistant, err := chainclient.NewMarketsAssistant(ctx, chainClient)
if err != nil {
@@ -594,6 +610,11 @@ func main() {
}
fmt.Println("gas fee:", gasFee, "INJ")
+
+ gasPrice = chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
}
```
@@ -716,7 +737,7 @@ import dotenv
from grpc import RpcError
from pyinjective.async_client import AsyncClient
-from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
+from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT
from pyinjective.core.network import Network
from pyinjective.transaction import Transaction
from pyinjective.wallet import PrivateKey
@@ -768,7 +789,10 @@ async def main() -> None:
return
# build tx
- gas_price = GAS_PRICE
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+
gas_limit = int(sim_res["gasInfo"]["gasUsed"]) + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
fee = [
@@ -804,12 +828,11 @@ import (
"os"
"time"
- "github.com/InjectiveLabs/sdk-go/client"
- "github.com/InjectiveLabs/sdk-go/client/common"
-
- chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
rpchttp "github.com/cometbft/cometbft/rpc/client/http"
authztypes "github.com/cosmos/cosmos-sdk/x/authz"
+
+ chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
+ "github.com/InjectiveLabs/sdk-go/client/common"
)
func main() {
@@ -848,13 +871,17 @@ func main() {
chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
- common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)
if err != nil {
panic(err)
}
+ gasPrice := chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
+
grantee := "inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r"
msgType := "/injective.exchange.v1beta1.MsgCreateSpotLimitOrder"
@@ -881,6 +908,11 @@ func main() {
}
fmt.Println("gas fee:", gasFee, "INJ")
+
+ gasPrice = chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
}
```
diff --git a/source/includes/_bank.md b/source/includes/_bank.md
index 2e98d45f..08e001d9 100644
--- a/source/includes/_bank.md
+++ b/source/includes/_bank.md
@@ -19,7 +19,7 @@ import dotenv
from grpc import RpcError
from pyinjective.async_client import AsyncClient
-from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
+from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT
from pyinjective.core.network import Network
from pyinjective.transaction import Transaction
from pyinjective.wallet import PrivateKey
@@ -71,7 +71,10 @@ async def main() -> None:
return
# build tx
- gas_price = GAS_PRICE
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+
gas_limit = int(sim_res["gasInfo"]["gasUsed"]) + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
fee = [
@@ -108,15 +111,12 @@ import (
"time"
"cosmossdk.io/math"
-
- "github.com/InjectiveLabs/sdk-go/client"
-
- "github.com/InjectiveLabs/sdk-go/client/common"
-
- chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
rpchttp "github.com/cometbft/cometbft/rpc/client/http"
sdktypes "github.com/cosmos/cosmos-sdk/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
+
+ chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
+ "github.com/InjectiveLabs/sdk-go/client/common"
)
func main() {
@@ -154,13 +154,17 @@ func main() {
chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
- common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)
if err != nil {
panic(err)
}
+ gasPrice := chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
+
// prepare tx msg
msg := &banktypes.MsgSend{
FromAddress: senderAddress.String(),
@@ -187,6 +191,11 @@ func main() {
}
fmt.Println("gas fee:", gasFee, "INJ")
+
+ gasPrice = chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
}
```
@@ -308,14 +317,12 @@ import (
"time"
"cosmossdk.io/math"
-
- "github.com/InjectiveLabs/sdk-go/client"
- "github.com/InjectiveLabs/sdk-go/client/common"
-
- chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
rpchttp "github.com/cometbft/cometbft/rpc/client/http"
sdktypes "github.com/cosmos/cosmos-sdk/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
+
+ chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
+ "github.com/InjectiveLabs/sdk-go/client/common"
)
func main() {
@@ -356,13 +363,17 @@ func main() {
chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
- common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)
if err != nil {
panic(err)
}
+ gasPrice := chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
+
// prepare tx msg
msg := &banktypes.MsgMultiSend{
@@ -413,6 +424,11 @@ func main() {
}
fmt.Println("gas fee:", gasFee, "INJ")
+
+ gasPrice = chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
}
```
diff --git a/source/includes/_binaryoptions.md b/source/includes/_binaryoptions.md
index 27f57977..3f677da1 100644
--- a/source/includes/_binaryoptions.md
+++ b/source/includes/_binaryoptions.md
@@ -206,7 +206,6 @@ import (
exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types"
oracletypes "github.com/InjectiveLabs/sdk-go/chain/oracle/types"
- "github.com/InjectiveLabs/sdk-go/client"
chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
"github.com/InjectiveLabs/sdk-go/client/common"
)
@@ -247,12 +246,16 @@ func main() {
chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
- common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)
if err != nil {
panic(err)
}
+ gasPrice := chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
+
minPriceTickSize := math.LegacyMustNewDecFromStr("0.01")
minQuantityTickSize := math.LegacyMustNewDecFromStr("0.001")
@@ -285,6 +288,11 @@ func main() {
str, _ := json.MarshalIndent(response, "", " ")
fmt.Print(string(str))
+
+ gasPrice = chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
}
```
@@ -424,7 +432,7 @@ import dotenv
from grpc import RpcError
from pyinjective.async_client import AsyncClient
-from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
+from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT
from pyinjective.core.network import Network
from pyinjective.transaction import Transaction
from pyinjective.utils.denom import Denom
@@ -502,7 +510,10 @@ async def main() -> None:
print(sim_res_msg)
# build tx
- gas_price = GAS_PRICE
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+
gas_limit = int(sim_res["gasInfo"]["gasUsed"]) + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
fee = [
@@ -686,7 +697,7 @@ import dotenv
from grpc import RpcError
from pyinjective.async_client import AsyncClient
-from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
+from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT
from pyinjective.core.network import Network
from pyinjective.transaction import Transaction
from pyinjective.wallet import PrivateKey
@@ -752,7 +763,10 @@ async def main() -> None:
print(sim_res_msg)
# build tx
- gas_price = GAS_PRICE
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+
gas_limit = int(sim_res["gasInfo"]["gasUsed"]) + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
fee = [
@@ -934,7 +948,7 @@ import dotenv
from grpc import RpcError
from pyinjective.async_client import AsyncClient
-from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
+from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT
from pyinjective.core.network import Network
from pyinjective.transaction import Transaction
from pyinjective.wallet import PrivateKey
@@ -991,7 +1005,10 @@ async def main() -> None:
print(sim_res_msg)
# build tx
- gas_price = GAS_PRICE
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+
gas_limit = int(sim_res["gasInfo"]["gasUsed"]) + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
fee = [
@@ -1148,7 +1165,7 @@ import dotenv
from grpc import RpcError
from pyinjective.async_client import AsyncClient
-from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
+from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT
from pyinjective.core.network import Network
from pyinjective.transaction import Transaction
from pyinjective.wallet import PrivateKey
@@ -1213,7 +1230,10 @@ async def main() -> None:
print(sim_res_msg)
# build tx
- gas_price = GAS_PRICE
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+
gas_limit = int(sim_res["gasInfo"]["gasUsed"]) + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
fee = [
@@ -1375,7 +1395,7 @@ import dotenv
from grpc import RpcError
from pyinjective.async_client import AsyncClient
-from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
+from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT
from pyinjective.core.network import Network
from pyinjective.transaction import Transaction
from pyinjective.wallet import PrivateKey
@@ -1518,7 +1538,10 @@ async def main() -> None:
print(sim_res_msg)
# build tx
- gas_price = GAS_PRICE
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+
gas_limit = int(sim_res["gasInfo"]["gasUsed"]) + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
fee = [
@@ -1561,7 +1584,6 @@ import (
"github.com/shopspring/decimal"
exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types"
- "github.com/InjectiveLabs/sdk-go/client"
chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
"github.com/InjectiveLabs/sdk-go/client/common"
)
@@ -1603,7 +1625,6 @@ func main() {
chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
- common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)
if err != nil {
@@ -1611,6 +1632,11 @@ func main() {
return
}
+ gasPrice := chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
+
ctx := context.Background()
marketsAssistant, err := chainclient.NewMarketsAssistant(ctx, chainClient)
if err != nil {
@@ -1698,6 +1724,11 @@ func main() {
}
fmt.Println("gas fee:", gasFee, "INJ")
+
+ gasPrice = chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
}
```
diff --git a/source/includes/_broadcaster.md b/source/includes/_broadcaster.md
index c0feb113..a19c6062 100644
--- a/source/includes/_broadcaster.md
+++ b/source/includes/_broadcaster.md
@@ -18,13 +18,14 @@ To use the broadcaster you just need to create an instance of *MsgBroadcasterWit
```py
import asyncio
+import json
import os
import uuid
from decimal import Decimal
import dotenv
-from pyinjective.composer import Composer as ProtoMsgComposer
+from pyinjective.async_client import AsyncClient
from pyinjective.core.broadcaster import MsgBroadcasterWithPk
from pyinjective.core.network import Network
from pyinjective.wallet import PrivateKey
@@ -36,11 +37,20 @@ async def main() -> None:
# select network: local, testnet, mainnet
network = Network.testnet()
- composer = ProtoMsgComposer(network=network.string())
+
+ client = AsyncClient(network)
+ composer = await client.composer()
+
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
message_broadcaster = MsgBroadcasterWithPk.new_using_simulation(
network=network,
private_key=private_key_in_hexa,
+ gas_price=gas_price,
+ client=client,
+ composer=composer,
)
priv_key = PrivateKey.from_hex(private_key_in_hexa)
@@ -83,7 +93,12 @@ async def main() -> None:
# broadcast the transaction
result = await message_broadcaster.broadcast([msg])
print("---Transaction Response---")
- print(result)
+ print(json.dumps(result, indent=2))
+
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+ message_broadcaster.update_gas_price(gas_price=gas_price)
if __name__ == "__main__":
@@ -155,13 +170,14 @@ This is the most common broadcaster configuration. Unless you are using grantee
```py
import asyncio
+import json
import os
import uuid
from decimal import Decimal
import dotenv
-from pyinjective.composer import Composer as ProtoMsgComposer
+from pyinjective.async_client import AsyncClient
from pyinjective.core.broadcaster import MsgBroadcasterWithPk
from pyinjective.core.network import Network
from pyinjective.wallet import PrivateKey
@@ -173,11 +189,21 @@ async def main() -> None:
# select network: local, testnet, mainnet
network = Network.testnet()
- composer = ProtoMsgComposer(network=network.string())
+
+ client = AsyncClient(network)
+ composer = await client.composer()
+ await client.sync_timeout_height()
+
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
message_broadcaster = MsgBroadcasterWithPk.new_without_simulation(
network=network,
private_key=private_key_in_hexa,
+ gas_price=gas_price,
+ client=client,
+ composer=composer,
)
priv_key = PrivateKey.from_hex(private_key_in_hexa)
@@ -220,7 +246,12 @@ async def main() -> None:
# broadcast the transaction
result = await message_broadcaster.broadcast([msg])
print("---Transaction Response---")
- print(result)
+ print(json.dumps(result, indent=2))
+
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+ message_broadcaster.update_gas_price(gas_price=gas_price)
if __name__ == "__main__":
@@ -245,6 +276,7 @@ This is the required broadcaster configuration when operating with grantee accou
```py
import asyncio
+import json
import os
import uuid
from decimal import Decimal
@@ -252,7 +284,6 @@ from decimal import Decimal
import dotenv
from pyinjective.async_client import AsyncClient
-from pyinjective.composer import Composer as ProtoMsgComposer
from pyinjective.core.broadcaster import MsgBroadcasterWithPk
from pyinjective.core.network import Network
from pyinjective.wallet import Address, PrivateKey
@@ -265,10 +296,10 @@ async def main() -> None:
# select network: local, testnet, mainnet
network = Network.testnet()
- composer = ProtoMsgComposer(network=network.string())
# initialize grpc client
client = AsyncClient(network)
+ composer = await client.composer()
await client.sync_timeout_height()
# load account
@@ -276,9 +307,16 @@ async def main() -> None:
pub_key = priv_key.to_public_key()
address = pub_key.to_address()
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+
message_broadcaster = MsgBroadcasterWithPk.new_for_grantee_account_using_simulation(
network=network,
grantee_private_key=private_key_in_hexa,
+ gas_price=gas_price,
+ client=client,
+ composer=composer,
)
# prepare tx msg
@@ -301,7 +339,12 @@ async def main() -> None:
# broadcast the transaction
result = await message_broadcaster.broadcast([msg])
print("---Transaction Response---")
- print(result)
+ print(json.dumps(result, indent=2))
+
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+ message_broadcaster.update_gas_price(gas_price=gas_price)
if __name__ == "__main__":
@@ -365,6 +408,7 @@ For the broadcaster to calculate the gas fee running the simulation, create an i
```py
import asyncio
+import json
import os
import uuid
from decimal import Decimal
@@ -372,7 +416,6 @@ from decimal import Decimal
import dotenv
from pyinjective.async_client import AsyncClient
-from pyinjective.composer import Composer as ProtoMsgComposer
from pyinjective.core.broadcaster import MsgBroadcasterWithPk
from pyinjective.core.network import Network
from pyinjective.wallet import Address, PrivateKey
@@ -385,20 +428,26 @@ async def main() -> None:
# select network: local, testnet, mainnet
network = Network.testnet()
- composer = ProtoMsgComposer(network=network.string())
# initialize grpc client
client = AsyncClient(network)
- await client.sync_timeout_height()
+ composer = await client.composer()
# load account
priv_key = PrivateKey.from_hex(private_key_in_hexa)
pub_key = priv_key.to_public_key()
address = pub_key.to_address()
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+
message_broadcaster = MsgBroadcasterWithPk.new_for_grantee_account_without_simulation(
network=network,
grantee_private_key=private_key_in_hexa,
+ gas_price=gas_price,
+ client=client,
+ composer=composer,
)
# prepare tx msg
@@ -420,7 +469,12 @@ async def main() -> None:
# broadcast the transaction
result = await message_broadcaster.broadcast([msg])
print("---Transaction Response---")
- print(result)
+ print(json.dumps(result, indent=2))
+
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+ message_broadcaster.update_gas_price(gas_price=gas_price)
if __name__ == "__main__":
@@ -434,21 +488,56 @@ For the broadcaster to calculate the gas fee based on the messages included with
---
-***NOTE:***
-
+**NOTE:**
There an important consideration when using the Transaction Broadcaster calculating the gas cost without simulation to send a _MsgBatchUpdateOrders_ message.
The logic that estimates the gas cost for the _MsgBatchUpdateOrders_ correclty calculates the gas required for each order action (creation or cancelation) it includes. But there is no easy way to calculate the gas cost when canceling all orders for a market id using one of the following parameters: `spot_market_ids_to_cancel_all`, `derivative_market_ids_to_cancel_all` or `binary_options_market_ids_to_cancel_all`. The complexity is related to the fact that the gas cost depends on the number of orders to be cancelled.
By default the estimation logic calculates a gas cost considering the number of orders to cancel for each market id is 20.
-To improve the gas cost calculation when using the _MsgBatchUpdateOrders_ message to cancel all orders for one or more markets you can change the number of estimated orders to cancel per market running the following command:
-
- `BatchUpdateOrdersGasLimitEstimator.AVERAGE_CANCEL_ALL_AFFECTED_ORDERS = 30`
+To improve the gas cost calculation when using the _MsgBatchUpdateOrders_ message to cancel all orders for one or more markets you can change the number of estimated orders to cancel per market. Check in the fine-tunning section the proper `AVERAGE_CANCEL_ALL_AFFECTED_ORDERS` global variable to change.
+---
-## Fine-tunning gas fee local estimation
+## Fine-tunning message based gas fee estimation
As mentioned before the gas estimation without using simulation is implemented by using fixed values as gas cost for certain messages and actions. Since the real gas cost can differ at some point from the estimator calculations, the Python SDK allows the developer to fine-tune certain gas cost values in order to improve the gas cost estimation.
In the next tables you can find the global values used for gas estimation calculations, that can be modified in your application:
+### Gas limit estimation based on gas heuristics
+This is the estimator implemented with the class `GasHeuristicsGasLimitEstimator`.
+
+
+| Module | Global Variable | Description |
+| ----------------------------------------------------- | --------------------------------------------------- | ------------------------------------------------------------------------------------ |
+| `pyinjective.core.gas_heuristics_gas_limit_estimator` | `SPOT_ORDER_CREATION_GAS_LIMIT` | The gas cost associated to the creation of one spot limit order |
+| `pyinjective.core.gas_heuristics_gas_limit_estimator` | `SPOT_MARKET_ORDER_CREATION_GAS_LIMIT` | The gas cost associated to the creation of one spot market order |
+| `pyinjective.core.gas_heuristics_gas_limit_estimator` | `POST_ONLY_SPOT_ORDER_CREATION_GAS_LIMIT` | The gas cost associated to the creation of one post only spot limit order |
+| `pyinjective.core.gas_heuristics_gas_limit_estimator` | `DERIVATIVE_ORDER_CREATION_GAS_LIMIT` | The gas cost associated to the creation of one derivative order |
+| `pyinjective.core.gas_heuristics_gas_limit_estimator` | `DERIVATIVE_MARKET_ORDER_CREATION_GAS_LIMIT` | The gas cost associated to the creation of one derivative market order |
+| `pyinjective.core.gas_heuristics_gas_limit_estimator` | `POST_ONLY_DERIVATIVE_ORDER_CREATION_GAS_LIMIT` | The gas cost associated to the creation of one post only derivative limit order |
+| `pyinjective.core.gas_heuristics_gas_limit_estimator` | `BINARY_OPTIONS_ORDER_CREATION_GAS_LIMIT` | The gas cost associated to the creation of one binary options order |
+| `pyinjective.core.gas_heuristics_gas_limit_estimator` | `BINARY_OPTIONS_MARKET_ORDER_CREATION_GAS_LIMIT` | The gas cost associated to the creation of one binary options market order |
+| `pyinjective.core.gas_heuristics_gas_limit_estimator` | `POST_ONLY_BINARY_OPTIONS_ORDER_CREATION_GAS_LIMIT` | The gas cost associated to the creation of one post only binary options limit order |
+| `pyinjective.core.gas_heuristics_gas_limit_estimator` | `SPOT_ORDER_CANCELATION_GAS_LIMIT` | The gas cost associated to the cancellation of one spot order |
+| `pyinjective.core.gas_heuristics_gas_limit_estimator` | `DERIVATIVE_ORDER_CANCELATION_GAS_LIMIT` | The gas cost associated to the cancellation of one derivative order |
+| `pyinjective.core.gas_heuristics_gas_limit_estimator` | `BINARY_OPTIONS_ORDER_CANCELATION_GAS_LIMIT` | The gas cost associated to the cancellation of one binary options order |
+| `pyinjective.core.gas_heuristics_gas_limit_estimator` | `DEPOSIT_GAS_LIMIT` | The gas cost associated to a deposit into a subaccount |
+| `pyinjective.core.gas_heuristics_gas_limit_estimator` | `WITHDRAW_GAS_LIMIT` | The gas cost associated to a withdrawal from a subaccount |
+| `pyinjective.core.gas_heuristics_gas_limit_estimator` | `SUBACCOUNT_TRANSFER_GAS_LIMIT` | The gas cost associated to a funds transfer between subaccounts of the same address |
+| `pyinjective.core.gas_heuristics_gas_limit_estimator` | `EXTERNAL_TRANSFER_GAS_LIMIT` | The gas cost associated to a funds transfer to a subaccount from a different address |
+| `pyinjective.core.gas_heuristics_gas_limit_estimator` | `INCREASE_POSITION_MARGIN_TRANSFER_GAS_LIMIT` | The gas cost associated to increasing a position's margin |
+| `pyinjective.core.gas_heuristics_gas_limit_estimator` | `DECREASE_POSITION_MARGIN_TRANSFER_GAS_LIMIT` | The gas cost associated to decreasing a position's margin |
+
+
+
+| Module | Class | Global Variable | Description |
+| ----------------------------------------------------- | -------------------------------------- | ------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------- |
+| `pyinjective.core.broadcaster.py` | `MessageBasedTransactionFeeCalculator` | `TRANSACTION_GAS_LIMIT` | The gas cost associated to the TX processing |
+| `pyinjective.core.gas_heuristics_gas_limit_estimator` | `GasHeuristicsGasLimitEstimator` | `GENERAL_MESSAGE_GAS_LIMIT` | Generic base gas cost for any message |
+| `pyinjective.core.gas_heuristics_gas_limit_estimator` | `BatchUpdateOrdersGasLimitEstimator` | `AVERAGE_CANCEL_ALL_AFFECTED_ORDERS` | This global represents the expected number of orders to be cancelled when executing a "cancel all orders for a market" action |
+| `pyinjective.core.gas_heuristics_gas_limit_estimator` | `ExecGasLimitEstimator` | `DEFAULT_GAS_LIMIT` | Estimation of the general gas amount required for a MsgExec (for the general message processing) |
+
+
+### Gas limit estimation based on chain statistics
+This is the estimator implemented with the class `GasLimitEstimator`, and it is the original implementation for gas estimation without simulations. It has been replaced now by the `GasHeuristicsGasLimitEstimator`, but the user can still use it.
| Module | Global Variable | Description |
@@ -473,4 +562,4 @@ In the next tables you can find the global values used for gas estimation calcul
| `BatchUpdateOrdersGasLimitEstimator` | `MESSAGE_GAS_LIMIT` | Estimation of the general gas amount required for a MsgBatchUpdateOrders (not for particular actions, but for the general message processing) |
| `BatchUpdateOrdersGasLimitEstimator` | `AVERAGE_CANCEL_ALL_AFFECTED_ORDERS` | This global represents the expected number of orders to be cancelled when executing a "cancel all orders for a market" action |
| `ExecGasLimitEstimator` | `DEFAULT_GAS_LIMIT` | Estimation of the general gas amount required for a MsgExec (for the general message processing) |
-| `GenericExchangeGasLimitEstimator` | `BASIC_REFERENCE_GAS_LIMIT` | Base gas cost for messages not related to orders. Each type of message will calculate its cost multiplying this reference cost by a multiplier |
\ No newline at end of file
+| `GenericExchangeGasLimitEstimator` | `BASIC_REFERENCE_GAS_LIMIT` | Base gas cost for messages not related to orders. Each type of message will calculate its cost multiplying this reference cost by a multiplier |
diff --git a/source/includes/_chainexchange.md b/source/includes/_chainexchange.md
index 5f643794..39a65c80 100644
--- a/source/includes/_chainexchange.md
+++ b/source/includes/_chainexchange.md
@@ -4575,6 +4575,10 @@ func main() {
common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)
+ if err != nil {
+ panic(err)
+ }
+
marketId := "0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe" // Example derivative market ID
res, err := chainClient.FetchMarketBalance(context.Background(), marketId)
@@ -4602,7 +4606,7 @@ func main() {
```
-| Parameter | Type | Description |
|---|
| balance | Decimal | The current market balance |
+| Parameter | Type | Description |
|---|
| balance | MarketBalance | The current market balance |
@@ -5085,7 +5089,7 @@ import dotenv
from grpc import RpcError
from pyinjective.async_client import AsyncClient
-from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
+from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT
from pyinjective.core.network import Network
from pyinjective.transaction import Transaction
from pyinjective.wallet import PrivateKey
@@ -5132,7 +5136,10 @@ async def main() -> None:
return
# build tx
- gas_price = GAS_PRICE
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+
gas_limit = int(sim_res["gasInfo"]["gasUsed"]) + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
fee = [
@@ -5168,12 +5175,11 @@ import (
"os"
"time"
- "github.com/InjectiveLabs/sdk-go/client"
- "github.com/InjectiveLabs/sdk-go/client/common"
+ rpchttp "github.com/cometbft/cometbft/rpc/client/http"
exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types"
chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
- rpchttp "github.com/cometbft/cometbft/rpc/client/http"
+ "github.com/InjectiveLabs/sdk-go/client/common"
)
func main() {
@@ -5212,13 +5218,17 @@ func main() {
chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
- common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)
if err != nil {
panic(err)
}
+ gasPrice := chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
+
msg := &exchangetypes.MsgRewardsOptOut{
Sender: senderAddress.String(),
}
@@ -5240,6 +5250,11 @@ func main() {
}
fmt.Println("gas fee:", gasFee, "INJ")
+
+ gasPrice = chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
}
```
@@ -5340,6 +5355,7 @@ Message to grant stakes to grantees.
```py
import asyncio
+import json
import os
from decimal import Decimal
@@ -5362,11 +5378,17 @@ async def main() -> None:
client = AsyncClient(network)
await client.initialize_tokens_from_chain_denoms()
composer = await client.composer()
- await client.sync_timeout_height()
+
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
message_broadcaster = MsgBroadcasterWithPk.new_using_simulation(
network=network,
private_key=configured_private_key,
+ gas_price=gas_price,
+ client=client,
+ composer=composer,
)
# load account
@@ -5385,7 +5407,12 @@ async def main() -> None:
# broadcast the transaction
result = await message_broadcaster.broadcast([message])
print("---Transaction Response---")
- print(result)
+ print(json.dumps(result, indent=2))
+
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+ message_broadcaster.update_gas_price(gas_price=gas_price)
if __name__ == "__main__":
@@ -5404,9 +5431,6 @@ import (
"os"
"cosmossdk.io/math"
-
- "github.com/InjectiveLabs/sdk-go/client"
-
"github.com/InjectiveLabs/sdk-go/client/common"
exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types"
@@ -5450,13 +5474,17 @@ func main() {
chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
- common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)
if err != nil {
panic(err)
}
+ gasPrice := chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
+
grantAuthorization := &exchangetypes.GrantAuthorization{
Grantee: "inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r",
Amount: math.NewIntWithDecimal(1, 18),
@@ -5476,6 +5504,11 @@ func main() {
str, _ := json.MarshalIndent(response, "", " ")
fmt.Print(string(str))
+
+ gasPrice = chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
}
```
@@ -5601,6 +5634,7 @@ Message for grantees to claim stake grants.
```py
import asyncio
+import json
import os
import dotenv
@@ -5622,11 +5656,17 @@ async def main() -> None:
client = AsyncClient(network)
await client.initialize_tokens_from_chain_denoms()
composer = await client.composer()
- await client.sync_timeout_height()
+
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
message_broadcaster = MsgBroadcasterWithPk.new_using_simulation(
network=network,
private_key=configured_private_key,
+ gas_price=gas_price,
+ client=client,
+ composer=composer,
)
# load account
@@ -5643,7 +5683,12 @@ async def main() -> None:
# broadcast the transaction
result = await message_broadcaster.broadcast([message])
print("---Transaction Response---")
- print(result)
+ print(json.dumps(result, indent=2))
+
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+ message_broadcaster.update_gas_price(gas_price=gas_price)
if __name__ == "__main__":
@@ -5661,8 +5706,6 @@ import (
"fmt"
"os"
- "github.com/InjectiveLabs/sdk-go/client"
-
"github.com/InjectiveLabs/sdk-go/client/common"
exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types"
@@ -5706,13 +5749,17 @@ func main() {
chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
- common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)
if err != nil {
panic(err)
}
+ gasPrice := chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
+
msg := &exchangetypes.MsgActivateStakeGrant{
Sender: senderAddress.String(),
Granter: "inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r",
@@ -5727,6 +5774,11 @@ func main() {
str, _ := json.MarshalIndent(response, "", " ")
fmt.Print(string(str))
+
+ gasPrice = chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
}
```
diff --git a/source/includes/_changelog.md b/source/includes/_changelog.md
index ea44a97c..d8469059 100644
--- a/source/includes/_changelog.md
+++ b/source/includes/_changelog.md
@@ -1,5 +1,11 @@
# Change Log
+## 2025-04-21
+- Added documentation for `TXFees` module's endpoints
+- Updated all messages to reflect the changes included in the chain version 1.15, and the Indexer for that chain version
+- Python SDK v1.10.0
+- Go SDK v1.57.0
+
## 2025-02-17
- Changed the `Permissions` module documentation to reflect the new module version (new queries and messages)
- Updated all messages to reflect the changes included in the chain version 1.14, and the Indexer for that chain version
diff --git a/source/includes/_derivatives.md b/source/includes/_derivatives.md
index a8af1f7b..23fe6694 100644
--- a/source/includes/_derivatives.md
+++ b/source/includes/_derivatives.md
@@ -3088,6 +3088,7 @@ func main() {
```py
import asyncio
+import json
import os
from decimal import Decimal
@@ -3110,11 +3111,17 @@ async def main() -> None:
client = AsyncClient(network)
await client.initialize_tokens_from_chain_denoms()
composer = await client.composer()
- await client.sync_timeout_height()
+
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
message_broadcaster = MsgBroadcasterWithPk.new_using_simulation(
network=network,
private_key=configured_private_key,
+ gas_price=gas_price,
+ client=client,
+ composer=composer,
)
# load account
@@ -3144,7 +3151,12 @@ async def main() -> None:
# broadcast the transaction
result = await message_broadcaster.broadcast([message])
print("---Transaction Response---")
- print(result)
+ print(json.dumps(result, indent=2))
+
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+ message_broadcaster.update_gas_price(gas_price=gas_price)
if __name__ == "__main__":
@@ -3167,7 +3179,6 @@ import (
exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types"
oracletypes "github.com/InjectiveLabs/sdk-go/chain/oracle/types"
- "github.com/InjectiveLabs/sdk-go/client"
chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
"github.com/InjectiveLabs/sdk-go/client/common"
)
@@ -3208,12 +3219,16 @@ func main() {
chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
- common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)
if err != nil {
panic(err)
}
+ gasPrice := chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
+
minPriceTickSize := math.LegacyMustNewDecFromStr("0.01")
minQuantityTickSize := math.LegacyMustNewDecFromStr("0.001")
@@ -3245,6 +3260,11 @@ func main() {
str, _ := json.MarshalIndent(response, "", " ")
fmt.Print(string(str))
+
+ gasPrice = chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
}
```
@@ -3375,6 +3395,7 @@ func main() {
```py
import asyncio
+import json
import os
from decimal import Decimal
@@ -3397,11 +3418,17 @@ async def main() -> None:
client = AsyncClient(network)
await client.initialize_tokens_from_chain_denoms()
composer = await client.composer()
- await client.sync_timeout_height()
+
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
message_broadcaster = MsgBroadcasterWithPk.new_using_simulation(
network=network,
private_key=configured_private_key,
+ gas_price=gas_price,
+ client=client,
+ composer=composer,
)
# load account
@@ -3432,7 +3459,12 @@ async def main() -> None:
# broadcast the transaction
result = await message_broadcaster.broadcast([message])
print("---Transaction Response---")
- print(result)
+ print(json.dumps(result, indent=2))
+
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+ message_broadcaster.update_gas_price(gas_price=gas_price)
if __name__ == "__main__":
@@ -3455,7 +3487,6 @@ import (
exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types"
oracletypes "github.com/InjectiveLabs/sdk-go/chain/oracle/types"
- "github.com/InjectiveLabs/sdk-go/client"
chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
"github.com/InjectiveLabs/sdk-go/client/common"
)
@@ -3496,12 +3527,16 @@ func main() {
chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
- common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)
if err != nil {
panic(err)
}
+ gasPrice := chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
+
minPriceTickSize := math.LegacyMustNewDecFromStr("0.01")
minQuantityTickSize := math.LegacyMustNewDecFromStr("0.001")
@@ -3534,6 +3569,11 @@ func main() {
str, _ := json.MarshalIndent(response, "", " ")
fmt.Print(string(str))
+
+ gasPrice = chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
}
```
@@ -3673,7 +3713,7 @@ import dotenv
from grpc import RpcError
from pyinjective.async_client import AsyncClient
-from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
+from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT
from pyinjective.core.network import Network
from pyinjective.transaction import Transaction
from pyinjective.wallet import PrivateKey
@@ -3741,7 +3781,10 @@ async def main() -> None:
print(sim_res_msg)
# build tx
- gas_price = GAS_PRICE
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+
gas_limit = int(sim_res["gasInfo"]["gasUsed"]) + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
fee = [
@@ -3784,7 +3827,6 @@ import (
"github.com/shopspring/decimal"
exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types"
- "github.com/InjectiveLabs/sdk-go/client"
chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
"github.com/InjectiveLabs/sdk-go/client/common"
)
@@ -3825,13 +3867,17 @@ func main() {
chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
- common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)
if err != nil {
panic(err)
}
+ gasPrice := chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
+
ctx := context.Background()
marketsAssistant, err := chainclient.NewMarketsAssistant(ctx, chainClient)
if err != nil {
@@ -3896,6 +3942,11 @@ func main() {
}
fmt.Println("gas fee:", gasFee, "INJ")
+
+ gasPrice = chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
}
```
@@ -4062,7 +4113,7 @@ import dotenv
from grpc import RpcError
from pyinjective.async_client import AsyncClient
-from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
+from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT
from pyinjective.core.network import Network
from pyinjective.transaction import Transaction
from pyinjective.wallet import PrivateKey
@@ -4130,7 +4181,10 @@ async def main() -> None:
print(sim_res_msg)
# build tx
- gas_price = GAS_PRICE
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+
gas_limit = int(sim_res["gasInfo"]["gasUsed"]) + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
fee = [
@@ -4173,7 +4227,6 @@ import (
"github.com/shopspring/decimal"
exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types"
- "github.com/InjectiveLabs/sdk-go/client"
chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
"github.com/InjectiveLabs/sdk-go/client/common"
)
@@ -4215,13 +4268,17 @@ func main() {
chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
- common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)
if err != nil {
panic(err)
}
+ gasPrice := chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
+
ctx := context.Background()
marketsAssistant, err := chainclient.NewMarketsAssistant(ctx, chainClient)
if err != nil {
@@ -4287,6 +4344,11 @@ func main() {
}
fmt.Println("gas fee:", gasFee, "INJ")
+
+ gasPrice = chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
}
```
@@ -4452,7 +4514,7 @@ import dotenv
from grpc import RpcError
from pyinjective.async_client import AsyncClient
-from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
+from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT
from pyinjective.core.network import Network
from pyinjective.transaction import Transaction
from pyinjective.wallet import PrivateKey
@@ -4506,7 +4568,10 @@ async def main() -> None:
return
# build tx
- gas_price = GAS_PRICE
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+
gas_limit = int(sim_res["gasInfo"]["gasUsed"]) + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
fee = [
@@ -4542,13 +4607,11 @@ import (
"os"
"time"
- "github.com/InjectiveLabs/sdk-go/client"
-
- "github.com/InjectiveLabs/sdk-go/client/common"
+ rpchttp "github.com/cometbft/cometbft/rpc/client/http"
exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types"
chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
- rpchttp "github.com/cometbft/cometbft/rpc/client/http"
+ "github.com/InjectiveLabs/sdk-go/client/common"
)
func main() {
@@ -4587,13 +4650,17 @@ func main() {
chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
- common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)
if err != nil {
panic(err)
}
+ gasPrice := chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
+
msg := &exchangetypes.MsgCancelDerivativeOrder{
Sender: senderAddress.String(),
MarketId: "0x4ca0f92fc28be0c9761326016b5a1a2177dd6375558365116b5bdda9abc229ce",
@@ -4618,6 +4685,11 @@ func main() {
}
fmt.Println("gas fee:", gasFee, "INJ")
+
+ gasPrice = chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
}
```
@@ -4768,7 +4840,7 @@ import dotenv
from grpc import RpcError
from pyinjective.async_client import AsyncClient
-from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
+from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT
from pyinjective.core.network import Network
from pyinjective.transaction import Transaction
from pyinjective.wallet import PrivateKey
@@ -4911,7 +4983,10 @@ async def main() -> None:
print(sim_res_msg)
# build tx
- gas_price = GAS_PRICE
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+
gas_limit = int(sim_res["gasInfo"]["gasUsed"]) + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
fee = [
@@ -4954,7 +5029,6 @@ import (
"github.com/shopspring/decimal"
exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types"
- "github.com/InjectiveLabs/sdk-go/client"
chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
"github.com/InjectiveLabs/sdk-go/client/common"
)
@@ -4996,7 +5070,6 @@ func main() {
chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
- common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)
if err != nil {
@@ -5004,6 +5077,11 @@ func main() {
return
}
+ gasPrice := chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
+
ctx := context.Background()
marketsAssistant, err := chainclient.NewMarketsAssistant(ctx, chainClient)
if err != nil {
@@ -5091,6 +5169,11 @@ func main() {
}
fmt.Println("gas fee:", gasFee, "INJ")
+
+ gasPrice = chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
}
```
@@ -5317,7 +5400,7 @@ import dotenv
from grpc import RpcError
from pyinjective.async_client import AsyncClient
-from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
+from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT
from pyinjective.core.network import Network
from pyinjective.transaction import Transaction
from pyinjective.wallet import PrivateKey
@@ -5392,7 +5475,10 @@ async def main() -> None:
print(sim_res_msg)
# build tx
- gas_price = GAS_PRICE
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+
gas_limit = int(sim_res["gasInfo"]["gasUsed"]) + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
fee = [
@@ -5436,7 +5522,6 @@ import (
"github.com/shopspring/decimal"
exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types"
- "github.com/InjectiveLabs/sdk-go/client"
chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
"github.com/InjectiveLabs/sdk-go/client/common"
)
@@ -5477,13 +5562,17 @@ func main() {
chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
- common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)
if err != nil {
panic(err)
}
+ gasPrice := chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
+
ctx := context.Background()
marketsAssistant, err := chainclient.NewMarketsAssistant(ctx, chainClient)
if err != nil {
@@ -5527,6 +5616,11 @@ func main() {
str, _ := json.MarshalIndent(response, "", " ")
fmt.Print(string(str))
+
+ gasPrice = chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
}
```
@@ -5680,7 +5774,7 @@ import dotenv
from grpc import RpcError
from pyinjective.async_client import AsyncClient
-from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
+from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT
from pyinjective.core.network import Network
from pyinjective.transaction import Transaction
from pyinjective.wallet import PrivateKey
@@ -5737,7 +5831,10 @@ async def main() -> None:
return
# build tx
- gas_price = GAS_PRICE
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+
gas_limit = int(sim_res["gasInfo"]["gasUsed"]) + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
fee = [
@@ -5774,14 +5871,11 @@ import (
"time"
"cosmossdk.io/math"
-
- "github.com/InjectiveLabs/sdk-go/client"
-
- "github.com/InjectiveLabs/sdk-go/client/common"
+ rpchttp "github.com/cometbft/cometbft/rpc/client/http"
exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types"
chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
- rpchttp "github.com/cometbft/cometbft/rpc/client/http"
+ "github.com/InjectiveLabs/sdk-go/client/common"
)
func main() {
@@ -5820,13 +5914,17 @@ func main() {
chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
- common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)
if err != nil {
panic(err)
}
+ gasPrice := chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
+
msg := &exchangetypes.MsgIncreasePositionMargin{
Sender: senderAddress.String(),
MarketId: "0x4ca0f92fc28be0c9761326016b5a1a2177dd6375558365116b5bdda9abc229ce",
@@ -5852,6 +5950,11 @@ func main() {
}
fmt.Println("gas fee:", gasFee, "INJ")
+
+ gasPrice = chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
}
```
@@ -5970,6 +6073,7 @@ Message to reduce the margin assigned to a particular position
```py
import asyncio
+import json
import os
from decimal import Decimal
@@ -5991,11 +6095,17 @@ async def main() -> None:
# initialize grpc client
client = AsyncClient(network)
composer = await client.composer()
- await client.sync_timeout_height()
+
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
message_broadcaster = MsgBroadcasterWithPk.new_using_simulation(
network=network,
private_key=configured_private_key,
+ gas_price=gas_price,
+ client=client,
+ composer=composer,
)
# load account
@@ -6020,7 +6130,12 @@ async def main() -> None:
# broadcast the transaction
result = await message_broadcaster.broadcast([msg])
print("---Transaction Response---")
- print(result)
+ print(json.dumps(result, indent=2))
+
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+ message_broadcaster.update_gas_price(gas_price=gas_price)
if __name__ == "__main__":
@@ -6039,14 +6154,11 @@ import (
"os"
"cosmossdk.io/math"
-
- "github.com/InjectiveLabs/sdk-go/client"
-
- "github.com/InjectiveLabs/sdk-go/client/common"
+ rpchttp "github.com/cometbft/cometbft/rpc/client/http"
exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types"
chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
- rpchttp "github.com/cometbft/cometbft/rpc/client/http"
+ "github.com/InjectiveLabs/sdk-go/client/common"
)
func main() {
@@ -6085,13 +6197,17 @@ func main() {
chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
- common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)
if err != nil {
panic(err)
}
+ gasPrice := chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
+
defaultSubaccountID := chainClient.DefaultSubaccount(senderAddress)
msg := &exchangetypes.MsgDecreasePositionMargin{
@@ -6111,6 +6227,11 @@ func main() {
str, _ := json.MarshalIndent(response, "", " ")
fmt.Print(string(str))
+
+ gasPrice = chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
}
```
@@ -6229,6 +6350,7 @@ Modifies certain market fields. It can only be sent by the market's admin.
```py
import asyncio
+import json
import os
from decimal import Decimal
@@ -6251,11 +6373,17 @@ async def main() -> None:
client = AsyncClient(network)
await client.initialize_tokens_from_chain_denoms()
composer = await client.composer()
- await client.sync_timeout_height()
+
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
message_broadcaster = MsgBroadcasterWithPk.new_using_simulation(
network=network,
private_key=configured_private_key,
+ gas_price=gas_price,
+ client=client,
+ composer=composer,
)
# load account
@@ -6279,7 +6407,12 @@ async def main() -> None:
# broadcast the transaction
result = await message_broadcaster.broadcast([message])
print("---Transaction Response---")
- print(result)
+ print(json.dumps(result, indent=2))
+
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+ message_broadcaster.update_gas_price(gas_price=gas_price)
if __name__ == "__main__":
@@ -6301,7 +6434,6 @@ import (
rpchttp "github.com/cometbft/cometbft/rpc/client/http"
exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types"
- "github.com/InjectiveLabs/sdk-go/client"
chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
"github.com/InjectiveLabs/sdk-go/client/common"
)
@@ -6342,12 +6474,16 @@ func main() {
chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
- common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)
if err != nil {
panic(err)
}
+ gasPrice := chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
+
minPriceTickSize := math.LegacyMustNewDecFromStr("0.1")
minQuantityTickSize := math.LegacyMustNewDecFromStr("0.1")
minNotional := math.LegacyMustNewDecFromStr("2")
@@ -6376,6 +6512,11 @@ func main() {
str, _ := json.MarshalIndent(response, "", " ")
fmt.Print(string(str))
+
+ gasPrice = chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
}
```
@@ -6503,7 +6644,7 @@ from decimal import Decimal
import dotenv
from pyinjective.async_client import AsyncClient
-from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
+from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT
from pyinjective.core.network import Network
from pyinjective.orderhash import OrderHashManager
from pyinjective.transaction import Transaction
@@ -6608,7 +6749,11 @@ async def main() -> None:
.with_account_num(client.get_number())
.with_chain_id(network.chain_id)
)
- gas_price = GAS_PRICE
+
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+
base_gas = 85000
gas_limit = base_gas + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
@@ -6645,7 +6790,11 @@ async def main() -> None:
.with_account_num(client.get_number())
.with_chain_id(network.chain_id)
)
- gas_price = GAS_PRICE
+
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+
base_gas = 85000
gas_limit = base_gas + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
@@ -6737,7 +6886,11 @@ async def main() -> None:
.with_account_num(client.get_number())
.with_chain_id(network.chain_id)
)
- gas_price = GAS_PRICE
+
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+
base_gas = 85000
gas_limit = base_gas + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
@@ -6780,7 +6933,6 @@ import (
"github.com/shopspring/decimal"
exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types"
- "github.com/InjectiveLabs/sdk-go/client"
chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
"github.com/InjectiveLabs/sdk-go/client/common"
)
@@ -6821,13 +6973,17 @@ func main() {
chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
- common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)
if err != nil {
panic(err)
}
+ gasPrice := chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
+
ctx := context.Background()
marketsAssistant, err := chainclient.NewMarketsAssistant(ctx, chainClient)
if err != nil {
@@ -6899,6 +7055,11 @@ func main() {
}
fmt.Println("gas fee:", gasFee, "INJ")
+
+ gasPrice = chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
}
```
diff --git a/source/includes/_derivativesrpc.md b/source/includes/_derivativesrpc.md
index 82df6927..ca6284c4 100644
--- a/source/includes/_derivativesrpc.md
+++ b/source/includes/_derivativesrpc.md
@@ -3882,7 +3882,7 @@ async def main() -> None:
skip = 1
limit = 2
pagination = PaginationOption(skip=skip, limit=limit)
- orders = await client.fetch_subaccount_orders_list(
+ orders = await client.fetch_derivative_subaccount_orders_list(
subaccount_id=subaccount_id, market_id=market_id, pagination=pagination
)
print(orders)
diff --git a/source/includes/_ibctransfer.md b/source/includes/_ibctransfer.md
index e5dfbb37..8f657f5a 100644
--- a/source/includes/_ibctransfer.md
+++ b/source/includes/_ibctransfer.md
@@ -756,6 +756,7 @@ Defines a msg to transfer fungible tokens (i.e Coins) between ICS20 enabled chai
```py
import asyncio
+import json
import os
from decimal import Decimal
@@ -778,7 +779,10 @@ async def main() -> None:
client = AsyncClient(network)
await client.initialize_tokens_from_chain_denoms()
composer = await client.composer()
- await client.sync_timeout_height()
+
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
message_broadcaster = MsgBroadcasterWithPk.new_using_simulation(
network=network,
@@ -811,7 +815,12 @@ async def main() -> None:
# broadcast the transaction
result = await message_broadcaster.broadcast([message])
print("---Transaction Response---")
- print(result)
+ print(json.dumps(result, indent=2))
+
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+ message_broadcaster.update_gas_price(gas_price=gas_price)
if __name__ == "__main__":
@@ -830,8 +839,6 @@ import (
"os"
"cosmossdk.io/math"
-
- "github.com/InjectiveLabs/sdk-go/client"
"github.com/InjectiveLabs/sdk-go/client/common"
chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
@@ -876,13 +883,17 @@ func main() {
chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
- common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)
if err != nil {
panic(err)
}
+ gasPrice := chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
+
sourcePort := "transfer"
sourceChannel := "channel-126"
coin := sdktypes.Coin{
@@ -910,6 +921,11 @@ func main() {
str, _ := json.MarshalIndent(response, "", " ")
fmt.Print(string(str))
+
+ gasPrice = chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
}
```
diff --git a/source/includes/_insurance.md b/source/includes/_insurance.md
index 1f9442e4..60dcf7d0 100644
--- a/source/includes/_insurance.md
+++ b/source/includes/_insurance.md
@@ -19,7 +19,7 @@ import dotenv
from grpc import RpcError
from pyinjective.async_client import AsyncClient
-from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
+from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT
from pyinjective.core.network import Network
from pyinjective.transaction import Transaction
from pyinjective.wallet import PrivateKey
@@ -75,7 +75,10 @@ async def main() -> None:
return
# build tx
- gas_price = GAS_PRICE
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+
gas_limit = int(sim_res["gasInfo"]["gasUsed"]) + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
fee = [
@@ -212,7 +215,7 @@ import dotenv
from grpc import RpcError
from pyinjective.async_client import AsyncClient
-from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
+from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT
from pyinjective.core.network import Network
from pyinjective.transaction import Transaction
from pyinjective.wallet import PrivateKey
@@ -264,7 +267,10 @@ async def main() -> None:
return
# build tx
- gas_price = GAS_PRICE
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+
gas_limit = int(sim_res["gasInfo"]["gasUsed"]) + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
fee = [
@@ -396,7 +402,7 @@ import dotenv
from grpc import RpcError
from pyinjective.async_client import AsyncClient
-from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
+from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT
from pyinjective.core.network import Network
from pyinjective.transaction import Transaction
from pyinjective.wallet import PrivateKey
@@ -448,7 +454,10 @@ async def main() -> None:
return
# build tx
- gas_price = GAS_PRICE
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+
gas_limit = int(sim_res["gasInfo"]["gasUsed"]) + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
fee = [
diff --git a/source/includes/_oracle.md b/source/includes/_oracle.md
index 0f007ec7..23f97693 100644
--- a/source/includes/_oracle.md
+++ b/source/includes/_oracle.md
@@ -19,7 +19,7 @@ import dotenv
from grpc import RpcError
from pyinjective.async_client import AsyncClient
-from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
+from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT
from pyinjective.core.network import Network
from pyinjective.transaction import Transaction
from pyinjective.wallet import PrivateKey
@@ -71,7 +71,10 @@ async def main() -> None:
return
# build tx
- gas_price = GAS_PRICE
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+
gas_limit = int(sim_res["gasInfo"]["gasUsed"]) + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
fee = [
@@ -107,7 +110,6 @@ import (
"os"
"cosmossdk.io/math"
- "github.com/InjectiveLabs/sdk-go/client"
"github.com/InjectiveLabs/sdk-go/client/common"
txtypes "github.com/cosmos/cosmos-sdk/types/tx"
@@ -152,13 +154,17 @@ func main() {
chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
- common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)
if err != nil {
panic(err)
}
+ gasPrice := chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
+
price := []math.LegacyDec{math.LegacyMustNewDecFromStr("100")}
base := []string{"BAYC"}
quote := []string{"WETH"}
@@ -178,6 +184,11 @@ func main() {
}
fmt.Printf("Broadcast result: %s\n", result)
+
+ gasPrice = chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
}
```
@@ -297,7 +308,7 @@ import dotenv
from grpc import RpcError
from pyinjective.async_client import AsyncClient
-from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
+from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT
from pyinjective.core.network import Network
from pyinjective.transaction import Transaction
from pyinjective.wallet import PrivateKey
@@ -354,7 +365,10 @@ async def main() -> None:
print(sim_res_msg)
# build tx
- gas_price = GAS_PRICE
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+
gas_limit = int(sim_res["gasInfo"]["gasUsed"]) + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
fee = [
diff --git a/source/includes/_permissions.md b/source/includes/_permissions.md
index ec555486..22cf454a 100644
--- a/source/includes/_permissions.md
+++ b/source/includes/_permissions.md
@@ -2966,11 +2966,12 @@ Message to create a new namespace
```py
import asyncio
+import json
import os
import dotenv
-from pyinjective.composer import Composer as ProtoMsgComposer
+from pyinjective.async_client import AsyncClient
from pyinjective.core.broadcaster import MsgBroadcasterWithPk
from pyinjective.core.network import Network
from pyinjective.wallet import PrivateKey
@@ -2982,11 +2983,19 @@ async def main() -> None:
# select network: local, testnet, mainnet
network = Network.devnet()
- composer = ProtoMsgComposer(network=network.string())
+ client = AsyncClient(network)
+ composer = await client.composer()
+
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
message_broadcaster = MsgBroadcasterWithPk.new_using_simulation(
network=network,
private_key=private_key_in_hexa,
+ gas_price=gas_price,
+ client=client,
+ composer=composer,
)
priv_key = PrivateKey.from_hex(private_key_in_hexa)
@@ -3060,7 +3069,12 @@ async def main() -> None:
# broadcast the transaction
result = await message_broadcaster.broadcast([message])
print("---Transaction Response---")
- print(result)
+ print(json.dumps(result, indent=2))
+
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+ message_broadcaster.update_gas_price(gas_price=gas_price)
if __name__ == "__main__":
@@ -3079,7 +3093,6 @@ import (
"os"
permissionstypes "github.com/InjectiveLabs/sdk-go/chain/permissions/types"
- "github.com/InjectiveLabs/sdk-go/client"
chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
"github.com/InjectiveLabs/sdk-go/client/common"
rpchttp "github.com/cometbft/cometbft/rpc/client/http"
@@ -3121,13 +3134,17 @@ func main() {
chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
- common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)
if err != nil {
panic(err)
}
+ gasPrice := chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
+
denom := "factory/inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r/inj_test"
role1 := permissionstypes.Role{
Name: "EVERYONE",
@@ -3205,6 +3222,11 @@ func main() {
str, _ := json.MarshalIndent(response, "", " ")
fmt.Print(string(str))
+
+ gasPrice = chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
}
```
@@ -3386,11 +3408,12 @@ Message to update a namespace configuration
```py
import asyncio
+import json
import os
import dotenv
-from pyinjective.composer import Composer as ProtoMsgComposer
+from pyinjective.async_client import AsyncClient
from pyinjective.core.broadcaster import MsgBroadcasterWithPk
from pyinjective.core.network import Network
from pyinjective.wallet import PrivateKey
@@ -3402,11 +3425,20 @@ async def main() -> None:
# select network: local, testnet, mainnet
network = Network.devnet()
- composer = ProtoMsgComposer(network=network.string())
+
+ client = AsyncClient(network)
+ composer = await client.composer()
+
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
message_broadcaster = MsgBroadcasterWithPk.new_using_simulation(
network=network,
private_key=private_key_in_hexa,
+ gas_price=gas_price,
+ client=client,
+ composer=composer,
)
priv_key = PrivateKey.from_hex(private_key_in_hexa)
@@ -3462,7 +3494,12 @@ async def main() -> None:
# broadcast the transaction
result = await message_broadcaster.broadcast([message])
print("---Transaction Response---")
- print(result)
+ print(json.dumps(result, indent=2))
+
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+ message_broadcaster.update_gas_price(gas_price=gas_price)
if __name__ == "__main__":
@@ -3480,11 +3517,11 @@ import (
"fmt"
"os"
+ rpchttp "github.com/cometbft/cometbft/rpc/client/http"
+
permissionstypes "github.com/InjectiveLabs/sdk-go/chain/permissions/types"
- "github.com/InjectiveLabs/sdk-go/client"
chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
"github.com/InjectiveLabs/sdk-go/client/common"
- rpchttp "github.com/cometbft/cometbft/rpc/client/http"
)
func main() {
@@ -3523,13 +3560,17 @@ func main() {
chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
- common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)
if err != nil {
panic(err)
}
+ gasPrice := chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
+
denom := "factory/inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r/inj_test"
role1 := permissionstypes.Role{
@@ -3585,6 +3626,11 @@ func main() {
str, _ := json.MarshalIndent(response, "", " ")
fmt.Print(string(str))
+
+ gasPrice = chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
}
```
@@ -3756,11 +3802,12 @@ Message to update the roles assigned to an actor
```py
import asyncio
+import json
import os
import dotenv
-from pyinjective.composer import Composer as ProtoMsgComposer
+from pyinjective.async_client import AsyncClient
from pyinjective.core.broadcaster import MsgBroadcasterWithPk
from pyinjective.core.network import Network
from pyinjective.wallet import PrivateKey
@@ -3772,11 +3819,20 @@ async def main() -> None:
# select network: local, testnet, mainnet
network = Network.devnet()
- composer = ProtoMsgComposer(network=network.string())
+
+ client = AsyncClient(network)
+ composer = await client.composer()
+
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
message_broadcaster = MsgBroadcasterWithPk.new_using_simulation(
network=network,
private_key=private_key_in_hexa,
+ gas_price=gas_price,
+ client=client,
+ composer=composer,
)
priv_key = PrivateKey.from_hex(private_key_in_hexa)
@@ -3812,7 +3868,12 @@ async def main() -> None:
# broadcast the transaction
result = await message_broadcaster.broadcast([message])
print("---Transaction Response---")
- print(result)
+ print(json.dumps(result, indent=2))
+
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+ message_broadcaster.update_gas_price(gas_price=gas_price)
if __name__ == "__main__":
@@ -3834,7 +3895,6 @@ import (
txtypes "github.com/cosmos/cosmos-sdk/types/tx"
permissionstypes "github.com/InjectiveLabs/sdk-go/chain/permissions/types"
- "github.com/InjectiveLabs/sdk-go/client"
chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
"github.com/InjectiveLabs/sdk-go/client/common"
)
@@ -3875,13 +3935,17 @@ func main() {
chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
- common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)
if err != nil {
panic(err)
}
+ gasPrice := chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
+
denom := "factory/inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r/inj_test"
roleActors1 := permissionstypes.RoleActors{
Role: "admin",
@@ -3916,6 +3980,11 @@ func main() {
str, _ := json.MarshalIndent(response, "", " ")
fmt.Print(string(str))
+
+ gasPrice = chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
}
```
@@ -4029,11 +4098,12 @@ Message to claim existing vouchers for a particular address
```py
import asyncio
+import json
import os
import dotenv
-from pyinjective.composer import Composer as ProtoMsgComposer
+from pyinjective.async_client import AsyncClient
from pyinjective.core.broadcaster import MsgBroadcasterWithPk
from pyinjective.core.network import Network
from pyinjective.wallet import PrivateKey
@@ -4045,11 +4115,20 @@ async def main() -> None:
# select network: local, testnet, mainnet
network = Network.devnet()
- composer = ProtoMsgComposer(network=network.string())
+
+ client = AsyncClient(network)
+ composer = await client.composer()
+
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
message_broadcaster = MsgBroadcasterWithPk.new_using_simulation(
network=network,
private_key=private_key_in_hexa,
+ gas_price=gas_price,
+ client=client,
+ composer=composer,
)
priv_key = PrivateKey.from_hex(private_key_in_hexa)
@@ -4066,7 +4145,12 @@ async def main() -> None:
# broadcast the transaction
result = await message_broadcaster.broadcast([message])
print("---Transaction Response---")
- print(result)
+ print(json.dumps(result, indent=2))
+
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+ message_broadcaster.update_gas_price(gas_price=gas_price)
if __name__ == "__main__":
@@ -4088,7 +4172,6 @@ import (
txtypes "github.com/cosmos/cosmos-sdk/types/tx"
permissionstypes "github.com/InjectiveLabs/sdk-go/chain/permissions/types"
- "github.com/InjectiveLabs/sdk-go/client"
chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
"github.com/InjectiveLabs/sdk-go/client/common"
)
@@ -4129,13 +4212,17 @@ func main() {
chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
- common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)
if err != nil {
panic(err)
}
+ gasPrice := chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
+
denom := "factory/inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r/inj_test"
msg := &permissionstypes.MsgClaimVoucher{
@@ -4152,6 +4239,11 @@ func main() {
str, _ := json.MarshalIndent(response, "", " ")
fmt.Print(string(str))
+
+ gasPrice = chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
}
```
diff --git a/source/includes/_portfoliorpc.md b/source/includes/_portfoliorpc.md
index e054c1a1..2dfe4a87 100644
--- a/source/includes/_portfoliorpc.md
+++ b/source/includes/_portfoliorpc.md
@@ -26,7 +26,7 @@ async def main() -> None:
network = Network.testnet()
client = AsyncClient(network)
account_address = "inj1clw20s2uxeyxtam6f7m84vgae92s9eh7vygagt"
- portfolio = await client.fetch_account_portfolio_balances(account_address=account_address)
+ portfolio = await client.fetch_account_portfolio_balances(account_address=account_address, usd=False)
print(portfolio)
@@ -51,7 +51,7 @@ import (
func main() {
// select network: local, testnet, mainnet
- network := common.LoadNetwork("testnet", "lb")
+ network := common.LoadNetwork("devnet", "lb")
exchangeClient, err := exchangeclient.NewExchangeClient(network)
if err != nil {
panic(err)
@@ -59,7 +59,7 @@ func main() {
ctx := context.Background()
accountAddress := "inj1clw20s2uxeyxtam6f7m84vgae92s9eh7vygagt"
- res, err := exchangeClient.GetAccountPortfolioBalances(ctx, accountAddress)
+ res, err := exchangeClient.GetAccountPortfolioBalances(ctx, accountAddress, true)
if err != nil {
fmt.Println(err)
}
diff --git a/source/includes/_spot.md b/source/includes/_spot.md
index 0cce32f8..14b33508 100644
--- a/source/includes/_spot.md
+++ b/source/includes/_spot.md
@@ -1877,6 +1877,7 @@ func main() {
```py
import asyncio
+import json
import os
from decimal import Decimal
@@ -1899,11 +1900,17 @@ async def main() -> None:
client = AsyncClient(network)
await client.initialize_tokens_from_chain_denoms()
composer = await client.composer()
- await client.sync_timeout_height()
+
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
message_broadcaster = MsgBroadcasterWithPk.new_using_simulation(
network=network,
private_key=configured_private_key,
+ gas_price=gas_price,
+ client=client,
+ composer=composer,
)
# load account
@@ -1928,7 +1935,12 @@ async def main() -> None:
# broadcast the transaction
result = await message_broadcaster.broadcast([message])
print("---Transaction Response---")
- print(result)
+ print(json.dumps(result, indent=2))
+
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+ message_broadcaster.update_gas_price(gas_price=gas_price)
if __name__ == "__main__":
@@ -1950,7 +1962,6 @@ import (
rpchttp "github.com/cometbft/cometbft/rpc/client/http"
exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types"
- "github.com/InjectiveLabs/sdk-go/client"
chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
"github.com/InjectiveLabs/sdk-go/client/common"
)
@@ -1991,12 +2002,16 @@ func main() {
chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
- common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)
if err != nil {
panic(err)
}
+ gasPrice := chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
+
minPriceTickSize := math.LegacyMustNewDecFromStr("0.01")
minQuantityTickSize := math.LegacyMustNewDecFromStr("0.001")
minNotional := math.LegacyMustNewDecFromStr("1")
@@ -2028,6 +2043,11 @@ func main() {
str, _ := json.MarshalIndent(response, "", " ")
fmt.Print(string(str))
+
+ gasPrice = chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
}
```
@@ -2143,7 +2163,7 @@ import dotenv
from grpc import RpcError
from pyinjective.async_client import AsyncClient
-from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
+from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT
from pyinjective.core.network import Network
from pyinjective.transaction import Transaction
from pyinjective.wallet import PrivateKey
@@ -2209,7 +2229,10 @@ async def main() -> None:
print(sim_res_msg)
# build tx
- gas_price = GAS_PRICE
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+
gas_limit = int(sim_res["gasInfo"]["gasUsed"]) + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
fee = [
@@ -2253,7 +2276,6 @@ import (
"github.com/shopspring/decimal"
exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types"
- "github.com/InjectiveLabs/sdk-go/client"
chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
"github.com/InjectiveLabs/sdk-go/client/common"
)
@@ -2293,13 +2315,17 @@ func main() {
chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
- common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)
if err != nil {
panic(err)
}
+ gasPrice := chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
+
ctx := context.Background()
marketsAssistant, err := chainclient.NewMarketsAssistant(ctx, chainClient)
if err != nil {
@@ -2365,6 +2391,11 @@ func main() {
}
fmt.Println("gas fee:", gasFee, "INJ")
+
+ gasPrice = chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
}
```
@@ -2531,7 +2562,7 @@ import dotenv
from grpc import RpcError
from pyinjective.async_client import AsyncClient
-from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
+from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT
from pyinjective.core.network import Network
from pyinjective.transaction import Transaction
from pyinjective.wallet import PrivateKey
@@ -2596,7 +2627,10 @@ async def main() -> None:
print(sim_res_msg)
# build tx
- gas_price = GAS_PRICE
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+
gas_limit = int(sim_res["gasInfo"]["gasUsed"]) + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
fee = [
@@ -2639,7 +2673,6 @@ import (
"github.com/shopspring/decimal"
exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types"
- "github.com/InjectiveLabs/sdk-go/client"
chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
"github.com/InjectiveLabs/sdk-go/client/common"
)
@@ -2680,13 +2713,17 @@ func main() {
chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
- common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)
if err != nil {
panic(err)
}
+ gasPrice := chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
+
ctx := context.Background()
marketsAssistant, err := chainclient.NewMarketsAssistant(ctx, chainClient)
if err != nil {
@@ -2750,6 +2787,11 @@ func main() {
}
fmt.Println("gas fee:", gasFee, "INJ")
+
+ gasPrice = chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
}
```
@@ -2913,7 +2955,7 @@ import dotenv
from grpc import RpcError
from pyinjective.async_client import AsyncClient
-from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
+from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT
from pyinjective.core.network import Network
from pyinjective.transaction import Transaction
from pyinjective.wallet import PrivateKey
@@ -2967,7 +3009,10 @@ async def main() -> None:
return
# build tx
- gas_price = GAS_PRICE
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+
gas_limit = int(sim_res["gasInfo"]["gasUsed"]) + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
fee = [
@@ -3003,8 +3048,6 @@ import (
"os"
"time"
- "github.com/InjectiveLabs/sdk-go/client"
-
"github.com/InjectiveLabs/sdk-go/client/common"
exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types"
@@ -3048,13 +3091,17 @@ func main() {
chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
- common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)
if err != nil {
panic(err)
}
+ gasPrice := chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
+
msg := &exchangetypes.MsgCancelSpotOrder{
Sender: senderAddress.String(),
MarketId: "0xa508cb32923323679f29a032c70342c147c17d0145625922b0ef22e955c844c0",
@@ -3079,6 +3126,11 @@ func main() {
}
fmt.Println("gas fee:", gasFee, "INJ")
+
+ gasPrice = chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
}
```
@@ -3208,7 +3260,7 @@ import dotenv
from grpc import RpcError
from pyinjective.async_client import AsyncClient
-from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
+from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT
from pyinjective.core.network import Network
from pyinjective.transaction import Transaction
from pyinjective.wallet import PrivateKey
@@ -3351,7 +3403,10 @@ async def main() -> None:
print(sim_res_msg)
# build tx
- gas_price = GAS_PRICE
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+
gas_limit = int(sim_res["gasInfo"]["gasUsed"]) + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
fee = [
@@ -3394,7 +3449,6 @@ import (
"github.com/shopspring/decimal"
exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types"
- "github.com/InjectiveLabs/sdk-go/client"
chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
"github.com/InjectiveLabs/sdk-go/client/common"
)
@@ -3436,7 +3490,6 @@ func main() {
chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
- common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)
if err != nil {
@@ -3444,6 +3497,11 @@ func main() {
return
}
+ gasPrice := chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
+
ctx := context.Background()
marketsAssistant, err := chainclient.NewMarketsAssistant(ctx, chainClient)
if err != nil {
@@ -3531,6 +3589,11 @@ func main() {
}
fmt.Println("gas fee:", gasFee, "INJ")
+
+ gasPrice = chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
}
```
@@ -3747,6 +3810,7 @@ Modifies certain market fields. It can only be sent by the market's admin.
```py
import asyncio
+import json
import os
from decimal import Decimal
@@ -3769,11 +3833,17 @@ async def main() -> None:
client = AsyncClient(network)
await client.initialize_tokens_from_chain_denoms()
composer = await client.composer()
- await client.sync_timeout_height()
+
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
message_broadcaster = MsgBroadcasterWithPk.new_using_simulation(
network=network,
private_key=configured_private_key,
+ gas_price=gas_price,
+ client=client,
+ composer=composer,
)
# load account
@@ -3795,7 +3865,12 @@ async def main() -> None:
# broadcast the transaction
result = await message_broadcaster.broadcast([message])
print("---Transaction Response---")
- print(result)
+ print(json.dumps(result, indent=2))
+
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+ message_broadcaster.update_gas_price(gas_price=gas_price)
if __name__ == "__main__":
@@ -3817,7 +3892,6 @@ import (
rpchttp "github.com/cometbft/cometbft/rpc/client/http"
exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types"
- "github.com/InjectiveLabs/sdk-go/client"
chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
"github.com/InjectiveLabs/sdk-go/client/common"
)
@@ -3858,12 +3932,16 @@ func main() {
chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
- common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)
if err != nil {
panic(err)
}
+ gasPrice := chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
+
minPriceTickSize := math.LegacyMustNewDecFromStr("0.01")
minQuantityTickSize := math.LegacyMustNewDecFromStr("0.01")
minNotional := math.LegacyMustNewDecFromStr("2")
@@ -3892,6 +3970,11 @@ func main() {
str, _ := json.MarshalIndent(response, "", " ")
fmt.Print(string(str))
+
+ gasPrice = chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
}
```
@@ -4017,7 +4100,7 @@ from decimal import Decimal
import dotenv
from pyinjective.async_client import AsyncClient
-from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
+from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT
from pyinjective.core.network import Network
from pyinjective.orderhash import OrderHashManager
from pyinjective.transaction import Transaction
@@ -4122,7 +4205,11 @@ async def main() -> None:
.with_account_num(client.get_number())
.with_chain_id(network.chain_id)
)
- gas_price = GAS_PRICE
+
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+
base_gas = 85000
gas_limit = base_gas + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
@@ -4159,7 +4246,11 @@ async def main() -> None:
.with_account_num(client.get_number())
.with_chain_id(network.chain_id)
)
- gas_price = GAS_PRICE
+
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+
base_gas = 85000
gas_limit = base_gas + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
@@ -4251,7 +4342,11 @@ async def main() -> None:
.with_account_num(client.get_number())
.with_chain_id(network.chain_id)
)
- gas_price = GAS_PRICE
+
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+
base_gas = 85000
gas_limit = base_gas + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
@@ -4294,7 +4389,6 @@ import (
"github.com/shopspring/decimal"
exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types"
- "github.com/InjectiveLabs/sdk-go/client"
chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
"github.com/InjectiveLabs/sdk-go/client/common"
)
@@ -4335,13 +4429,17 @@ func main() {
chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
- common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)
if err != nil {
panic(err)
}
+ gasPrice := chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
+
ctx := context.Background()
marketsAssistant, err := chainclient.NewMarketsAssistant(ctx, chainClient)
if err != nil {
@@ -4413,6 +4511,11 @@ func main() {
}
fmt.Println("gas fee:", gasFee, "INJ")
+
+ gasPrice = chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
}
```
diff --git a/source/includes/_staking.md b/source/includes/_staking.md
index eec491a7..f1892525 100644
--- a/source/includes/_staking.md
+++ b/source/includes/_staking.md
@@ -1350,6 +1350,7 @@ Changes the withdraw address for a delegator (or validator self-delegation)
```py
import asyncio
+import json
import os
import dotenv
@@ -1368,9 +1369,14 @@ async def main() -> None:
client = AsyncClient(network)
composer = await client.composer()
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+
message_broadcaster = MsgBroadcasterWithPk.new_without_simulation(
network=network,
private_key=configured_private_key,
+ gas_price=gas_price,
client=client,
composer=composer,
)
@@ -1390,7 +1396,12 @@ async def main() -> None:
# broadcast the transaction
result = await message_broadcaster.broadcast([message])
print("---Transaction Response---")
- print(result)
+ print(json.dumps(result, indent=2))
+
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+ message_broadcaster.update_gas_price(gas_price=gas_price)
if __name__ == "__main__":
@@ -1408,12 +1419,11 @@ import (
"fmt"
"os"
+ rpchttp "github.com/cometbft/cometbft/rpc/client/http"
"github.com/cosmos/cosmos-sdk/x/distribution/types"
- "github.com/InjectiveLabs/sdk-go/client"
chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
"github.com/InjectiveLabs/sdk-go/client/common"
- rpchttp "github.com/cometbft/cometbft/rpc/client/http"
)
func main() {
@@ -1452,13 +1462,17 @@ func main() {
chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
- common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)
if err != nil {
panic(err)
}
+ gasPrice := chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
+
withdrawAddress := "inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r"
msg := &types.MsgSetWithdrawAddress{
@@ -1475,6 +1489,11 @@ func main() {
str, _ := json.MarshalIndent(response, "", " ")
fmt.Print(string(str))
+
+ gasPrice = chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
}
```
@@ -1576,6 +1595,7 @@ Withdraw rewards of a delegator
```py
import asyncio
+import json
import os
import dotenv
@@ -1595,9 +1615,14 @@ async def main() -> None:
client = AsyncClient(network)
composer = await client.composer()
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+
message_broadcaster = MsgBroadcasterWithPk.new_without_simulation(
network=network,
private_key=configured_private_key,
+ gas_price=gas_price,
client=client,
composer=composer,
)
@@ -1617,7 +1642,12 @@ async def main() -> None:
# broadcast the transaction
result = await message_broadcaster.broadcast([message])
print("---Transaction Response---")
- print(result)
+ print(json.dumps(result, indent=2))
+
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+ message_broadcaster.update_gas_price(gas_price=gas_price)
if __name__ == "__main__":
@@ -1635,12 +1665,11 @@ import (
"os"
"time"
- "github.com/InjectiveLabs/sdk-go/client"
- "github.com/InjectiveLabs/sdk-go/client/common"
-
- chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
rpchttp "github.com/cometbft/cometbft/rpc/client/http"
distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
+
+ chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
+ "github.com/InjectiveLabs/sdk-go/client/common"
)
func main() {
@@ -1679,13 +1708,17 @@ func main() {
chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
- common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)
if err != nil {
panic(err)
}
+ gasPrice := chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
+
msg := new(distributiontypes.MsgWithdrawDelegatorReward)
msg.DelegatorAddress = senderAddress.String()
msg.ValidatorAddress = "injvaloper14gy4acwjm96wd20awm9ar6j54lev5p7espy9ug"
@@ -1707,6 +1740,11 @@ func main() {
}
fmt.Println("gas fee:", gasFee, "INJ")
+
+ gasPrice = chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
}
```
@@ -1820,6 +1858,7 @@ Withdraws the full commission to the validator address
```py
import asyncio
+import json
import os
import dotenv
@@ -1839,9 +1878,14 @@ async def main() -> None:
client = AsyncClient(network)
composer = await client.composer()
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+
message_broadcaster = MsgBroadcasterWithPk.new_without_simulation(
network=network,
private_key=configured_private_key,
+ gas_price=gas_price,
client=client,
composer=composer,
)
@@ -1859,7 +1903,12 @@ async def main() -> None:
# broadcast the transaction
result = await message_broadcaster.broadcast([message])
print("---Transaction Response---")
- print(result)
+ print(json.dumps(result, indent=2))
+
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+ message_broadcaster.update_gas_price(gas_price=gas_price)
if __name__ == "__main__":
@@ -1877,12 +1926,11 @@ import (
"fmt"
"os"
+ rpchttp "github.com/cometbft/cometbft/rpc/client/http"
"github.com/cosmos/cosmos-sdk/x/distribution/types"
- "github.com/InjectiveLabs/sdk-go/client"
chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
"github.com/InjectiveLabs/sdk-go/client/common"
- rpchttp "github.com/cometbft/cometbft/rpc/client/http"
)
func main() {
@@ -1921,13 +1969,17 @@ func main() {
chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
- common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)
if err != nil {
panic(err)
}
+ gasPrice := chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
+
validatorAddress := "injvaloper1ultw9r29l8nxy5u6thcgusjn95vsy2caw722q5"
msg := &types.MsgWithdrawValidatorCommission{
@@ -1943,6 +1995,11 @@ func main() {
str, _ := json.MarshalIndent(response, "", " ")
fmt.Print(string(str))
+
+ gasPrice = chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
}
```
@@ -2043,6 +2100,7 @@ Allows an account to directly fund the community pool
```py
import asyncio
+import json
import os
from decimal import Decimal
@@ -2062,9 +2120,14 @@ async def main() -> None:
client = AsyncClient(network)
composer = await client.composer()
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+
message_broadcaster = MsgBroadcasterWithPk.new_without_simulation(
network=network,
private_key=configured_private_key,
+ gas_price=gas_price,
client=client,
composer=composer,
)
@@ -2084,7 +2147,12 @@ async def main() -> None:
# broadcast the transaction
result = await message_broadcaster.broadcast([message])
print("---Transaction Response---")
- print(result)
+ print(json.dumps(result, indent=2))
+
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+ message_broadcaster.update_gas_price(gas_price=gas_price)
if __name__ == "__main__":
@@ -2103,14 +2171,12 @@ import (
"os"
"cosmossdk.io/math"
-
+ rpchttp "github.com/cometbft/cometbft/rpc/client/http"
"github.com/cosmos/cosmos-sdk/types"
distriutiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
- "github.com/InjectiveLabs/sdk-go/client"
chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
"github.com/InjectiveLabs/sdk-go/client/common"
- rpchttp "github.com/cometbft/cometbft/rpc/client/http"
)
func main() {
@@ -2149,13 +2215,17 @@ func main() {
chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
- common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)
if err != nil {
panic(err)
}
+ gasPrice := chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
+
amount := types.NewCoin("inj", math.NewInt(1))
msg := &distriutiontypes.MsgFundCommunityPool{
@@ -2172,6 +2242,11 @@ func main() {
str, _ := json.MarshalIndent(response, "", " ")
fmt.Print(string(str))
+
+ gasPrice = chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
}
```
@@ -2288,7 +2363,7 @@ import dotenv
from grpc import RpcError
from pyinjective.async_client import AsyncClient
-from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
+from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT
from pyinjective.core.network import Network
from pyinjective.transaction import Transaction
from pyinjective.wallet import PrivateKey
@@ -2340,7 +2415,10 @@ async def main() -> None:
return
# build tx
- gas_price = GAS_PRICE
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+
gas_limit = int(sim_res["gasInfo"]["gasUsed"]) + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
fee = [
@@ -2377,8 +2455,6 @@ import (
"time"
"cosmossdk.io/math"
-
- "github.com/InjectiveLabs/sdk-go/client"
"github.com/InjectiveLabs/sdk-go/client/common"
chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
@@ -2423,13 +2499,17 @@ func main() {
chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
- common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)
if err != nil {
panic(err)
}
+ gasPrice := chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
+
msg := new(stakingtypes.MsgDelegate)
msg.DelegatorAddress = senderAddress.String()
msg.ValidatorAddress = "injvaloper14gy4acwjm96wd20awm9ar6j54lev5p7espy9ug"
@@ -2454,6 +2534,11 @@ func main() {
}
fmt.Println("gas fee:", gasFee, "INJ")
+
+ gasPrice = chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
}
```
diff --git a/source/includes/_tokenfactory.md b/source/includes/_tokenfactory.md
index 2060ef64..d967f542 100644
--- a/source/includes/_tokenfactory.md
+++ b/source/includes/_tokenfactory.md
@@ -614,11 +614,12 @@ Create a new denom
```py
import asyncio
+import json
import os
import dotenv
-from pyinjective.composer import Composer as ProtoMsgComposer
+from pyinjective.async_client import AsyncClient
from pyinjective.core.broadcaster import MsgBroadcasterWithPk
from pyinjective.core.network import Network
from pyinjective.wallet import PrivateKey
@@ -630,11 +631,20 @@ async def main() -> None:
# select network: local, testnet, mainnet
network = Network.testnet()
- composer = ProtoMsgComposer(network=network.string())
+
+ client = AsyncClient(network)
+ composer = await client.composer()
+
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
message_broadcaster = MsgBroadcasterWithPk.new_using_simulation(
network=network,
private_key=private_key_in_hexa,
+ gas_price=gas_price,
+ client=client,
+ composer=composer,
)
priv_key = PrivateKey.from_hex(private_key_in_hexa)
@@ -653,7 +663,12 @@ async def main() -> None:
# broadcast the transaction
result = await message_broadcaster.broadcast([message])
print("---Transaction Response---")
- print(result)
+ print(json.dumps(result, indent=2))
+
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+ message_broadcaster.update_gas_price(gas_price=gas_price)
if __name__ == "__main__":
@@ -672,7 +687,6 @@ import (
"os"
tokenfactorytypes "github.com/InjectiveLabs/sdk-go/chain/tokenfactory/types"
- "github.com/InjectiveLabs/sdk-go/client"
chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
"github.com/InjectiveLabs/sdk-go/client/common"
rpchttp "github.com/cometbft/cometbft/rpc/client/http"
@@ -713,13 +727,17 @@ func main() {
chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
- common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)
if err != nil {
panic(err)
}
+ gasPrice := chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
+
message := new(tokenfactorytypes.MsgCreateDenom)
message.Sender = senderAddress.String()
message.Subdenom = "inj_test"
@@ -736,6 +754,11 @@ func main() {
str, _ := json.MarshalIndent(response, "", " ")
fmt.Print(string(str))
+
+ gasPrice = chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
}
```
@@ -843,11 +866,12 @@ Allows a token admin's account to mint more units
```py
import asyncio
+import json
import os
import dotenv
-from pyinjective.composer import Composer as ProtoMsgComposer
+from pyinjective.async_client import AsyncClient
from pyinjective.core.broadcaster import MsgBroadcasterWithPk
from pyinjective.core.network import Network
from pyinjective.wallet import PrivateKey
@@ -859,11 +883,20 @@ async def main() -> None:
# select network: local, testnet, mainnet
network = Network.testnet()
- composer = ProtoMsgComposer(network=network.string())
+
+ client = AsyncClient(network)
+ composer = await client.composer()
+
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
message_broadcaster = MsgBroadcasterWithPk.new_using_simulation(
network=network,
private_key=private_key_in_hexa,
+ gas_price=gas_price,
+ client=client,
+ composer=composer,
)
priv_key = PrivateKey.from_hex(private_key_in_hexa)
@@ -881,7 +914,12 @@ async def main() -> None:
# broadcast the transaction
result = await message_broadcaster.broadcast([message])
print("---Transaction Response---")
- print(result)
+ print(json.dumps(result, indent=2))
+
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+ message_broadcaster.update_gas_price(gas_price=gas_price)
if __name__ == "__main__":
@@ -902,7 +940,6 @@ import (
"cosmossdk.io/math"
tokenfactorytypes "github.com/InjectiveLabs/sdk-go/chain/tokenfactory/types"
- "github.com/InjectiveLabs/sdk-go/client"
chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
"github.com/InjectiveLabs/sdk-go/client/common"
rpchttp "github.com/cometbft/cometbft/rpc/client/http"
@@ -944,13 +981,17 @@ func main() {
chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
- common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)
if err != nil {
panic(err)
}
+ gasPrice := chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
+
message := new(tokenfactorytypes.MsgMint)
message.Sender = senderAddress.String()
message.Amount = sdktypes.Coin{
@@ -967,6 +1008,11 @@ func main() {
str, _ := json.MarshalIndent(response, "", " ")
fmt.Print(string(str))
+
+ gasPrice = chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
}
```
@@ -1080,11 +1126,12 @@ Allows a token admin's account to burn circulating units
```py
import asyncio
+import json
import os
import dotenv
-from pyinjective.composer import Composer as ProtoMsgComposer
+from pyinjective.async_client import AsyncClient
from pyinjective.core.broadcaster import MsgBroadcasterWithPk
from pyinjective.core.network import Network
from pyinjective.wallet import PrivateKey
@@ -1096,11 +1143,20 @@ async def main() -> None:
# select network: local, testnet, mainnet
network = Network.testnet()
- composer = ProtoMsgComposer(network=network.string())
+
+ client = AsyncClient(network)
+ composer = await client.composer()
+
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
message_broadcaster = MsgBroadcasterWithPk.new_using_simulation(
network=network,
private_key=private_key_in_hexa,
+ gas_price=gas_price,
+ client=client,
+ composer=composer,
)
priv_key = PrivateKey.from_hex(private_key_in_hexa)
@@ -1118,7 +1174,12 @@ async def main() -> None:
# broadcast the transaction
result = await message_broadcaster.broadcast([message])
print("---Transaction Response---")
- print(result)
+ print(json.dumps(result, indent=2))
+
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+ message_broadcaster.update_gas_price(gas_price=gas_price)
if __name__ == "__main__":
@@ -1139,7 +1200,6 @@ import (
"cosmossdk.io/math"
tokenfactorytypes "github.com/InjectiveLabs/sdk-go/chain/tokenfactory/types"
- "github.com/InjectiveLabs/sdk-go/client"
chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
"github.com/InjectiveLabs/sdk-go/client/common"
rpchttp "github.com/cometbft/cometbft/rpc/client/http"
@@ -1181,13 +1241,17 @@ func main() {
chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
- common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)
if err != nil {
panic(err)
}
+ gasPrice := chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
+
message := new(tokenfactorytypes.MsgBurn)
message.Sender = senderAddress.String()
message.Amount = sdktypes.Coin{
@@ -1204,6 +1268,11 @@ func main() {
str, _ := json.MarshalIndent(response, "", " ")
fmt.Print(string(str))
+
+ gasPrice = chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
}
```
@@ -1317,11 +1386,12 @@ Allows a token admin's account to set the token metadata
```py
import asyncio
+import json
import os
import dotenv
-from pyinjective.composer import Composer as ProtoMsgComposer
+from pyinjective.async_client import AsyncClient
from pyinjective.core.broadcaster import MsgBroadcasterWithPk
from pyinjective.core.network import Network
from pyinjective.wallet import PrivateKey
@@ -1333,11 +1403,20 @@ async def main() -> None:
# select network: local, testnet, mainnet
network = Network.testnet()
- composer = ProtoMsgComposer(network=network.string())
+
+ client = AsyncClient(network)
+ composer = await client.composer()
+
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
message_broadcaster = MsgBroadcasterWithPk.new_without_simulation(
network=network,
private_key=private_key_in_hexa,
+ gas_price=gas_price,
+ client=client,
+ composer=composer,
)
priv_key = PrivateKey.from_hex(private_key_in_hexa)
@@ -1369,7 +1448,12 @@ async def main() -> None:
# broadcast the transaction
result = await message_broadcaster.broadcast([message])
print("---Transaction Response---")
- print(result)
+ print(json.dumps(result, indent=2))
+
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+ message_broadcaster.update_gas_price(gas_price=gas_price)
if __name__ == "__main__":
@@ -1387,12 +1471,12 @@ import (
"fmt"
"os"
+ rpchttp "github.com/cometbft/cometbft/rpc/client/http"
+ banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
+
tokenfactorytypes "github.com/InjectiveLabs/sdk-go/chain/tokenfactory/types"
- "github.com/InjectiveLabs/sdk-go/client"
chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
"github.com/InjectiveLabs/sdk-go/client/common"
- rpchttp "github.com/cometbft/cometbft/rpc/client/http"
- banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
)
func main() {
@@ -1430,13 +1514,17 @@ func main() {
chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
- common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)
if err != nil {
panic(err)
}
+ gasPrice := chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
+
denom := "factory/inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r/inj_test"
subdenom := "inj_test"
tokenDecimals := uint32(6)
@@ -1477,6 +1565,11 @@ func main() {
str, _ := json.MarshalIndent(response, "", " ")
fmt.Print(string(str))
+
+ gasPrice = chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
}
```
@@ -1608,11 +1701,12 @@ Allows a token admin's account to transfer administrative privileged to other ac
```py
import asyncio
+import json
import os
import dotenv
-from pyinjective.composer import Composer as ProtoMsgComposer
+from pyinjective.async_client import AsyncClient
from pyinjective.core.broadcaster import MsgBroadcasterWithPk
from pyinjective.core.network import Network
from pyinjective.wallet import PrivateKey
@@ -1624,11 +1718,20 @@ async def main() -> None:
# select network: local, testnet, mainnet
network = Network.testnet()
- composer = ProtoMsgComposer(network=network.string())
+
+ client = AsyncClient(network)
+ composer = await client.composer()
+
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
message_broadcaster = MsgBroadcasterWithPk.new_without_simulation(
network=network,
private_key=private_key_in_hexa,
+ gas_price=gas_price,
+ client=client,
+ composer=composer,
)
priv_key = PrivateKey.from_hex(private_key_in_hexa)
@@ -1644,7 +1747,12 @@ async def main() -> None:
# broadcast the transaction
result = await message_broadcaster.broadcast([message])
print("---Transaction Response---")
- print(result)
+ print(json.dumps(result, indent=2))
+
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+ message_broadcaster.update_gas_price(gas_price=gas_price)
if __name__ == "__main__":
@@ -1662,11 +1770,11 @@ import (
"fmt"
"os"
+ rpchttp "github.com/cometbft/cometbft/rpc/client/http"
+
tokenfactorytypes "github.com/InjectiveLabs/sdk-go/chain/tokenfactory/types"
- "github.com/InjectiveLabs/sdk-go/client"
chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
"github.com/InjectiveLabs/sdk-go/client/common"
- rpchttp "github.com/cometbft/cometbft/rpc/client/http"
)
func main() {
@@ -1704,13 +1812,17 @@ func main() {
chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
- common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)
if err != nil {
panic(err)
}
+ gasPrice := chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
+
message := new(tokenfactorytypes.MsgChangeAdmin)
message.Sender = senderAddress.String()
message.Denom = "factory/inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r/inj_test"
@@ -1726,6 +1838,11 @@ func main() {
str, _ := json.MarshalIndent(response, "", " ")
fmt.Print(string(str))
+
+ gasPrice = chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
}
```
diff --git a/source/includes/_txfees.md b/source/includes/_txfees.md
index 0955a4a1..3def2a0c 100644
--- a/source/includes/_txfees.md
+++ b/source/includes/_txfees.md
@@ -1,4 +1,4 @@
-# - Chain TXFees
+# - TXFees
The txfees module for Injective provides the required functionality to support fee market as per EIP-1559.
@@ -13,9 +13,100 @@ Retrieves the current chain gas price
> Request Example:
+
+```py
+import asyncio
+import json
+
+from pyinjective.async_client import AsyncClient
+from pyinjective.core.network import Network
+
+
+async def main() -> None:
+ network = Network.testnet()
+ client = AsyncClient(network)
+ metadata = await client.fetch_eip_base_fee()
+ print(json.dumps(metadata, indent=2))
+
+
+if __name__ == "__main__":
+ asyncio.get_event_loop().run_until_complete(main())
+```
+
+```go
+package main
+
+import (
+ "context"
+ "encoding/json"
+ "fmt"
+
+ "os"
+
+ "github.com/InjectiveLabs/sdk-go/client"
+ chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
+ "github.com/InjectiveLabs/sdk-go/client/common"
+ rpchttp "github.com/cometbft/cometbft/rpc/client/http"
+)
+
+func main() {
+ network := common.LoadNetwork("testnet", "lb")
+ tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket")
+ if err != nil {
+ panic(err)
+ }
+
+ senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring(
+ os.Getenv("HOME")+"/.injectived",
+ "injectived",
+ "file",
+ "inj-user",
+ "12345678",
+ "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided
+ false,
+ )
+
+ if err != nil {
+ panic(err)
+ }
+
+ clientCtx, err := chainclient.NewClientContext(
+ network.ChainId,
+ senderAddress.String(),
+ cosmosKeyring,
+ )
+
+ if err != nil {
+ panic(err)
+ }
+
+ clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient)
+
+ chainClient, err := chainclient.NewChainClient(
+ clientCtx,
+ network,
+ common.OptionGasPrices(client.DefaultGasPriceWithDenom),
+ )
+
+ if err != nil {
+ panic(err)
+ }
+
+ ctx := context.Background()
+
+ res, err := chainClient.FetchEipBaseFee(ctx)
+ if err != nil {
+ fmt.Println(err)
+ }
+
+ str, _ := json.MarshalIndent(res, "", " ")
+ fmt.Print(string(str))
+
+}
+```
No parameters
@@ -32,6 +123,7 @@ No parameters
```
+| Parameter | Type | Description |
|---|
| base_fee | EipBaseFee | The current chain gas price |
@@ -39,4 +131,5 @@ No parameters
**EipBaseFee**
+| Parameter | Type | Description |
|---|
| base_fee | Decimal | The current chain gas price |
diff --git a/source/includes/_wasm.md b/source/includes/_wasm.md
index 8639ba0e..1809959e 100644
--- a/source/includes/_wasm.md
+++ b/source/includes/_wasm.md
@@ -1721,7 +1721,7 @@ import dotenv
from grpc import RpcError
from pyinjective.async_client import AsyncClient
-from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
+from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT
from pyinjective.core.network import Network
from pyinjective.transaction import Transaction
from pyinjective.wallet import PrivateKey
@@ -1783,7 +1783,10 @@ async def main() -> None:
return
# build tx
- gas_price = GAS_PRICE
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+
gas_limit = int(sim_res["gasInfo"]["gasUsed"]) + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
fee = [
diff --git a/source/includes/_wasmx.md b/source/includes/_wasmx.md
index 02257ff0..2986e769 100644
--- a/source/includes/_wasmx.md
+++ b/source/includes/_wasmx.md
@@ -21,7 +21,7 @@ import dotenv
from grpc import RpcError
from pyinjective.async_client import AsyncClient
-from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
+from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT
from pyinjective.core.network import Network
from pyinjective.transaction import Transaction
from pyinjective.wallet import PrivateKey
@@ -79,7 +79,10 @@ async def main() -> None:
return
# build tx
- gas_price = GAS_PRICE
+ gas_price = await client.current_chain_gas_price()
+ # adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gas_price = int(gas_price * 1.1)
+
gas_limit = int(sim_res["gasInfo"]["gasUsed"]) + GAS_FEE_BUFFER_AMOUNT # add buffer for gas fee computation
gas_fee = "{:.18f}".format((gas_price * gas_limit) / pow(10, 18)).rstrip("0")
fee = [
@@ -115,11 +118,11 @@ import (
"fmt"
"os"
+ rpchttp "github.com/cometbft/cometbft/rpc/client/http"
+
wasmxtypes "github.com/InjectiveLabs/sdk-go/chain/wasmx/types"
- "github.com/InjectiveLabs/sdk-go/client"
chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
"github.com/InjectiveLabs/sdk-go/client/common"
- rpchttp "github.com/cometbft/cometbft/rpc/client/http"
)
func main() {
@@ -157,13 +160,17 @@ func main() {
chainClient, err := chainclient.NewChainClient(
clientCtx,
network,
- common.OptionGasPrices(client.DefaultGasPriceWithDenom),
)
if err != nil {
panic(err)
}
+ gasPrice := chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
+
firstAmount := 69
firstToken := "factory/inj1hdvy6tl89llqy3ze8lv6mz5qh66sx9enn0jxg6/inj12ngevx045zpvacus9s6anr258gkwpmthnz80e9"
secondAmount := 420
@@ -196,6 +203,11 @@ func main() {
str, _ := json.MarshalIndent(response, "", " ")
fmt.Println(string(str))
+
+ gasPrice = chainClient.CurrentChainGasPrice()
+ // adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
+ gasPrice = int64(float64(gasPrice) * 1.1)
+ chainClient.SetGasPrice(gasPrice)
}
```