Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/use dot env in examples #301

Merged
merged 2 commits into from
Feb 6, 2024
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
7 changes: 6 additions & 1 deletion examples/SendToInjective.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import asyncio
import json
import os

import dotenv

from pyinjective.core.network import Network
from pyinjective.sendtocosmos import Peggo


async def main() -> None:
dotenv.load_dotenv()
private_key = os.getenv("INJECTIVE_PRIVATE_KEY")

# select network: testnet, mainnet
network = Network.testnet()
peggo_composer = Peggo(network=network.string())

private_key = "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e"
ethereum_endpoint = "https://eth-goerli.g.alchemy.com/v2/q-7JVv4mTfsNh1y_djKkKn3maRBGILLL"

maxFeePerGas_Gwei = 4
Expand Down
8 changes: 7 additions & 1 deletion examples/chain_client/0_LocalOrderHash.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import asyncio
import os
import uuid

import dotenv

from pyinjective.async_client import AsyncClient
from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
from pyinjective.core.network import Network
Expand All @@ -10,6 +13,9 @@


async def main() -> None:
dotenv.load_dotenv()
configured_private_key = os.getenv("INJECTIVE_PRIVATE_KEY")

# select network: local, testnet, mainnet
network = Network.testnet()

Expand All @@ -19,7 +25,7 @@ async def main() -> None:
await client.sync_timeout_height()

# load account
priv_key = PrivateKey.from_hex("f9db9bf330e23cb7839039e944adef6e9df447b90b503d5b4464c90bea9022f3")
priv_key = PrivateKey.from_hex(configured_private_key)
pub_key = priv_key.to_public_key()
address = pub_key.to_address()
await client.fetch_account(address.to_acc_bech32())
Expand Down
7 changes: 6 additions & 1 deletion examples/chain_client/13_MsgIncreasePositionMargin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import asyncio
import os

import dotenv
from grpc import RpcError

from pyinjective.async_client import AsyncClient
Expand All @@ -10,6 +12,9 @@


async def main() -> None:
dotenv.load_dotenv()
configured_private_key = os.getenv("INJECTIVE_PRIVATE_KEY")

# select network: local, testnet, mainnet
network = Network.testnet()

Expand All @@ -19,7 +24,7 @@ async def main() -> None:
await client.sync_timeout_height()

# load account
priv_key = PrivateKey.from_hex("f9db9bf330e23cb7839039e944adef6e9df447b90b503d5b4464c90bea9022f3")
priv_key = PrivateKey.from_hex(configured_private_key)
pub_key = priv_key.to_public_key()
address = pub_key.to_address()
await client.fetch_account(address.to_acc_bech32())
Expand Down
7 changes: 6 additions & 1 deletion examples/chain_client/15_MsgWithdraw.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import asyncio
import os

import dotenv
from grpc import RpcError

from pyinjective.async_client import AsyncClient
Expand All @@ -10,6 +12,9 @@


async def main() -> None:
dotenv.load_dotenv()
configured_private_key = os.getenv("INJECTIVE_PRIVATE_KEY")

# select network: local, testnet, mainnet
network = Network.testnet()

Expand All @@ -19,7 +24,7 @@ async def main() -> None:
await client.sync_timeout_height()

# load account
priv_key = PrivateKey.from_hex("f9db9bf330e23cb7839039e944adef6e9df447b90b503d5b4464c90bea9022f3")
priv_key = PrivateKey.from_hex(configured_private_key)
pub_key = priv_key.to_public_key()
address = pub_key.to_address()
await client.fetch_account(address.to_acc_bech32())
Expand Down
7 changes: 6 additions & 1 deletion examples/chain_client/16_MsgSubaccountTransfer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import asyncio
import os

import dotenv
from grpc import RpcError

from pyinjective.async_client import AsyncClient
Expand All @@ -10,6 +12,9 @@


async def main() -> None:
dotenv.load_dotenv()
configured_private_key = os.getenv("INJECTIVE_PRIVATE_KEY")

# select network: local, testnet, mainnet
network = Network.testnet()

Expand All @@ -19,7 +24,7 @@ async def main() -> None:
await client.sync_timeout_height()

# load account
priv_key = PrivateKey.from_hex("f9db9bf330e23cb7839039e944adef6e9df447b90b503d5b4464c90bea9022f3")
priv_key = PrivateKey.from_hex(configured_private_key)
pub_key = priv_key.to_public_key()
address = pub_key.to_address()
await client.fetch_account(address.to_acc_bech32())
Expand Down
7 changes: 6 additions & 1 deletion examples/chain_client/17_MsgBatchUpdateOrders.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import asyncio
import os
import uuid

