This document specifies the x/auth/tx package of the Cosmos SDK.This package represents the Cosmos SDK implementation of the client.TxConfig, client.TxBuilder, client.TxEncoder and client.TxDecoder interfaces.
client.TxConfig defines an interface a client can utilize to generate an application-defined concrete transaction type.
The interface defines a set of methods for creating a client.TxBuilder.
package clientimport ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/tx" signingtypes "github.com/cosmos/cosmos-sdk/types/tx/signing" "github.com/cosmos/cosmos-sdk/x/auth/signing")type ( // TxEncodingConfig defines an interface that contains transaction // encoders and decoders TxEncodingConfig interface { TxEncoder()sdk.TxEncoder TxDecoder()sdk.TxDecoder TxJSONEncoder()sdk.TxEncoder TxJSONDecoder()sdk.TxDecoder MarshalSignatureJSON([]signingtypes.SignatureV2) ([]byte, error)UnmarshalSignatureJSON([]byte) ([]signingtypes.SignatureV2, error)} // TxConfig defines an interface a client can utilize to generate an // application-defined concrete transaction type. The type returned must // implement TxBuilder. TxConfig interface { TxEncodingConfig NewTxBuilder()TxBuilder WrapTxBuilder(sdk.Tx) (TxBuilder, error)SignModeHandler()signing.SignModeHandler} // TxBuilder defines an interface which an application-defined concrete transaction // type must implement. Namely, it must be able to set messages, generate // signatures, and provide canonical bytes to sign over. The transaction must // also know how to encode itself. TxBuilder interface { GetTx()signing.Tx SetMsgs(msgs ...sdk.Msg)error SetSignatures(signatures ...signingtypes.SignatureV2)error SetMemo(memo string)SetFeeAmount(amount sdk.Coins)SetFeePayer(feePayer sdk.AccAddress)SetGasLimit(limit uint64)SetTip(tip *tx.Tip)SetTimeoutHeight(height uint64)SetFeeGranter(feeGranter sdk.AccAddress)AddAuxSignerData(tx.AuxSignerData)error})
The default implementation of client.TxConfig is instantiated by NewTxConfig in x/auth/tx module.
package tximport ( "fmt" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" signingtypes "github.com/cosmos/cosmos-sdk/types/tx/signing" "github.com/cosmos/cosmos-sdk/x/auth/signing")type config struct { handler signing.SignModeHandler decoder sdk.TxDecoder encoder sdk.TxEncoder jsonDecoder sdk.TxDecoder jsonEncoder sdk.TxEncoder protoCodec codec.ProtoCodecMarshaler}// NewTxConfig returns a new protobuf TxConfig using the provided ProtoCodec and sign modes. The// first enabled sign mode will become the default sign mode.// NOTE: Use NewTxConfigWithHandler to provide a custom signing handler in case the sign mode// is not supported by default (eg: SignMode_SIGN_MODE_EIP_191).func NewTxConfig(protoCodec codec.ProtoCodecMarshaler, enabledSignModes []signingtypes.SignMode)client.TxConfig { return NewTxConfigWithHandler(protoCodec, makeSignModeHandler(enabledSignModes))}// NewTxConfig returns a new protobuf TxConfig using the provided ProtoCodec and signing handler.func NewTxConfigWithHandler(protoCodec codec.ProtoCodecMarshaler, handler signing.SignModeHandler)client.TxConfig { return &config{ handler: handler, decoder: DefaultTxDecoder(protoCodec), encoder: DefaultTxEncoder(), jsonDecoder: DefaultJSONTxDecoder(protoCodec), jsonEncoder: DefaultJSONTxEncoder(protoCodec), protoCodec: protoCodec,}}func (g config)NewTxBuilder()client.TxBuilder { return newBuilder(g.protoCodec)}// WrapTxBuilder returns a builder from provided transactionfunc (g config)WrapTxBuilder(newTx sdk.Tx) (client.TxBuilder, error) { newBuilder, ok := newTx.(*wrapper) if !ok { return nil, fmt.Errorf("expected %T, got %T", &wrapper{}, newTx)}return newBuilder, nil}func (g config)SignModeHandler()signing.SignModeHandler { return g.handler}func (g config)TxEncoder()sdk.TxEncoder { return g.encoder}func (g config)TxDecoder()sdk.TxDecoder { return g.decoder}func (g config)TxJSONEncoder()sdk.TxEncoder { return g.jsonEncoder}func (g config)TxJSONDecoder()sdk.TxDecoder { return g.jsonDecoder}
package clientimport ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/tx" signingtypes "github.com/cosmos/cosmos-sdk/types/tx/signing" "github.com/cosmos/cosmos-sdk/x/auth/signing")type ( // TxEncodingConfig defines an interface that contains transaction // encoders and decoders TxEncodingConfig interface { TxEncoder()sdk.TxEncoder TxDecoder()sdk.TxDecoder TxJSONEncoder()sdk.TxEncoder TxJSONDecoder()sdk.TxDecoder MarshalSignatureJSON([]signingtypes.SignatureV2) ([]byte, error)UnmarshalSignatureJSON([]byte) ([]signingtypes.SignatureV2, error)} // TxConfig defines an interface a client can utilize to generate an // application-defined concrete transaction type. The type returned must // implement TxBuilder. TxConfig interface { TxEncodingConfig NewTxBuilder()TxBuilder WrapTxBuilder(sdk.Tx) (TxBuilder, error)SignModeHandler()signing.SignModeHandler} // TxBuilder defines an interface which an application-defined concrete transaction // type must implement. Namely, it must be able to set messages, generate // signatures, and provide canonical bytes to sign over. The transaction must // also know how to encode itself. TxBuilder interface { GetTx()signing.Tx SetMsgs(msgs ...sdk.Msg)error SetSignatures(signatures ...signingtypes.SignatureV2)error SetMemo(memo string)SetFeeAmount(amount sdk.Coins)SetFeePayer(feePayer sdk.AccAddress)SetGasLimit(limit uint64)SetTip(tip *tx.Tip)SetTimeoutHeight(height uint64)SetFeeGranter(feeGranter sdk.AccAddress)AddAuxSignerData(tx.AuxSignerData)error})
The client.TxBuilder interface is as well implemented by x/auth/tx.
A client.TxBuilder can be accessed with TxConfig.NewTxBuilder().
The x/auth/tx module provides a CLI command to query any transaction, given its hash, transaction sequence or signature.Without any argument, the command will query the transaction using the transaction hash.
The x/auth/block module provides a CLI command to query any block, given its hash, height, or events.When querying a block by its hash, use the --type=hash flag:
The encode command encodes a transaction created with the --generate-only flag or signed with the sign command.
The transaction is seralized it to Protobuf and returned as base64.