Skip to main content

Using Terrad

This guide will go over commands which are available on Terrad, the command-line interface that connects to Terra and enables you to interact with the Terra blockchain. Terrad operates as both a client and a server as every active validator and full node runs Terrad and communicates with their node via Terrad. You can use Terrad to interact with the Terra blockchain by uploading contracts, querying data, managing staking activities, working with governance proposals, and more. For more general information, run terrad --help in your terminal. For more information about a specific Terrad command, append the -h or --help flag after the command: terrad query --help.

Accessing a Node

To query state and send transactions, you must connect to a node, which is the access point to the entire network of peer connections. You can either run your own full node or connect to someone else's.

Running your own full node

Running your own full node is the most secure option, but it comes with relatively high resource requirements. For more information about the requirements of running your own full node and a tutorial for installing Terrad, check out the installation guide. For a tutorial that explains how to connect to an existing Terra network, see joining a network.

Connecting to a remote full node

If you don't want to run your own full node, you can connect to someone else's full node. As you consider your options for operators, it is recommended to prioritize operators that you can trust. Malicious operators might intentionally return incorrect query results or censor your transactions. You shouldn't worry about an operator being able to access your account as long as you have your private key stored in a secure location. Possible options of full node operators include validators, wallet providers, or exchanges.

To connect to the full node, you need an address in the https://<host>:<port> format, for example https://77.87.106.33:26657. This address has to be communicated by the full node operator you choose to trust. You will use this address in the following section.

If you are not running a node and would like to communicate through Terrad, lists of public nodes can be found here.

Configuring Terrad

Terrad enables you to interact with a node that runs on the Terra network, whether you run it yourself or not. To configure Terrad, edit the the config.toml file in the ~/.terra/config/ directory.

Querying Blockchain State

To query all relevant information from the blockchain, such as account balances, amount of bonded tokens, outstanding rewards, and so on, use terrad query. The following list shows some of the most useful commands for delegators:


_20
# query account balances and other account-related information
_20
terrad query account <ACCOUNT_ADDRESS>
_20
# Account address is of the form terra1rEXAMPLE9tEXAMPLEf9cvEXAMPLEss
_20
# you can find the one for your node by running `terrad keys list`
_20
_20
# query the list of validators
_20
terrad query staking validators
_20
_20
# query the information of a validator given their address
_20
terrad query staking validator <validatorAddress>
_20
_20
# query all delegations made from a delegator given their address
_20
# (note: delegator addresses are regular account addresses)
_20
terrad query staking delegations <delegatorAddress>
_20
_20
# query a specific delegation made from a delegator to a validator
_20
terrad query staking delegation <delegatorAddress> <validatorAddress>
_20
_20
# query the rewards of a delegator given a delegator address (e.g. terra10snjt8dmpr5my0h76xj48ty80uzwhraqalu4eg)
_20
terrad query distr rewards <delegatorAddress>

Sending Transactions

The terra tx command can be used to send transactions containing module messages with state-changing directives that get processed and included in blocks.


_1
terrad tx ...

To learn more about the different types of transactions you can issue, see the section for each module.

Simulating a transaction

To simulate a transaction without actually broadcasting it, append the --dry-run flag to the command statement:


_6
terrad tx bank send \
_6
<sender_address> \
_6
<recipient_address> \
_6
<amount_and_denomination> \
_6
--chain-id=<chain-id> \
_6
--dry-run

Example: simulate a Luna transfer:


_6
terrad tx bank send \
_6
terra1ru2ySENDER-EXAMPLEtf9cva9kp33h0jnsm9ss \
_6
terra1rRECIPIENT-EXAMPLEtf9cva9kp33h0jnsm9ss \
_6
1uluna \
_6
--chain-id=pisco-1 \
_6
--dry-run

Generating a transaction without sending

To build a transaction and print its JSON format to STDOUT, append --generate-only to the list of the command line arguments. This allows you to separate the creation and signing of a transaction with the broadcasting.


_6
terrad tx bank send \
_6
<sender_address> \
_6
<recipient_address> \
_6
<amount_and_denomination> \
_6
--chain-id=<chain-id> \
_6
--generate-only > unsignedSendTx.json


_4
terrad tx sign \
_4
--chain-id=<chain_id> \
_4
--from=<address> \
_4
unsignedSendTx.json > signedSendTx.json

Example: Sign an unsigned transaction


_3
terrad tx sign \
_3
--chain-id=pisco-1 \
_3
--from=terra1EXAMPLEy09tEXAMPLEtf9EXAMPLE3h0EXAMPLEss unsignedTx.json

A successful transaction response should look similar to the following:


