# Messages

In Terra, each module defines its own set of messages, which serve as the interface by which account holders can directly interact with the application state of Core Modules.

Message objects by themselves don't change the blockchain state, but when they are included in a transaction which is included in a block, the message's contents are processed by nodes and put into effect. You can read more about how transactions work here.

All messages defined in this section are directly accessible as aliases from the jigu.core.msg namespace. For instance, you can do:

# from jigu.core.msg.bank import MsgSend
# from jigu.core.msg.oracle import MsgExchangeRateVote
# from jigu.core.msg.distribution import MsgModifyWithdrawAddress

from jigu.core.msg import (
    MsgSend,
    MsgExchangeRateVote
    MsgModifyWithdrawAddress
)

In Jigu, there are 2 classes that are used to capture information pertaining to messages, StdMsg and MsgInfo. They describe two difference contexts in which you will work with messages, rather than classes you will need to instantiate directly.

# StdMsg

jigu.core.msg.StdMsg

The abstract base class StdMsg defines the structure for all messages. You will never create an StdMsg directly, but use its subclasses such as MsgDelegate when creating transactions. These are messages that have not already been submitted on the blockchain, and thus have no "event log" information. The basic structure defined by StdMsg is:

  • the message type, a fully qualified path that includes the message's home module.

    Example: "staking/MsgDelegate"

  • the message action, a short name used to identify its message.

    Example: "delegate"

  • the message value, its body content containing information pertinent to state changes and validation.

If you want to influence the state of the Terra blockchain, you will create a message and include it in a transaction to broadcast. Simple transactions featuring MsgSend and MsgSwap were illustrated in the tutorial, A Tour of Jigu.

# MsgInfo

jigu.query.msginfo.MsgInfo

The other context you may find yourself working with messages is through MsgInfo, which is generated from fetching TxInfo objects for transactions which have already been included in the blockchain and carries information about a message's success / failure as well as any event logs and error logs.

MsgInfo is a wrapper around an instance of StdMsg, and is a proper superset, with the following additional properties:

bool
success

Whether the event was successfully included in the blockchain or not.

JiguBox
log

If no error occured, it will be None. This field will be populated with the error content.

EventsQuery
events

A queriable list of the events.

# Example

This example shows how to use MsgInfo to access message metadata from TxInfo.

from jigu import Terra
from jigu.core.msg import StdMsg, MsgExchangeRateVote
from jigu.query.msginfo import MsgInfo

soju = Terra("soju-0013", "https://soju-lcd.terra.dev/")

tx = soju.tx_info("715B5B468648DBC8AA4CEE47DF1D5E2227CF83464C39AE8D9594BE2E90B17980")

# get the first message
msg = tx.msgs[0]

# chain of inheritance
assert isinstance(msg, MsgInfo)
assert isinstance(msg, MsgExchangeRateVote)
assert isinstance(msg, StdMsg)

# see msg content
msg._pp

# see the vote event
msg.events.vote[0]._pp

# see the message event
msg.events.message[0]._pp

# was the message successful?
print(msg.success)
Updated on: 3/11/2020, 8:29:01 PM