import dotenv
from grpc import RpcError

from pyinjective.async_client import AsyncClient
Expand All @@ -11,6 +13,9 @@


async def main() -> None:
dotenv.load_dotenv()
configured_private_key = os.getenv("INJECTIVE_PRIVATE_KEY")

# select network: local, testnet, mainnet
network = Network.testnet()

Expand All @@ -20,7 +25,7 @@ async def main() -> None:
await client.sync_timeout_height()

# load account
priv_key = PrivateKey.from_hex("f9db9bf330e23cb7839039e944adef6e9df447b90b503d5b4464c90bea9022f3")
priv_key = PrivateKey.from_hex(configured_private_key)
pub_key = priv_key.to_public_key()
address = pub_key.to_address()
await client.fetch_account(address.to_acc_bech32())
Expand Down
7 changes: 6 additions & 1 deletion examples/chain_client/18_MsgBid.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import asyncio
import os

import dotenv
from grpc import RpcError

from pyinjective.async_client import AsyncClient
Expand All @@ -10,6 +12,9 @@


async def main() -> None:
dotenv.load_dotenv()
configured_private_key = os.getenv("INJECTIVE_PRIVATE_KEY")

# select network: local, testnet, mainnet
network = Network.testnet()

Expand All @@ -19,7 +24,7 @@ async def main() -> None:
await client.sync_timeout_height()

# load account
priv_key = PrivateKey.from_hex("f9db9bf330e23cb7839039e944adef6e9df447b90b503d5b4464c90bea9022f3")
priv_key = PrivateKey.from_hex(configured_private_key)
pub_key = priv_key.to_public_key()
address = pub_key.to_address()
await client.fetch_account(address.to_acc_bech32())
Expand Down
12 changes: 9 additions & 3 deletions examples/chain_client/19_MsgGrant.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import asyncio
import os

import dotenv
from grpc import RpcError

from pyinjective.async_client import AsyncClient
Expand All @@ -10,6 +12,10 @@


async def main() -> None:
dotenv.load_dotenv()
configured_private_key = os.getenv("INJECTIVE_PRIVATE_KEY")
grantee_public_address = os.getenv("INJECTIVE_GRANTEE_PUBLIC_ADDRESS")

# select network: local, testnet, mainnet
network = Network.testnet()

Expand All @@ -19,7 +25,7 @@ async def main() -> None:
await client.sync_timeout_height()

# load account
priv_key = PrivateKey.from_hex("f9db9bf330e23cb7839039e944adef6e9df447b90b503d5b4464c90bea9022f3")
priv_key = PrivateKey.from_hex(configured_private_key)
pub_key = priv_key.to_public_key()
address = pub_key.to_address()
await client.fetch_account(address.to_acc_bech32())
Expand All @@ -30,8 +36,8 @@ async def main() -> None:

# GENERIC AUTHZ
msg = composer.MsgGrantGeneric(
granter="inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r",
grantee="inj14au322k9munkmx5wrchz9q30juf5wjgz2cfqku",
granter=address.to_acc_bech32(),
grantee=grantee_public_address,
msg_type="/injective.exchange.v1beta1.MsgCreateSpotLimitOrder",
expire_in=31536000, # 1 year
)
Expand Down
7 changes: 6 additions & 1 deletion examples/chain_client/1_MsgSend.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import asyncio
import os

import dotenv
from grpc import RpcError

from pyinjective.async_client import AsyncClient
Expand All @@ -10,6 +12,9 @@


async def main() -> None:
dotenv.load_dotenv()
configured_private_key = os.getenv("INJECTIVE_PRIVATE_KEY")

# select network: local, testnet, mainnet
network = Network.testnet()

Expand All @@ -19,7 +24,7 @@ async def main() -> None:
await client.sync_timeout_height()

# load account
priv_key = PrivateKey.from_hex("f9db9bf330e23cb7839039e944adef6e9df447b90b503d5b4464c90bea9022f3")
priv_key = PrivateKey.from_hex(configured_private_key)
pub_key = priv_key.to_public_key()
address = pub_key.to_address()
await client.fetch_account(address.to_acc_bech32())
Expand Down
12 changes: 9 additions & 3 deletions examples/chain_client/20_MsgExec.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import asyncio
import os
import uuid

