Skip to content

Commit ca0c2ce

Browse files
author
abel
committed
(feat) Refactored all examples to remove references to private keys. Added the use of dotenv to load private keys into environment variables. Removed asyncio package dependency
1 parent 158b341 commit ca0c2ce

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1461
-1378
lines changed

examples/SendToInjective.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
import asyncio
22
import json
3+
import os
4+
5+
import dotenv
36

47
from pyinjective.core.network import Network
58
from pyinjective.sendtocosmos import Peggo
69

710

811
async def main() -> None:
12+
dotenv.load_dotenv()
13+
private_key = os.getenv("INJECTIVE_PRIVATE_KEY")
14+
915
# select network: testnet, mainnet
1016
network = Network.testnet()
1117
peggo_composer = Peggo(network=network.string())
1218

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

1621
maxFeePerGas_Gwei = 4

examples/chain_client/0_LocalOrderHash.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import asyncio
2+
import os
23
import uuid
34

5+
import dotenv
6+
47
from pyinjective.async_client import AsyncClient
58
from pyinjective.constant import GAS_FEE_BUFFER_AMOUNT, GAS_PRICE
69
from pyinjective.core.network import Network
@@ -10,6 +13,9 @@
1013

1114

1215
async def main() -> None:
16+
dotenv.load_dotenv()
17+
configured_private_key = os.getenv("INJECTIVE_PRIVATE_KEY")
18+
1319
# select network: local, testnet, mainnet
1420
network = Network.testnet()
1521

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

2127
# load account
22-
priv_key = PrivateKey.from_hex("f9db9bf330e23cb7839039e944adef6e9df447b90b503d5b4464c90bea9022f3")
28+
priv_key = PrivateKey.from_hex(configured_private_key)
2329
pub_key = priv_key.to_public_key()
2430
address = pub_key.to_address()
2531
await client.fetch_account(address.to_acc_bech32())

examples/chain_client/13_MsgIncreasePositionMargin.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import asyncio
2+
import os
23

4+
import dotenv
35
from grpc import RpcError
46

57
from pyinjective.async_client import AsyncClient
@@ -10,6 +12,9 @@
1012

1113

1214
async def main() -> None:
15+
dotenv.load_dotenv()
16+
configured_private_key = os.getenv("INJECTIVE_PRIVATE_KEY")
17+
1318
# select network: local, testnet, mainnet
1419
network = Network.testnet()
1520

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

2126
# load account
22-
priv_key = PrivateKey.from_hex("f9db9bf330e23cb7839039e944adef6e9df447b90b503d5b4464c90bea9022f3")
27+
priv_key = PrivateKey.from_hex(configured_private_key)
2328
pub_key = priv_key.to_public_key()
2429
address = pub_key.to_address()
2530
await client.fetch_account(address.to_acc_bech32())

examples/chain_client/15_MsgWithdraw.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import asyncio
2+
import os
23

4+
import dotenv
35
from grpc import RpcError
46

57
from pyinjective.async_client import AsyncClient
@@ -10,6 +12,9 @@
1012

1113

1214
async def main() -> None:
15+
dotenv.load_dotenv()
16+
configured_private_key = os.getenv("INJECTIVE_PRIVATE_KEY")
17+
1318
# select network: local, testnet, mainnet
1419
network = Network.testnet()
1520

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

2126
# load account
22-
priv_key = PrivateKey.from_hex("f9db9bf330e23cb7839039e944adef6e9df447b90b503d5b4464c90bea9022f3")
27+
priv_key = PrivateKey.from_hex(configured_private_key)
2328
pub_key = priv_key.to_public_key()
2429
address = pub_key.to_address()
2530
await client.fetch_account(address.to_acc_bech32())

examples/chain_client/16_MsgSubaccountTransfer.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import asyncio
2+
import os
23

4+
import dotenv
35
from grpc import RpcError
46

57
from pyinjective.async_client import AsyncClient
@@ -10,6 +12,9 @@
1012

1113

1214
async def main() -> None:
15+
dotenv.load_dotenv()
16+
configured_private_key = os.getenv("INJECTIVE_PRIVATE_KEY")
17+
1318
# select network: local, testnet, mainnet
1419
network = Network.testnet()
1520

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

2126
# load account
22-
priv_key = PrivateKey.from_hex("f9db9bf330e23cb7839039e944adef6e9df447b90b503d5b4464c90bea9022f3")
27+
priv_key = PrivateKey.from_hex(configured_private_key)
2328
pub_key = priv_key.to_public_key()
2429
address = pub_key.to_address()
2530
await client.fetch_account(address.to_acc_bech32())

examples/chain_client/17_MsgBatchUpdateOrders.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import asyncio
2+
import os
23
import uuid
34

5+
import dotenv
46
from grpc import RpcError
57

68
from pyinjective.async_client import AsyncClient
@@ -11,6 +13,9 @@
1113

1214

1315
async def main() -> None:
16+
dotenv.load_dotenv()
17+
configured_private_key = os.getenv("INJECTIVE_PRIVATE_KEY")
18+
1419
# select network: local, testnet, mainnet
1520
network = Network.testnet()
1621

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