_46
{
_46
"body": {
_46
"messages": [
_46
{
_46
"@type": "/cosmos.bank.v1beta1.MsgSend",
_46
"from_address": "terra1ru2ySENDER-EXAMPLEtf9cva9kp33h0jnsm9ss",
_46
"to_address": "terra1rRECIPIENT-EXAMPLEtf9cva9kp33h0jnsm9ss",
_46
"amount": [
_46
{
_46
"denom": "uluna",
_46
"amount": "1"
_46
}
_46
]
_46
}
_46
],
_46
"memo": "",
_46
"timeout_height": "0",
_46
"extension_options": [],
_46
"non_critical_extension_options": []
_46
},
_46
"auth_info": {
_46
"signer_infos": [
_46
{
_46
"public_key": {
_46
"@type": "/cosmos.crypto.secp256k1.PubKey",
_46
"key": "A3Z50zDpCEXAMPLEG5Ru+DGOFEXAMPLEm0EXAMPLEKtxd"
_46
},
_46
"mode_info": {
_46
"single": {
_46
"mode": "SIGN_MODE_DIRECT"
_46
}
_46
},
_46
"sequence": "0"
_46
}
_46
],
_46
"fee": {
_46
"amount": [],
_46
"gas_limit": "200000",
_46
"payer": "",
_46
"granter": ""
_46
}
_46
},
_46
"signatures": [
_46
"dclBjQ9IsPPkOlcFMsBlQqkx7yqRl0oPBnRuEXAMPLEwlSQTGndiJtZMXI7j5MZ+5JEZI0X3MOg0cr72sq11lA=="
_46
]
_46
}

You can validate the transaction's signatures by executing the following command:


_1
terrad tx sign --validate-signatures signedSendTx.json

You can broadcast the signed transaction to a node by providing the JSON file to the following command:


_1
terrad tx broadcast --node=<node> signedSendTx.json

Fees

Transactions on the Terra Protocol network must include a transaction fee in order to be processed. This fee pays for the gas required to run the transaction. To calculate fees, use the following formula:

fees=gasgasPricesfees = gas * gasPrices

The value of gas is dependent on the transaction. Different transactions require different amounts of gas. The gas amount for a transaction is calculated as it is being processed, but there is a way to estimate it beforehand by using the auto value for the gas flag. Of course, this only gives an estimate. You can adjust this estimate with the flag --gas-adjustment (default 1.0) if you want to be sure you provide enough gas for the transaction to successfully process.

The gasPrice is the price of each unit of gas. Each validator sets a min-gas-price value and will only include transactions that have a gasPrice greater than their min-gas-price.

The transaction fees are the product of gas and gasPrice. As a user, you can specify a desired gasPrice or fee value for a transaction. The higher the value given for gasPrice or fee, the higher the chance that your transaction will get included in a block.

Setting Fees

Each transaction may either supply fees or gas prices, but not both. Most users will typically provide fees as this is the final cost you will end up incurring for the transaction being included in the ledger, where as gas prices will be dynamically calculated depending on the validator.

Validators specify a minimum gas price that they use to determine whether or not to include a transaction. The stipulation gasPrices >= minGasPrices is checked during the CheckTx process. Note, your transaction must supply fees that are greater than or equal to any of the denominations the validator requires.

To directly use fees:


_1
terrad tx send ... --fees=100000uluna

If you use fees, validators will calculate the implied minGasPrices by dividing your fee with the estimated gas consumption.

To use gas prices:


_1
terrad tx send ... --gas-prices=0.05uluna

Automatic Fee Estimation

You may want to cap the maximum gas that can be consumed by the transaction via the --gas flag. If you pass --gas=auto, the gas will be automatically estimated before executing the transaction.

Gas estimates might be inaccurate as state changes could occur in between the end of the simulation and the actual execution of a transaction, thus an adjustment is applied on top of the original estimate in order to ensure the transaction is broadcasted successfully.

The adjustment can be controlled via the --gas-adjustment flag, which defaults to the value of 1.0.

To get a direct fee estimation from Terrad:


_3
terrad tx estimate-fee ...\
_3
--gas-prices=0.01uluna
_3
--gas-adjustment=1.4

To create and send transactions using fee-estimation, use the template below as a format:


_4
terrad tx send ... \
_4
--gas-prices=0.01uluna
_4
--gas=auto
_4
--gas-adjustment=1.4

Shell Autocompletion

Auto-completion scripts for popular UNIX shell interpreters such as bash and zsh can be generated using the completion command. This makes interacting with Terra Core endpoints when using the command-line more convenient.

If you want to generate bash completion scripts run the following command:


_1
terrad completion > terrad_completion

If you want to generate zsh completion scripts run the following command:


_1
terrad completion --zsh > terrad_completion

On most UNIX systems, such scripts may be loaded in .bashrc or .bash_profile to enable Bash autocompletion.


_1
echo '. terrad_completion' >> ~/.bashrc

Refer to the user's manual of your operating system's interpreter for information on how to enable shell autocompletion.