Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 83 additions & 34 deletions source/includes/_account.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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",
Expand All @@ -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)
}
```
<!-- MARKDOWN-AUTO-DOCS:END -->
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand All @@ -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)
}
```
<!-- MARKDOWN-AUTO-DOCS:END -->
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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",
Expand All @@ -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)
}
```
<!-- MARKDOWN-AUTO-DOCS:END -->
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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",
Expand All @@ -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)
}
```
<!-- MARKDOWN-AUTO-DOCS:END -->
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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)
}
```
<!-- MARKDOWN-AUTO-DOCS:END -->
Expand Down
Loading
Loading