The envelope
A transaction is a wrapper around one or more messages and includes the information needed to authorize and pay for them:messages array holds exactly what a module page shows under In a transaction. The @type field is the type URL, and it selects the handler. Everything else is envelope, and defaults are correct unless stated otherwise: payer and granter apply to fee grants, unordered and timeout_timestamp to unordered transactions.
Several messages can go in one transaction. They execute in order and atomically.
The three steps
Building, signing, and broadcasting are separate operations. Separating them is what allows offline signing. The commands below are the shortest path; Generating, Signing and Broadcasting Transactions covers multisig, offline signing, and the same flow in Go, gRPC, REST, and CosmJS.sign fetches the account number and sequence itself; offline signing supplies them with --offline --account-number --sequence.
The key must control the address in the message’s signer field. The module pages name that field for every message. See Setting up the keyring for managing the keys these commands sign with.
Broadcasting returns a transaction hash, not a result. Query for it:
code of 0 is success.
For what gas measures and how the limit and price above are applied, see Execution Context, Gas, and Events.
The API surfaces broadcast directly through cosmos.tx.v1beta1.Service/BroadcastTx on gRPC or POST /cosmos/tx/v1beta1/txs on REST. Both take the signed transaction as bytes, so building and signing still happen first.
Governance-gated messages
Some messages takeauthority as their signer, meaning the governance module account, which no one holds a key for. They execute only through a passed governance proposal, wrapped in MsgSubmitProposal. See Proposal submission for the deposit and voting periods a proposal has to clear. The module pages flag every one. MsgUpdateParams on each module is the common case.
The address the message needs: