diff --git a/README.md b/README.md index 67a6c070..f8d669ca 100644 --- a/README.md +++ b/README.md @@ -39,9 +39,11 @@ The package is intended to be used by coders, developers, technically-skilled tr ## Python SDK Tutorial -[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)][Colab link] - -[Colab link]: https://colab.research.google.com/github/NibiruChain/py-sdk/blob/master/examples/collab_notebook.ipynb + +

+ +

+
## Installation from `PyPI` @@ -55,6 +57,79 @@ You may need to update `pip` to get this to run: python -m pip install --upgrade pip ``` +## Usage + +#### Ex: Creating a wallet and SDK client + +```python +from nibiru import wallet + +# Save the mnemonic for later +mnemonic, private_key = wallet.PrivateKey.generate() +``` + +After, creating an account, you can create an `Sdk` instance. + +```python +import nibiru + +network = nibiru.network.Network.testnet(2) +sdk = nibiru.Sdk.authorize(mnemonic) + .with_network(network) +``` + +The `Sdk` class creates an interface to sign and send transactions or execute +queries. It is associated with: +- A transaction signer (wallet), which is configured from existing mnemonic to recover a `PrivateKey`. +- A `Network`, which specifies the RPC, LCD, and gRPC endpoints for connecting to Nibiru Chain. +- An optional `TxConfig` for changing gas parameters. + +#### Ex: Using the faucet + +```python +import requests + +requests.post( + "https://faucet.testnet-2.nibiru.fi/", + json={ + "address": agent.address, + "coins": ["10000000unibi", "100000000000unusd"], + }, +) +``` + +#### Ex: Querying chain state + +```python +# Querying the token balances of the account +sdk.query.get_bank_balances(sdk.address) + +# Querying from the vpool module +query_resp = sdk.query.vpool.all_pools() +print(query_resp) +# Queries from other modules can be accessed from "sdk.query.module" +``` + +#### Ex: Submitting transactions + +```python +import nibiru +from nibiru.msg + +tx_resp = sdk.tx.execute_msgs( + nibiru.msg.MsgOpenPosition( + sender=sdk.address, + token_pair="ubtc:unusd", + side=nibiru.common.Side.BUY, + quote_asset_amount=10, + leverage=10, + base_asset_amount_limit=0, + ) +) +``` + +You can broadcast any available transaction by passing its corresponding `Msg` to the `sdk.tx.execute_msgs` function. + ## Documentation Website Documentation can be found here: [Nibiru-py documentation](https://nibiru-py.readthedocs.io/en/latest/index.html)