LCDClient
The LCDClient
is an object representing a HTTP connection to a Terra LCD node.
Get connected
Create a new LCDClient instance by specifying the URL and chain ID of the node to connect to.
Note
It is common practice to name the active LCDClient instance terra
, but this is not required.
>>> from terra_sdk.client.lcd import LCDClient
>>> terra = LCDClient(url="https://lcd.terra.dev", chain_id="columbus-5")
>>> terra.tendermint.node_info()['default_node_info']['network']
'columbus-5'
You can also specify gas estimation parameters for your chain for building transactions.
import requests
from terra_sdk.core import Coins
res = requests.get("https://fcd.terra.dev/v1/txs/gas_prices")
terra = LCDClient(
url="https://lcd.terra.dev",
chain_id="columbus-5",
gas_prices=Coins(res.json()),
gas_adjustment="1.4"
)
Using the module APIs
LCDClient includes functions for interacting with each of the core modules (see sidebar). These functions are divided and
and organized by module name (eg. terra.market
), and handle
the tedium of building HTTP requests, parsing the results, and handling errors.
Each request fetches live data from the blockchain:
>>> terra.market.parameters()
{'base_pool': '7000000000000.000000000000000000', 'pool_recovery_period': '200', 'min_spread': '0.005000000000000000'}
The height of the last result (if applicable) is available:
>>> terra.last_request_height
89292
Create a wallet
LCDClient can create a Wallet
object from any Key
implementation. Wallet objects
are useful for easily creating and signing transactions.
>>> from terra_sdk.key.mnemonic import MnemonicKey
>>> mk = MnemonicKey()
>>> wallet = terra.wallet(mk)
>>> wallet.account_number()
27
LCDClient Reference
- class terra_sdk.client.lcd.LCDClient(url, chain_id=None, gas_prices=None, gas_adjustment=None)[source]
An object representing a connection to a node running the Terra LCD server.
- chain_id: str
Chain ID of blockchain network connecting to.
- feegrant: terra_sdk.client.lcd.api.feegrant.FeeGrantAPI
FeeGrant
.
- gas_adjustment: Union[str, float, int, terra_sdk.core.numeric.Dec]
Gas adjustment factor for automatic fee estimation.
- gas_prices: Union[Iterable[terra_sdk.core.coin.Coin], str, Dict[str, Union[str, int, float, decimal.Decimal, terra_sdk.core.numeric.Dec]], Dict[str, terra_sdk.core.coin.Coin]]
Gas prices to use for automatic fee estimation.
- ibc: terra_sdk.client.lcd.api.ibc.IbcAPI
IbcAPI
.
- last_request_height: Optional[int]
Height of response of last-made made LCD request.
- treasury: terra_sdk.client.lcd.api.treasury.TreasuryAPI
TreasuryAPI
.
- url: str
URL endpoint of LCD server.