2227
# load account
23-
priv_key = PrivateKey.from_hex("f9db9bf330e23cb7839039e944adef6e9df447b90b503d5b4464c90bea9022f3")
28+
priv_key = PrivateKey.from_hex(configured_private_key)
2429
pub_key = priv_key.to_public_key()
2530
address = pub_key.to_address()
2631
await client.fetch_account(address.to_acc_bech32())

examples/chain_client/18_MsgBid.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import asyncio
2+
import os
23

4+
import dotenv
35
from grpc import RpcError
46

57
from pyinjective.async_client import AsyncClient
@@ -10,6 +12,9 @@
1012

1113

1214
async def main() -> None:
15+
dotenv.load_dotenv()
16+
configured_private_key = os.getenv("INJECTIVE_PRIVATE_KEY")
17+
1318
# select network: local, testnet, mainnet
1419
network = Network.testnet()
1520

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

2126
# load account
22-
priv_key = PrivateKey.from_hex("f9db9bf330e23cb7839039e944adef6e9df447b90b503d5b4464c90bea9022f3")
27+
priv_key = PrivateKey.from_hex(configured_private_key)
2328
pub_key = priv_key.to_public_key()
2429
address = pub_key.to_address()
2530
await client.fetch_account(address.to_acc_bech32())

examples/chain_client/19_MsgGrant.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import asyncio
2+
import os
23

4+
import dotenv
35
from grpc import RpcError
46

57
from pyinjective.async_client import AsyncClient
@@ -10,6 +12,10 @@
1012

1113

1214
async def main() -> None:
15+
dotenv.load_dotenv()
16+
configured_private_key = os.getenv("INJECTIVE_PRIVATE_KEY")
17+
grantee_public_address = os.getenv("INJECTIVE_GRANTEE_PUBLIC_ADDRESS")
18+
1319
# select network: local, testnet, mainnet
1420
network = Network.testnet()
1521

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

2127
# load account
22-
priv_key = PrivateKey.from_hex("f9db9bf330e23cb7839039e944adef6e9df447b90b503d5b4464c90bea9022f3")
28+
priv_key = PrivateKey.from_hex(configured_private_key)
2329
pub_key = priv_key.to_public_key()
2430
address = pub_key.to_address()
2531
await client.fetch_account(address.to_acc_bech32())
@@ -30,8 +36,8 @@ async def main() -> None:
3036

3137
# GENERIC AUTHZ
3238
msg = composer.MsgGrantGeneric(
33-
granter="inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r",
34-
grantee="inj14au322k9munkmx5wrchz9q30juf5wjgz2cfqku",
39+
granter=address.to_acc_bech32(),
40+
grantee=grantee_public_address,
3541
msg_type="/injective.exchange.v1beta1.MsgCreateSpotLimitOrder",
3642
expire_in=31536000, # 1 year
3743
)

examples/chain_client/1_MsgSend.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import asyncio
2+
import os
23

4+
import dotenv
35
from grpc import RpcError
46

57
from pyinjective.async_client import AsyncClient
@@ -10,6 +12,9 @@
1012

1113

1214
async def main() -> None:
15+
dotenv.load_dotenv()
16+
configured_private_key = os.getenv("INJECTIVE_PRIVATE_KEY")
17+
1318
# select network: local, testnet, mainnet
1419
network = Network.testnet()
1520

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

2126
# load account
22-
priv_key = PrivateKey.from_hex("f9db9bf330e23cb7839039e944adef6e9df447b90b503d5b4464c90bea9022f3")
27+
priv_key = PrivateKey.from_hex(configured_private_key)
2328
pub_key = priv_key.to_public_key()
2429
address = pub_key.to_address()
2530
await client.fetch_account(address.to_acc_bech32())

examples/chain_client/20_MsgExec.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import asyncio
2+
import os
23
import uuid
34

5+
import dotenv
46
from grpc import RpcError
57

68
from pyinjective.async_client import AsyncClient
@@ -11,6 +13,10 @@
1113

1214

1315
async def main() -> None:
16+
dotenv.load_dotenv()
17+
configured_private_key = os.getenv("INJECTIVE_GRANTEE_PRIVATE_KEY")
18+
granter_inj_address = os.getenv("INJECTIVE_GRANTER_PUBLIC_ADDRESS")
19+
1420
# select network: local, testnet, mainnet
1521
network = Network.testnet()
1622

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

2228
# load account
23-
priv_key = PrivateKey.from_hex("5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e")
29+
priv_key = PrivateKey.from_hex(configured_private_key)
2430
pub_key = priv_key.to_public_key()
2531
address = pub_key.to_address()
2632
await client.fetch_account(address.to_acc_bech32())
2733

2834
# prepare tx msg
2935
market_id = "0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe"
30-
grantee = "inj14au322k9munkmx5wrchz9q30juf5wjgz2cfqku"
31-
granter_inj_address = "inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r"
36+
grantee = address.to_acc_bech32()
37+
3238
granter_address = Address.from_acc_bech32(granter_inj_address)
3339
granter_subaccount_id = granter_address.get_subaccount_id(index=0)
3440
msg0 = composer.MsgCreateSpotLimitOrder(

0 commit comments

Comments
 (0)