02Transactions - InjectiveLabs/injective-ts Wiki

Transactions

*Pre-requisite reading: * Cosmos SDK Transactions

State changes on Injective can be done through transactions. Users create transactions, sign them and broadcast them to Injective.

When broadcasted and only after every validation is successfully passed (these validations include signature validation, parameters validations, etc) the transaction is included within a block which is approved by the network through a consensus process.

Messages

Messages are the instructions included in transactions to specify the state change the user want to do. Every transaction has to have at least one message. Messages are module-specific objects that trigger state transitions within the scope of the module they belong to. We can pack multiple messages within the same transaction.

There is an abstraction class (MsgBase) that we export from the @injectivelabs/sdk-ts and every message extends the MsgBase interface, which has couple of mapping functionalities:

  • toData -> Converts the Message to a simple Object representation,
  • toProto -> Returns a proto representation of the Message,
  • toDirectSign -> Converts the Message to a proto representation (ready to be used in the normal Cosmos way of handling transactions),
  • toAmino -> Converts the Message to a amino representation + type (usually used to covert the message to EIP712 typed data to be signable in Ethereum native wallets),
  • toWeb3 -> same as toAmino, the only difference being the type path

Transaction Context

Besides Message(s), every transaction has context. These details include fees, accountDetails, memo, signatures, etc.

Transaction Flow

Every transaction we want to broadcast to Injective has the same flow. The flow consists of three steps: preparing, signing and broadcasting the transaction.