import dotenv
from grpc import RpcError

from pyinjective.async_client import AsyncClient
Expand All @@ -11,6 +13,10 @@


async def main() -> None:
dotenv.load_dotenv()
configured_private_key = os.getenv("INJECTIVE_GRANTEE_PRIVATE_KEY")
granter_inj_address = os.getenv("INJECTIVE_GRANTER_PUBLIC_ADDRESS")

# select network: local, testnet, mainnet
network = Network.testnet()

Expand All @@ -20,15 +26,15 @@ async def main() -> None:
await client.sync_timeout_height()

# load account
priv_key = PrivateKey.from_hex("5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e")
priv_key = PrivateKey.from_hex(configured_private_key)
pub_key = priv_key.to_public_key()
address = pub_key.to_address()
await client.fetch_account(address.to_acc_bech32())

# prepare tx msg
market_id = "0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe"
grantee = "inj14au322k9munkmx5wrchz9q30juf5wjgz2cfqku"
granter_inj_address = "inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r"
grantee = address.to_acc_bech32()

granter_address = Address.from_acc_bech32(granter_inj_address)
granter_subaccount_id = granter_address.get_subaccount_id(index=0)
msg0 = composer.MsgCreateSpotLimitOrder(
Expand Down
12 changes: 9 additions & 3 deletions examples/chain_client/21_MsgRevoke.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import asyncio
import os

import dotenv
from grpc import RpcError

from pyinjective.async_client import AsyncClient
Expand All @@ -10,6 +12,10 @@


async def main() -> None:
dotenv.load_dotenv()
configured_private_key = os.getenv("INJECTIVE_PRIVATE_KEY")
grantee_public_address = os.getenv("INJECTIVE_GRANTEE_PUBLIC_ADDRESS")

# select network: local, testnet, mainnet
network = Network.testnet()

Expand All @@ -19,15 +25,15 @@ async def main() -> None:
await client.sync_timeout_height()

# load account
priv_key = PrivateKey.from_hex("f9db9bf330e23cb7839039e944adef6e9df447b90b503d5b4464c90bea9022f3")
priv_key = PrivateKey.from_hex(configured_private_key)
pub_key = priv_key.to_public_key()
address = pub_key.to_address()
await client.fetch_account(address.to_acc_bech32())

# prepare tx msg
msg = composer.MsgRevoke(
granter="inj14au322k9munkmx5wrchz9q30juf5wjgz2cfqku",
grantee="inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r",
granter=address.to_acc_bech32(),
grantee=grantee_public_address,
msg_type="/injective.exchange.v1beta1.MsgCreateSpotLimitOrder",
)

Expand Down
7 changes: 6 additions & 1 deletion examples/chain_client/22_MsgSendToEth.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import asyncio
import os

import dotenv
import requests
from grpc import RpcError

Expand All @@ -11,6 +13,9 @@


async def main() -> None:
dotenv.load_dotenv()
configured_private_key = os.getenv("INJECTIVE_PRIVATE_KEY")

# select network: local, testnet, mainnet
network = Network.testnet()

Expand All @@ -20,7 +25,7 @@ async def main() -> None:
await client.sync_timeout_height()

# load account
priv_key = PrivateKey.from_hex("f9db9bf330e23cb7839039e944adef6e9df447b90b503d5b4464c90bea9022f3")
priv_key = PrivateKey.from_hex(configured_private_key)
pub_key = priv_key.to_public_key()
address = pub_key.to_address()
await client.fetch_account(address.to_acc_bech32())
Expand Down
7 changes: 6 additions & 1 deletion examples/chain_client/23_MsgRelayPriceFeedPrice.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import asyncio
import os

import dotenv
from grpc import RpcError

from pyinjective.async_client import AsyncClient
Expand All @@ -10,6 +12,9 @@


async def main() -> None:
dotenv.load_dotenv()
configured_private_key = os.getenv("INJECTIVE_PRIVATE_KEY")

# select network: local, testnet, mainnet
network = Network.testnet()

Expand All @@ -19,7 +24,7 @@ async def main() -> None:
await client.sync_timeout_height()

# load account
priv_key = PrivateKey.from_hex("f9db9bf330e23cb7839039e944adef6e9df447b90b503d5b4464c90bea9022f3")
priv_key = PrivateKey.from_hex(configured_private_key)
pub_key = priv_key.to_public_key()
address = pub_key.to_address()
await client.fetch_account(address.to_acc_bech32())
Expand Down
Loading
Loading